473,322 Members | 1,421 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,322 software developers and data experts.

fetch data from database display data in drop down menu

hi,
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 39029
please provid you database table info and let us know what do u want to retrive ...
Nov 17 '06 #2
Hi,

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
</select>

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
ronverdonk
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 ...
hi,
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
ronverdonk
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");
  2.  
  3.   if(!conn){
  4.   echo "connection error";
  5.   exit;
  6.   }
  7.  
  8.     session_start(); 
  9.     $USER_ID=$_SESSION['USER_ID'];
  10.  
  11.     $query="SELECT WEEK_ID FROM WEEKLY_REPORTS WHERE WR_EMPLOYEE_ID=$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>';
  24.  
i hope it must help ....
check:i think mysql use '+' instead of '.' to concatenate html elements in echo field.
Jul 8 '10 #7
Markus
6,050 Expert 4TB
@techsoul
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.

Mark.
Jul 8 '10 #8
first thing first...i am newbie
now
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
Markus
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
TheServant
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

11
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...
2
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...
3
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...
3
mmarif4u
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...
4
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...
22
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);
0
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...
2
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...
6
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...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.