Page 1 of 1
List box loading data from a table
Posted: Sat Aug 25, 2007 11:49 am
by SirChick
Is there a way to add to this list box by using infomation on my table.
Basically my table will have price and type and i want to add those 2 in the list so that it will look like this:
£12,000 - Steel
£12,500 - Wood
And because its a list box the user can then click which ever one and then i can submit it using a form ? ( i can do the form bit) but i cannot do the bit where by it creates the list in the box.. this is the html of the box so far:
Code: Select all
<select name="Combobox3" size="2" id="Combobox3" style="position:absolute;left:343px;top:662px;width:223px;font-family:MS Shell Dlg;z-index:25">
</select>
Posted: Sat Aug 25, 2007 11:51 am
by miro_igov
What table you mean? Database table?
Posted: Sat Aug 25, 2007 11:52 am
by SirChick
yeh a table on my databse.. lets just say its named "items"
Posted: Sat Aug 25, 2007 11:56 am
by miro_igov
Code: Select all
// code for connecting the database
<select name="Combobox3" size="2" id="Combobox3" style="position:absolute;left:343px;top:662px;width:223px;font-family:MS Shell Dlg;z-index:25">
$query = "SELECT `price`,`name` FROM `items` ORDER BY `price` ASC";
$res = mysql_query($query, $db_handler);
while($row = mysql_fetch_assoc($res)) {
echo '<option>'.$row['price'].' - '.$row['name'].'</option>';
}
</select>
Posted: Sat Aug 25, 2007 11:57 am
by SirChick
thankyou. will give it a try!
Posted: Sat Aug 25, 2007 12:08 pm
by SirChick
How would i get to run it though cos its using html inside php tags ?
would it be:
Code: Select all
// code for connecting the database
Echo'<select name="Combobox3" size="2" id="Combobox3"';
Echo'style="position:absolute;left:343px;top:662px;width:223px;font-family:MS Shell Dlg;z-index:25">';
Echo'$query = "SELECT `price`,`name` FROM `items` ORDER BY `price` ASC";';
Echo'$res = mysql_query($query, $db_handler);';
Echo'while($row = mysql_fetch_assoc($res)) {';
Echo'<option>'.$row['price'].' - '.$row['name'].'</option>';
Posted: Sat Aug 25, 2007 12:23 pm
by califdon
Just insert ?> and <?php tags to insert plain html where you need it.
Posted: Sat Aug 25, 2007 12:25 pm
by SirChick
doesnt work tho it says:
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\buyhouses.php on line 93
which is:
<?
<select name="Combobox3" size="2" id="Combobox3" style="position:absolute;left:343px;top:662px;width:223px;font-family:MS Shell Dlg;z-index:25">
Posted: Sat Aug 25, 2007 12:28 pm
by califdon
Code: Select all
// code for connecting the database
?>
<select name="Combobox3" size="2" id="Combobox3" style="position:absolute;left:343px;top:662px;width:223px;font-family:MS Shell Dlg;z-index:25">
<?php
$query = "SELECT `price`,`name` FROM `items` ORDER BY `price` ASC";
$res = mysql_query($query, $db_handler);
while($row = mysql_fetch_assoc($res)) {
echo '<option>'.$row['price'].' - '.$row['name'].'</option>';
}
?>
</select>
Posted: Sat Aug 25, 2007 12:30 pm
by SirChick
oh right so thats what the difference is with ?> and <?php
Posted: Sat Aug 25, 2007 12:36 pm
by califdon
Sounds like you need to study up on the basics of PHP. Try this:
http://www.php.net/manual/en/introduction.php