PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
SirChick
Forum Contributor
Posts: 125 Joined: Tue Jul 31, 2007 11:55 am
Post
by SirChick » Sat Aug 25, 2007 11:49 am
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>
miro_igov
Forum Contributor
Posts: 485 Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria
Post
by miro_igov » Sat Aug 25, 2007 11:51 am
What table you mean? Database table?
SirChick
Forum Contributor
Posts: 125 Joined: Tue Jul 31, 2007 11:55 am
Post
by SirChick » Sat Aug 25, 2007 11:52 am
yeh a table on my databse.. lets just say its named "items"
miro_igov
Forum Contributor
Posts: 485 Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria
Post
by miro_igov » Sat Aug 25, 2007 11:56 am
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>
SirChick
Forum Contributor
Posts: 125 Joined: Tue Jul 31, 2007 11:55 am
Post
by SirChick » Sat Aug 25, 2007 11:57 am
thankyou. will give it a try!
SirChick
Forum Contributor
Posts: 125 Joined: Tue Jul 31, 2007 11:55 am
Post
by SirChick » Sat Aug 25, 2007 12:08 pm
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>';
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Sat Aug 25, 2007 12:23 pm
Just insert ?> and <?php tags to insert plain html where you need it.
Last edited by
califdon on Sat Aug 25, 2007 12:26 pm, edited 1 time in total.
SirChick
Forum Contributor
Posts: 125 Joined: Tue Jul 31, 2007 11:55 am
Post
by SirChick » Sat Aug 25, 2007 12:25 pm
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">
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Sat Aug 25, 2007 12:28 pm
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>
SirChick
Forum Contributor
Posts: 125 Joined: Tue Jul 31, 2007 11:55 am
Post
by SirChick » Sat Aug 25, 2007 12:30 pm
oh right so thats what the difference is with ?> and <?php