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

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=mysql_query("SELECT DISTINCT semester, year from
schoolproject_pics ORDER BY year
DESC");
echo "<select name=\"semester\" onchange=\"GoTo()\">";
echo "<option value=\"$semester\">-Semester Year-</option>";
while($data = mysql_fetch_array($sql_query)){
if($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$data[semester]\">$data[semester]:$data[year]</option><BR>";
}
echo "<option
value=\"$data[semester]\">$data[semester]:$data[year]</option>"; }
echo "</select>";
mysql_free_result($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=$HTTP_GET_VARS['semester'];
$yearnow=$HTTP_GET_VARS['year'];
if((isset($semesternow) and strlen($semesternow) 0) and
(isset($yearnow) and strlen($yearnow) 0)){
print("<input type=\"hidden\" ID=\"semesterchosen\"
value=\"$semesternow\">");
print("<input type=\"hidden\" ID=\"yearchosen\"
value=\"$yearnow\">");
$sql_query2=mysql_query("SELECT DISTINCT school from
schoolproject_pics
WHERE semester='$semesternow' AND
year='$yearnow'");
echo "<select name=\"school\" onchange=\"GoMore()\">";
echo "<option value=\"$school\">-- School --</option>";
while(list($school) = mysql_fetch_array($sql_query2)){
echo "<option value=\"$school\">$school</option>";
}
echo "</select>";
mysql_free_result($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=\"$data[semester]\">$data[semester]:$data[year]</option><BR>";
}

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

Oct 1 '06 #1
2 1612
cp**********@yahoo.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=mysql_query("SELECT DISTINCT semester, year from
schoolproject_pics ORDER BY year
DESC");
echo "<select name=\"semester\" onchange=\"GoTo()\">";
echo "<option value=\"$semester\">-Semester Year-</option>";
while($data = mysql_fetch_array($sql_query)){
if($data[semester]==@$semester && $data[year]==@$year){
echo "<option value
selected=\"$data[semester]\">$data[semester]:$data[year]</option><BR>";
}
echo "<option
value=\"$data[semester]\">$data[semester]:$data[year]</option>"; }
echo "</select>";
mysql_free_result($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=$HTTP_GET_VARS['semester'];
$yearnow=$HTTP_GET_VARS['year'];
if((isset($semesternow) and strlen($semesternow) 0) and
(isset($yearnow) and strlen($yearnow) 0)){
print("<input type=\"hidden\" ID=\"semesterchosen\"
value=\"$semesternow\">");
print("<input type=\"hidden\" ID=\"yearchosen\"
value=\"$yearnow\">");
$sql_query2=mysql_query("SELECT DISTINCT school from
schoolproject_pics
WHERE semester='$semesternow' AND
year='$yearnow'");
echo "<select name=\"school\" onchange=\"GoMore()\">";
echo "<option value=\"$school\">-- School --</option>";
while(list($school) = mysql_fetch_array($sql_query2)){
echo "<option value=\"$school\">$school</option>";
}
echo "</select>";
mysql_free_result($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=\"$data[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=...&year=... ?

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**********@yahoo.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
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...
14
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 ;...
13
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...
1
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...
7
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...
1
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...
1
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...
0
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...
3
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
BarryA
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...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...

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.