PDA

View Full Version : Select damn you.. SELECT!


snyx
Fri 20th Sep '02, 5:51pm
hey all, im trying to customize this links script to fit my website, and what I wanna do is have the language field have a language selected when you load the page (ie. english) and not have it as "--select a language--" the category field below it auto selects the first category added.. so basically the bottom ones does what I want the top one to do. I played with this since 9am this morning, and not being a coder or any sort (I know html, lol) any help would be appreciated!!

thanks guys!
<tr>
<td><?=ADD_HP_LANG?></td>
<td align='center'>
<? //get languages from db
$res = MYSQL_QUERY("SELECT * FROM $table_languages order by lang"); // get lang. from db
echo "<select name='lang' onmouseover='this.focus()'>\n";
echo "<option value=''>".ADD_HP_CAT_SELECT."\n";
while ($row = MYSQL_FETCH_ARRAY($res)) // render lang-selection
{
if($lang == $row[lang]) { //render <select> for lang and select a lang, if set
echo "<option value='$row[lang]' selected>$row[lang]\n";
} else {
echo "<option value='$row[lang]'>$row[lang]\n"; }

}
MYSQL_FREE_RESULT($res); // give memory free
echo "</select>\n"; ?>
</td>
</tr>


<tr>
<td><?=ADD_HP_CAT?></td>
<td align='center'>
<? //generate select-field with cat's
$result = MYSQL_QUERY("SELECT * FROM $table_cat order by $catorder"); // get cats from db

// generate cat-selection <select>
echo "<select name='add_cat' onmouseover='this.focus()'>\n";
echo "<option value=''>".ADD_HP_CAT_SELECT."\n";
while ($row = MYSQL_FETCH_ARRAY($result))
{
if($row[id] == $from) { // render <select> for cats and select a cat, if redirected from there
echo "<option value='$row[id]' selected>$row[name]\n";
} elseif($add_cat == $row[id]) { echo "<option value='$row[id]' selected>$row[name]\n";
} else { echo "<option value='$row[id]'>$row[name]\n"; }

}
MYSQL_FREE_RESULT($result); // give memory free

echo "</select>\n"; ?>
</td>
</tr>-Myles
(sorry dbl posted @ vb.org cuz im itchin for help)

Dimava
Fri 20th Sep '02, 11:24pm
so you want it to show what the current language is, in the drop down menu?

or do you want to just exclude the selected language from the list?

-Dimava

snyx
Sat 21st Sep '02, 1:10am
its an required field so I just wanted it to show; language ID1 from db, for example.

-myles

Dan615
Sat 21st Sep '02, 8:58pm
ehhhh...it already looks like it's set up to work correctly...maybe $lang isn't set?

edit: i don't know if this matters, but try switching this around:


// try switching this to if ($row['lang'] == $lang) {
if($lang == $row[lang]) { //render <select> for lang and select a lang, if set
echo "<option value='$row[lang]' selected>$row[lang]\n";
} else {
echo "<option value='$row[lang]'>$row[lang]\n"; }

snyx
Sat 21st Sep '02, 10:14pm
cool thx, I will try that when get some free time tomrrow
and I will check the db to see if $lang is set :)

-myles

scoutt
Tue 24th Sep '02, 12:22pm
where is $lang coming from ? also I don't see any <form> tags and close you <option> tags as well.