473,836 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fetch data from database display data in drop down menu

4 New Member
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 39118
khalidbaloch
61 New Member
please provid you database table info and let us know what do u want to retrive ...
Nov 17 '06 #2
dswethar
65 New Member
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 Recognized Expert Specialist
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("SE LECT 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_ass oc($res)) {
$va = $row['value'];
echo "<option value='$va'>$va </option>";
}
echo '</select>';[/php]
Ronald :cool:
Nov 17 '06 #4
saurabhbpl
4 New Member
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_detail s and sublisting_deta ils.
there are 3 columns In listings_detail s table: listing_id(p.k. ),domain,listin g_title.
And also 3 columns in sublisting_deta ils table: sublisting_id(p .k.),listing_id ,sublisting_tit le.
Now i want to fetch the listing_title and sublisting_titl e and show into the dropdown menu.listing_ti tle should display in mainmenu and sublisting_titl e display in submenu.
Nov 18 '06 #5
ronverdonk
4,258 Recognized Expert Specialist
Well, you have the samples, what more do you want?

Ronald :cool:
Nov 18 '06 #6
techsoul
4 New Member
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 Recognized Expert Expert
@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
techsoul
4 New Member
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 ....concatenati on 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
techsoul
4 New Member
line 21 corrected : '$WID'->"$WID".
Jul 9 '10 #10

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

Similar topics

11
2505
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 the drop down. The problem is that the fields contain values of all different lengths and the columns are not aligned.
2
2587
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 disappears). Is there a way, I can keep the menu always on top. ( A good example of what I'm looking for is similar to the menu bar in http://www.milonic.com/ ).
3
1557
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 each page will have 30-50 links- unique to that page, so 1000+ total for site- on a drop down menu. Need we assume that such links (both plain english description to appear on site, and actual URL to link to- so 2 pieces data really for each...
3
6552
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 (for example Name,Id) with a text search field. What will be the query. Can anyone help me with details. thanks.
4
9302
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 if it works, and if it does not, tell me why it does not work. Thanks.
22
3479
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
3151
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 the browsers I have tested it on (IE6, IE7, Firefox, Opera and Safari). It is probably something simple, but I can't find it! Here is the CSS (using external style sheets): style-temp.css (Main style sheet for the site): * { font-family:...
2
3097
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 that dynamically pulls info from my database to populate a drop down menu. Upon an onChange event, I wish to display the fields related to that pull down menu WITHOUT SUBMITTING THE PAGE. The Senario: Database name: sp.mdb
6
7576
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 the problem that when I went to select the other drop down menus, the selections i made on the multiple select one would clear. Then I had tried putting the multiple select menu last so that the selections wouldn't clear but then after clicking the...
0
2206
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 IE7 the menu displays and if I am very very careful with how I move the mouse I can sometimes manage to catch the submenu - particularly the first time the page is displayed. Usually the menu disappears before I can mouse over it. I guess this is...
0
10832
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10248
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6976
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5815
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.