SQL driven HTML Menus?

SQL driven HTML Menus?

am 29.12.2005 13:28:34 von powerx

Hi All,

Would have thought this was a FAQ but I'm having trouble googling it so any
help appreciated...

I have an SQL database

ID BRAND
1 Apples
2 Pears
3 Oranges
4 ...
5 ...

What is the easiest way of getting the SQL "Brand List" into a dropdown menu
in my HTML / PHP page. It should automatically update when new items are
added?

Thanks

prx

Re: SQL driven HTML Menus?

am 29.12.2005 14:05:11 von Joe Makowiec

On 29 Dec 2005 in alt.php.sql, powerx wrote:

> Would have thought this was a FAQ but I'm having trouble googling it
> so any help appreciated...
>
> I have an SQL database
>
> ID BRAND
> 1 Apples
> 2 Pears
> 3 Oranges
> 4 ...
> 5 ...
>
> What is the easiest way of getting the SQL "Brand List" into a
> dropdown menu in my HTML / PHP page. It should automatically update
> when new items are added?

Pseudocode; adapt to your serverside scripting:

<$ SELECT ID, BRAND FROM database ORDER BY BRAND $>
....

....

--
Joe Makowiec
http://makowiec.org/
Email: http://makowiec.org/contact/?Joe

Re: SQL driven HTML Menus?

am 10.01.2006 20:25:50 von Jim Michaels

"powerx" wrote in message
news:43b3d661$0$904$db0fefd9@news.zen.co.uk...
> Hi All,
>
> Would have thought this was a FAQ but I'm having trouble googling it so
> any help appreciated...
>
> I have an SQL database
>
> ID BRAND
> 1 Apples
> 2 Pears
> 3 Oranges
> 4 ...
> 5 ...
>
> What is the easiest way of getting the SQL "Brand List" into a dropdown
> menu in my HTML / PHP page. It should automatically update when new items
> are added?

actually, what you have there is not a database, it is a table. a database
is a group of tables, so to speak. This will explain the following code:

make a dbinc.php (or whatever PHP name you wish) that has at least the
following 4 lines in it:
$link=mysql_connect("myserver.com:3306", "username", "password");
mysql_select_db("my_database", $link);
?>



include 'dbinc.php';
$q=mysql_query("SELECT ID, BRAND FROM tablename ORDER BY BRAND", $link);
?>


stripslashes() is only necessary if there could be a ' or " in the text.
you probably can take it out, but it doesn't hurt to leave it in. it takes
out the \ that MySQL pushes in when it finds special characters. It is also
necessary to use stripslashes on binary stuff (blob types) as the data comes
out, and mysql_escape_string() as the data comes in. mysql_escape_string()
is also used to prepare the MySQL INSERTs for ' or " characters.

If you would like to learn a lot about PHP programming, I suggest you
download the extended CHM manual from the PHP web site. (12MB). It has
plenty of examples.