dht1
asked on
Using More Query Results
I have a drop-down box. How could I take the values from a database and have them inserted automatically into the option list for the drop-down box?
Thanks,
Dave
Thanks,
Dave
Wow... Could you tell me how you put a text on option list. How you made a drop-down box. Use a DHTML or JScript? I think i need to know before i can give any suggestion.
ASKER
I've pasted some of my code from the drop-down box:
</td>
<td><p align="left"><select name="Day" size="1">
<option selected>01</option>
<option>02</option>
<option>03</option>
etc.... </SELECT>
Obviously I won't know how many options there will be...
Cheers,
Dave
</td>
<td><p align="left"><select name="Day" size="1">
<option selected>01</option>
<option>02</option>
<option>03</option>
etc.... </SELECT>
Obviously I won't know how many options there will be...
Cheers,
Dave
Wow...... it's not too hard to do...
For example... you have a table that keep all option you want....
<?php $result->query("Select * from TABLE"); ?>
..
..
..
<p align="left"><select name="Day" size="1">
<?php $rowitem = mysql_fetch_array($result) ) ?>
<option selected><?php echo $rowitem['columnname'] ?></option>
<?php while($rowitem = mysql_fetch_array($result) ) : ?>
<option> <?php echo $rowitem['columnname'] ?> </option>
<?php endwhile ?>
For example... you have a table that keep all option you want....
<?php $result->query("Select * from TABLE"); ?>
..
..
..
<p align="left"><select name="Day" size="1">
<?php $rowitem = mysql_fetch_array($result)
<option selected><?php echo $rowitem['columnname'] ?></option>
<?php while($rowitem = mysql_fetch_array($result)
<option> <?php echo $rowitem['columnname'] ?> </option>
<?php endwhile ?>
ASKER
I've pasted the code here. I've attempted to incorporate the code as above, but the result is an "empty" drop-down box...???
What could be wrong?
<div align="center"><center>
<table border="2" width="60%"
bordercolor="#000000" bordercolordark="#008080"
bordercolorlight="#000080" >
<tr>
<td><p align="left"><font color="#000000" size="5">Facility
Required</font></p>
</td>
<td><p align="left"><font color="#000000">
<select name="Facility" size="1">
<?php $rowitem = mysql_fetch_array($result) ) ?>
<option selected><? echo "$rowitem[name]"; ?>
</option>
<? $count = 0;
while($rowitem = mysql_fetch_array($result) ) : ?>
<option value="<? print "$var[$count]"; ?>" <? echo "$var[$count]"; ?>
</option>
<? $var[$count] = $rowitem[name];
++ $count;
endwhile ?>
What could be wrong?
<div align="center"><center>
<table border="2" width="60%"
bordercolor="#000000" bordercolordark="#008080"
bordercolorlight="#000080"
<tr>
<td><p align="left"><font color="#000000" size="5">Facility
Required</font></p>
</td>
<td><p align="left"><font color="#000000">
<select name="Facility" size="1">
<?php $rowitem = mysql_fetch_array($result)
<option selected><? echo "$rowitem[name]"; ?>
</option>
<? $count = 0;
while($rowitem = mysql_fetch_array($result)
<option value="<? print "$var[$count]"; ?>" <? echo "$var[$count]"; ?>
</option>
<? $var[$count] = $rowitem[name];
++ $count;
endwhile ?>
Well.... I amn't quite sure what's wrong to the code... but let's me guess
1. actually, PHP engine start working when start with <?php not only <?
2. when you fetch a row to array, you refer it by using %rowitem['name'], it means you must have (') to cover the name of column.
3. your code doesn't make any sense...
why.... 'cause $var (it support to be a array) get a value ($var[$count] = $rowitem[name];) after you print it print "$var[$count]"; ). what value does it use to print!!!!! Right.
<it might be have some value before your print at somewhere above this code but your code doesn't show it>
1. actually, PHP engine start working when start with <?php not only <?
2. when you fetch a row to array, you refer it by using %rowitem['name'], it means you must have (') to cover the name of column.
3. your code doesn't make any sense...
why.... 'cause $var (it support to be a array) get a value ($var[$count] = $rowitem[name];) after you print it print "$var[$count]"; ). what value does it use to print!!!!! Right.
<it might be have some value before your print at somewhere above this code but your code doesn't show it>
try to modify this part:
<? $count = 0;
while($rowitem = mysql_fetch_array($result) ) : ?>
<option value="<? print "$var[$count]"; ?>" <? echo "$var[$count]"; ?>
</option>
<? $var[$count] = $rowitem[name];
++ $count;
endwhile ?>
TO:
<? $count = 0;
while($rowitem = mysql_fetch_array($result) ) : ?>
<option value="<? print "$var[$count]"; ?>">
<? echo "$var[$count]"; ?>
</option>
<? $var[$count] = $rowitem[name];
++ $count;
endwhile ?>
u missed the last ">" of ur "option" tag
hope it can work as u wish!
<? $count = 0;
while($rowitem = mysql_fetch_array($result)
<option value="<? print "$var[$count]"; ?>" <? echo "$var[$count]"; ?>
</option>
<? $var[$count] = $rowitem[name];
++ $count;
endwhile ?>
TO:
<? $count = 0;
while($rowitem = mysql_fetch_array($result)
<option value="<? print "$var[$count]"; ?>">
<? echo "$var[$count]"; ?>
</option>
<? $var[$count] = $rowitem[name];
++ $count;
endwhile ?>
u missed the last ">" of ur "option" tag
hope it can work as u wish!
ASKER
mrvithan,
1. If the filename = <filename>.php3 then <? ... ?> is acceptable - and yes, I do have a .php3 extension.
2. What I did not include was a bit of debugging code that I whacked in before the form:
while($rowitem = mysql_fetch_array($result) );
$var[$count] = $rowitem[name];
print "$var[$count]<BR>";
++ count;
This works fine. All I need to do is get either $var[$count] or $rowitem[name] to be inserted on the option list... and I'll be damned if I can.
Freshmeat...it just didn't work.
Perhaps I'm going about this all the wrong way, but surely there IS a way of doing it... You're the experts :)
1. If the filename = <filename>.php3 then <? ... ?> is acceptable - and yes, I do have a .php3 extension.
2. What I did not include was a bit of debugging code that I whacked in before the form:
while($rowitem = mysql_fetch_array($result)
$var[$count] = $rowitem[name];
print "$var[$count]<BR>";
++ count;
This works fine. All I need to do is get either $var[$count] or $rowitem[name] to be inserted on the option list... and I'll be damned if I can.
Freshmeat...it just didn't work.
Perhaps I'm going about this all the wrong way, but surely there IS a way of doing it... You're the experts :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!!
I'm hungover... it took me a while to work out what $db and $sql should be, but I got there in the end :)
I'm hungover... it took me a while to work out what $db and $sql should be, but I got there in the end :)