|
Posted by Colin Fine on 10/01/06 18:59
cpptutor2000@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
Navigation:
[Reply to this message]
|