View Full Version : Print as menu (Mysql)
lord22
08-07-2008, 01:51 PM
Hi,
I have a simple databse with few columns, 2 of them are: "id" and "name"
I want to print the database values as a menu:
<select>
<option value="the id value">the name value</option>
<option value="the id value">the name value</option>
etc.
</select>
How can I do it?
Thanks!
boogyman
08-07-2008, 02:46 PM
assuming you have a server-side language and your host supports it, you can do a loop through the results and dynamically create the dropdown select list... I will demonstrate in PHP
$link = mysqli_connect(host,username,password,database);
if($query = mysqli_query('SELECT fields FROM table WHERE condition', $link))
{
while($rs = mysqli_fetch_array($query))
{
echo '<option value="'.$rs["ID"].'">'.$rs["VALUE"].'</option>';
}
}
where the blue values correspond to your specific information...
Also something to note is that its generally advised to separate the code from the output, so if you have some type of templating system, that would be best.
lord22
08-07-2008, 03:13 PM
Thank you very much!!
I'm just new in SQL and it wrote me some error, which I don't understand:
I wrote this:
if($query = mysqli_query('SELECT * FROM `my_categories`', $link))
And what it wrote was:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given
allahverdi
08-07-2008, 07:09 PM
boogyman, I have never seen mysqli. What is it? Or it must be mysql?
motormichael12
08-07-2008, 07:10 PM
MySQL Lite
boogyman
08-07-2008, 07:55 PM
Thank you very much!!
I'm just new in SQL and it wrote me some error, which I don't understand:
I wrote this:
if($query = mysqli_query('SELECT * FROM `my_categories`', $link))
And what it wrote was:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given
sorry I havent use the actual function in a while, I switched the order, should be
if($query = mysqli_query($link,'SELECT * FROM `my_categories`', ))
boogyman, I have never seen mysqli. What is it? Or it must be mysql?
MySQLi stands for mysql improved. Basically its a newer version of mysql
see http://forge.mysql.com/wiki/Converting_to_MySQLi or http://www.johnjawed.com/benchmarks/ for more information
lord22
08-07-2008, 08:37 PM
Thank You Very Much!!
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.