473,390 Members | 1,229 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

fetch data from database display data in drop down menu

i have a html drop down menus and i want to conver it into dynamically means
that menu show data from database.how can i fetch data from database for using menus and sub menus using php and mysql.
Nov 17 '06 #1
11 39054
please provid you database table info and let us know what do u want to retrive ...
Nov 17 '06 #2

I am not from PHP. But assuming that you know how to connect to the database and retrieve information, I'll explain to you how the drop down box should be filled.

Open Database connections
retrieve data

<select name="" id="">
loop i to the end of file
<option value="value of the option (most of the time the id)">option name</option>
end loop

I am sorry I cannot give you the full syntax. But you should have an idea now to continue with your work.
Nov 17 '06 #3
4,258 Expert 4TB
This sample will give you an idea onn how to populate a drop down using db values:
[php]// you have already opened your db connection
$res = mysql_query("SELECT value FROM table ORDER BY value")
or die("Invalid query: " . mysql_query());
echo '<label>Select value:</label>';
echo '<select id="val" name="val">';
echo '<option value="">Select</option>';
while ($row = mysql_fetch_assoc($res)) {
$va = $row['value'];
echo "<option value='$va'>$va</option>";
echo '</select>';[/php]
Ronald :cool:
Nov 17 '06 #4
please provid you database table info and let us know what do u want to retrive ...
thanks for your reply, i give you some detail of my database.
i have a two table listings_details and sublisting_details.
there are 3 columns In listings_details table: listing_id(p.k.),domain,listing_title.
And also 3 columns in sublisting_details table: sublisting_id(p.k.),listing_id,sublisting_title.
Now i want to fetch the listing_title and sublisting_title and show into the dropdown menu.listing_title should display in mainmenu and sublisting_title display in submenu.
Nov 18 '06 #5
4,258 Expert 4TB
Well, you have the samples, what more do you want?

Ronald :cool:
Nov 18 '06 #6
hi dear ...i m a newbie
here is d code tested on db oracle,iis server,php using sql as query lang.

Expand|Select|Wrap|Line Numbers
  1. $conn=oci_connect("xyz","1234","localhost/XE");
  3.   if(!conn){
  4.   echo "connection error";
  5.   exit;
  6.   }
  8.     session_start(); 
  9.     $USER_ID=$_SESSION['USER_ID'];
  12.     $editWR=oci_parse($conn,$query);
  13.     oci_execute($editWR);
  14.     echo '<table border=1>'.'<tr>'.'<td>'.'<div>';
  15.     echo '<label>'."Week ID:".'</label>';
  16.     echo'<SELECT name="weekid" id="weekid">';
  17.     echo '<OPTION VALUE="">'."Select".'</OPTION>';
  18.     while($row = oci_fetch_array($editWR,OCI_ASSOC))
  19.     {
  20.     $WID=$row ['WEEK_ID'];
  21.     echo'<OPTION VALUE='."$WID".'>'.$WID.'</OPTION>';
  22.     }
  23.     echo '</SELECT>'.'</div>'.'</td>'.'</tr>'.'</table>';
i hope it must help ....
check:i think mysql use '+' instead of '.' to concatenate html elements in echo field.
Jul 8 '10 #7
6,050 Expert 4TB
That code is just awful. Please don't offer help if you're going to post such awful examples.

1. Why are you concatenating strings that simply do not need to be concatenated?
2. Why switch, part way through a string, from single-quotes to double-quotes?
3. Variables are not parsed within single-quoted strings, so line #21 will not work as you expect.

Furthermore, please don't resurrect such old threads.

Jul 8 '10 #8
first thing first...i am newbie
1.if i do not concatenate it shows "HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server error has occurred."
if there is a way to avoid it that will be really helpful may be some setting in php.ini or something else
because the code is in php and the code which is concatenated is in basic html.I think this is the cause the error ....concatenation sort out the gap between two
.then it works fine

2.double quotes are used for string which is echoed as written which are neither variable nor html elements

3.yes you are right line #21 is not working.What change do I need to make?let me try....your help will be appreciated.
I am not sure extent of correctness of these...I change values and try things and this program is working fine for me on base php,sql,oracle,iis.

if anything that is wrong here i will surely like to know the reasons...
thanks @Markus's Avatar
for pointing out my mistakes.This saved a lot of my time.
Jul 8 '10 #9
line 21 corrected : '$WID'->"$WID".
Jul 9 '10 #10
1,168 Expert 1GB
What Markus means by "concatination is not needed" is instead of:
Expand|Select|Wrap|Line Numbers
  1. echo '<table border=1>'.'<tr>'.'<td>'.'<div>';
  2. // USE
  3. echo '<table border=1><tr><td><div>';
Line 21 should be:
Expand|Select|Wrap|Line Numbers
  1. echo '<OPTION VALUE=\''.$WID.'\'>'.$WID.'</OPTION>';
  2. // OR
  3. echo "<OPTION VALUE='$WID'>$WID</OPTION>";
Notice the space after the echo. You are right about there being a difference between a single quote and a double, but if you are breaking the string to put a variable (option 1), you do not need to put the variable in double quotes. If you prefer to not break the string, you can have the whole string in double quotes and do not need to break it for a variable. Also, think about the HTML when you're writing a PHP string. Your <option> should look like:
Expand|Select|Wrap|Line Numbers
  1. <option value='myVal'>myVal</option>
  2. // NOT
  3. <option value=myVal>myVal</option>
So you need to escape some strings using '\'.

That's all for now.
Jul 9 '10 #11
Thank you so much it really very help me once again thank you so much
Oct 27 '14 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Dan | last post by:
Hello all, I am getting records from a db and displaying the records to the user through a drop down menu in an asp page. Each record has 6 fields and I need to display them all to the user in...
by: hemanth.singamsetty | last post by:
Hello there, I've a drop down menu (created using CSS & Javascript -- see code below). My problem is, whenever I click a link on the menu the new page replaces the current page (and the menu...
by: phil | last post by:
We are developing specs. for a website for a nonprofit org, with database for membership related functions. But..question is regarding drop down menu links. We will have 20 category-pages, and...
by: mmarif4u | last post by:
Hi everyone, I have a little problem in php coding. i have mysql table guestbook: Fields are Id,name,email,comment,datetime. Now i want to search the database by php query using a Dropdown menu...
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
by: Archanak | last post by:
Hi, I am using 2-level CSS Drop Down Menu in my perl/CGI program. here is the code. #!c:/perl/bin/perl.exe use CGI qw(:standard);
by: mjohnson0321 | last post by:
I am trying to incorporate a CSS drop-down menu into a site (suckerfish menu). The menu gets lost behind the content below it, but only on one of the drop downs (News). The error occurs on all of...
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
by: buzzard724 | last post by:
Ul li drop down menu works in FF not quite in IE Thank you for looking at this. The page is generated dynamically by php, js and jquery. The drop down menu ul- reports-li - works fine in FF. In...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.