List box loading data from a table

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

Post Reply
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

List box loading data from a table

Post 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>
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

What table you mean? Database table?
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

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 »

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 »

thankyou. will give it a try!
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post 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>';
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

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 »

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">
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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>
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

oh right so thats what the difference is with ?> and <?php
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

Sounds like you need to study up on the basics of PHP. Try this: http://www.php.net/manual/en/introduction.php
Post Reply