473,803 Members | 2,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PLEASE HELP - Drop down list related question

Could some PHP guru please help me? I am creating a dynamic dropdown
list using a code snippet(Section A) as below:
Section A:
$sql_query=mysq l_query("SELECT DISTINCT semester, year from
schoolproject_p ics ORDER BY year
DESC");
echo "<select name=\"semester \" onchange=\"GoTo ()\">";
echo "<option value=\"$semest er\">-Semester Year-</option>";
while($data = mysql_fetch_arr ay($sql_query)) {
if($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$dat a[semester]\">$data[semester]:$data[year]</option><BR>";
}
echo "<option
value=\"$data[semester]\">$data[semester]:$data[year]</option>"; }
echo "</select>";
mysql_free_resu lt($sql_query);

The 'GoTo()' Javascript re-draws the same page with the chosen values
of 'semester' and 'year' so that
the values can be recovered by $_HTTP_GET_VARS , stored in two hidden
variables and then used in
another query to create another dynamic drop-down list, as in code
snippet (Section B).

$semesternow=$H TTP_GET_VARS['semester'];
$yearnow=$HTTP_ GET_VARS['year'];
if((isset($seme sternow) and strlen($semeste rnow) 0) and
(isset($yearnow ) and strlen($yearnow ) 0)){
print("<input type=\"hidden\" ID=\"semesterch osen\"
value=\"$semest ernow\">");
print("<input type=\"hidden\" ID=\"yearchosen \"
value=\"$yearno w\">");
$sql_query2=mys ql_query("SELEC T DISTINCT school from
schoolproject_p ics
WHERE semester='$seme sternow' AND
year='$yearnow' ");
echo "<select name=\"school\" onchange=\"GoMo re()\">";
echo "<option value=\"$school \">-- School --</option>";
while(list($sch ool) = mysql_fetch_arr ay($sql_query2) ){
echo "<option value=\"$school \">$school</option>";
}
echo "</select>";
mysql_free_resu lt($sql_query2) ;

Now the question:
When the page is re-drawn, how can the values of semester and year
previously chosen, be displayed in the first drop down list. I tried to
do it using the following, but it does not do anything:

f($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$dat a[semester]\">$data[semester]:$data[year]</option><BR>";
}

Any help would be greatly appreciated. Thanks in advance for your help.

Oct 1 '06 #1
2 1628
cp**********@ya hoo.com wrote:
Could some PHP guru please help me? I am creating a dynamic dropdown
list using a code snippet(Section A) as below:
Section A:
$sql_query=mysq l_query("SELECT DISTINCT semester, year from
schoolproject_p ics ORDER BY year
DESC");
echo "<select name=\"semester \" onchange=\"GoTo ()\">";
echo "<option value=\"$semest er\">-Semester Year-</option>";
while($data = mysql_fetch_arr ay($sql_query)) {
if($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$dat a[semester]\">$data[semester]:$data[year]</option><BR>";
}
echo "<option
value=\"$data[semester]\">$data[semester]:$data[year]</option>"; }
echo "</select>";
mysql_free_resu lt($sql_query);

The 'GoTo()' Javascript re-draws the same page with the chosen values
of 'semester' and 'year' so that
the values can be recovered by $_HTTP_GET_VARS , stored in two hidden
variables and then used in
another query to create another dynamic drop-down list, as in code
snippet (Section B).

$semesternow=$H TTP_GET_VARS['semester'];
$yearnow=$HTTP_ GET_VARS['year'];
if((isset($seme sternow) and strlen($semeste rnow) 0) and
(isset($yearnow ) and strlen($yearnow ) 0)){
print("<input type=\"hidden\" ID=\"semesterch osen\"
value=\"$semest ernow\">");
print("<input type=\"hidden\" ID=\"yearchosen \"
value=\"$yearno w\">");
$sql_query2=mys ql_query("SELEC T DISTINCT school from
schoolproject_p ics
WHERE semester='$seme sternow' AND
year='$yearnow' ");
echo "<select name=\"school\" onchange=\"GoMo re()\">";
echo "<option value=\"$school \">-- School --</option>";
while(list($sch ool) = mysql_fetch_arr ay($sql_query2) ){
echo "<option value=\"$school \">$school</option>";
}
echo "</select>";
mysql_free_resu lt($sql_query2) ;

Now the question:
When the page is re-drawn, how can the values of semester and year
previously chosen, be displayed in the first drop down list. I tried to
do it using the following, but it does not do anything:

f($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$dat a[semester]\">$data[semester]:$data[year]</option><BR>";
}

Any help would be greatly appreciated. Thanks in advance for your help.
I'm not completely clear what you're trying to do.

Are you saying that GoTo() submits a new HTTP request with
?semester=...&y ear=... ?

I'm also not clear what you mean to have in your <option>, but you seem
to be saying
<option value selected = ...
where I think you mean
<option selected value = ...

Furthermore you are setting $semesternow from the CGI variable ($_GET is
preferred over $HTTP_GET_VARS since 4.1.0, but that's presumably not
relevant), but seem to be comparing the value retrieved from the DB with
$semester, not $semesternow.

Does this help?

Colin

Oct 1 '06 #2
Hello,

on 09/30/2006 11:05 PM cp**********@ya hoo.com said the following:
Could some PHP guru please help me? I am creating a dynamic dropdown
list using a code snippet(Section A) as below:
If I got you right, you want to display linked select inputs with
options taken from database queries results, so when on you change one
select it display another with options dependent on the selected value
of the first, right?

In that case, you may want to take a look at this forms generation class
that comes with a plug-in to do that.

Actually, it does it better as it can use AJAX to update the dependent
select input options without reloading. It supports MySQL and many other
databases.

Here is an example page of what it does. This is not the AJAX/Database
driven version. For that see other example scripts that comes with the
class:

http://www.phpclasses.org/browse/file/9879.html

The class is here:

http://www.phpclasses.org/formsgeneration
--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Oct 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1553
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...
14
3114
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ; ExpenseType Data: 1 ; FOOD 2 ; AIRLINE 3 ; FARE
13
5262
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data structures? Thanks for any hints, Leszek Taratuta
1
9662
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
7
2440
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit the second drop down to just the related information. Explaining this is obviously challeging. So I'll try to draw a picture: (drop down 1) Select number --- once selected description is populated in text box (drop down 2) based on first...
1
981
by: jyoti pandey | last post by:
sir i have taken to drop down list and i want to select any data in drop down list1, accordind to this data display related data in drop down list2. how i can do this i am working in asp.net with c# the coding i have done is protected void Page_Load(object sender, EventArgs e) { strconn = new OleDbConnection(); strconn.ConnectionString = "Provider=msdaora.1; user id=payroll; password=payroll; data source=payroll"; ...
1
2970
by: student2008 | last post by:
Sorry about the title its a tricky one. I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button is pressed then a text box appears to enter a new question or answer or both. the newly entered data is then inserted into mysql. The newly entered data is then requested by mysql_fetch_array() to be displayed as options in the drop down list. If...
0
1118
by: mpathfinder | last post by:
hi guys . sorry for my weak Eng. writing . I want to design a component that in one of it's properties i'd able to collect list of controls of the windows form that hosts this component in a drop down form . for example when i add this component to a windows from which contains a TextBox and a Lable it shows their's name in a list in drop down format that i can select one of them in design mode . clear example of my question is the...
3
5912
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I analyze each word and rebuild the text string as a combination of correct text (not misspelled) and a drop down list offering suggestions in place of any misspelled words. Pretty common stuff using pspell. I display the new string so that the user...
0
9566
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10555
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
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10300
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7607
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
6844
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
5503
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...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2974
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.