Connecting Tech Pros Worldwide Forums | Help | Site Map

very simple drop-down list...

max
Guest
 
Posts: n/a
#1: Sep 19 '05
Hi! I'm having a problem with a very simple drop-down list since the
page comes out with no elements in the drop-down but giving no errors.
This is the code:


<form name="year_search_form" method="post" action="results.php">
<select name="select_year" id="select_year">
<?
$query="SELECT * FROM table ORDER BY year";
$result = mysql_query($query) or die ("Error in query: $query. "
..mysql_error());

while ($line = mysql_fetch_array($result)) {
print ("<OPTION value=".$line['year']."></OPTION>"); }
?>
</select>
</form>

The connection with the DB is established and working..
Thanks for your help!!

Steve
Guest
 
Posts: n/a
#2: Sep 19 '05

re: very simple drop-down list...


[color=blue]
> <form name="year_search_form" method="post" action="results.php">
> <select name="select_year" id="select_year">
> <?
> $query="SELECT * FROM table ORDER BY year";
> $result = mysql_query($query) or die ("Error in query: $query. "
> .mysql_error());[/color]

View the HTML source - any error message will be invisible via your
browser because you are in the middle of specifying a form and dropdown
list.

---
Steve

Geoff Berrow
Guest
 
Posts: n/a
#3: Sep 19 '05

re: very simple drop-down list...


I noticed that Message-ID: <lomXe.7950$9l.252465@twister1.libero.it>
from max contained the following:
[color=blue]
> print ("<OPTION value=".$line['year']."></OPTION>"); }[/color]

Duh...
print ("<OPTION>".$line['year']."</OPTION>"); }

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
max
Guest
 
Posts: n/a
#4: Sep 19 '05

re: very simple drop-down list...


Steve probably wrote the following stuff on 19/09/2005 1.14:[color=blue][color=green]
>><form name="year_search_form" method="post" action="results.php">
>><select name="select_year" id="select_year">
>><?
>>$query="SELECT * FROM table ORDER BY year";
>>$result = mysql_query($query) or die ("Error in query: $query. "
>>.mysql_error());[/color]
>
>
> View the HTML source - any error message will be invisible via your
> browser because you are in the middle of specifying a form and dropdown
> list.[/color]

ok, this is the html output source :

<form name="year_search_form" method="get" action="results.php">
<select name="select_year" id="select_year">

</select>
<input name="submit" type="submit" class="search_button" value="Search">
</form>

it looks like it doesn't get anything...
I tried a simple loop on the same page and it outputs the data fine...
max
Guest
 
Posts: n/a
#5: Sep 19 '05

re: very simple drop-down list...


Geoff Berrow probably wrote the following stuff on 19/09/2005 1.17:[color=blue]
> I noticed that Message-ID: <lomXe.7950$9l.252465@twister1.libero.it>
> from max contained the following:
>
>[color=green]
>> print ("<OPTION value=".$line['year']."></OPTION>"); }[/color]
>
>
> Duh...
> print ("<OPTION>".$line['year']."</OPTION>"); }
>[/color]

tried as you said but still nothing...
Darkstar 3D
Guest
 
Posts: n/a
#6: Sep 19 '05

re: very simple drop-down list...


Please post a couple of lines of the html source in the problem area.
Geoff's change looks spot on to me.

Steve
Guest
 
Posts: n/a
#7: Sep 19 '05

re: very simple drop-down list...


[color=blue]
> <select name="select_year" id="select_year">
>
> </select>[/color]
[color=blue]
> it looks like it doesn't get anything...
> I tried a simple loop on the same page and it outputs the data fine...[/color]


Wait... print is not a function! Remove the parentheses, and try this:

while ($line = mysql_fetch_array($result))
{
print "<OPTION
value=".$line['year'].">".$line['year']."</OPTION>";
}

---
Steve

Darkstar 3D
Guest
 
Posts: n/a
#8: Sep 19 '05

re: very simple drop-down list...


<---- Got plastered by that one!

Geoff Berrow
Guest
 
Posts: n/a
#9: Sep 19 '05

re: very simple drop-down list...


I noticed that Message-ID:
<1127088877.010943.86850@f14g2000cwb.googlegroups. com> from Steve
contained the following:
[color=blue]
>Wait... print is not a function! Remove the parentheses[/color]

True but that's not the problem. There are obviously no rows returned
by the query.

What I usually do is echo the SQL and paste it into phpMyadmin to check
the query.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
David C.
Guest
 
Posts: n/a
#10: Sep 19 '05

re: very simple drop-down list...


Instead of:

<?
$query="SELECT * FROM table ORDER BY year";
$result = mysql_query($query) or die ("Error in query: $query. "
..mysql_error());


while ($line = mysql_fetch_array($result)) {
print ("<OPTION value=".$line['year']."></OPTION>"); }
?>

Try this:

<?
$query="SELECT * FROM table ORDER BY year";
$result = mysql_query($query) or die ("Error in query: $query. "
..mysql_error());
$num_rows = mysql_num_rows($result);

for ($count = 0; $count < $num_rows; $count++) {
$line = mysql_fetch_array($result);
print ("<OPTION
value=".$line['year'].">".$line['year']."</OPTION>"); }
?>

mars
Guest
 
Posts: n/a
#11: Sep 19 '05

re: very simple drop-down list...


Geoff Berrow probably wrote the following stuff on 19/09/2005 8.29:[color=blue]
> I noticed that Message-ID:
> <1127088877.010943.86850@f14g2000cwb.googlegroups. com> from Steve
> contained the following:
>
>[color=green]
>>Wait... print is not a function! Remove the parentheses[/color]
>
>
> True but that's not the problem. There are obviously no rows returned
> by the query.
>
> What I usually do is echo the SQL and paste it into phpMyadmin to check
> the query.
>[/color]

thanks for your help guys, i tried to echo to output on the page without
using the "html select tag" and it works fine showing all the years..
But still it doesn't display anything in the dropdown menu.. :-\
mars
Guest
 
Posts: n/a
#12: Sep 19 '05

re: very simple drop-down list...


Darkstar 3D probably wrote the following stuff on 19/09/2005 1.58:[color=blue]
> Please post a couple of lines of the html source in the problem area.
> Geoff's change looks spot on to me.
>[/color]

ok, well I put this:

<form name="year_search_form" method="get" action="results.php">
<select name="select_year" id="select_year">
<?php
$num_rows = mysql_num_rows($result);
for ($count = 0; $count < $num_rows; $count++) {
$line = mysql_fetch_array($result);
print ("<OPTION value=".$line['year'].">".$line['year']."</OPTION>");}
?>
</select>
<input name="submit" type="submit" class="search_button" value="Search">
</form>
======
while just under it i displayed this to see if the sql query worked:
======
<?php
$line = mysql_fetch_array($result);
echo($line['year']);
while ($line = mysql_fetch_array($result)) {
print ("<br>".$line['year']); }
?>

and it outputs correctly the years contained in the table..
Thanks for your time!
Steve
Guest
 
Posts: n/a
#13: Sep 19 '05

re: very simple drop-down list...



Yep quiet right, had no PHP to test with before, but now I do and this
makes no difference.

OP says he tried dumping the query results and got what he expected, so
must have used different queries in each case (or DB content has
changed.)

---
Steve

mars
Guest
 
Posts: n/a
#14: Sep 19 '05

re: very simple drop-down list...


max probably wrote the following stuff on 19/09/2005 1.04:[color=blue]
> Hi! I'm having a problem with a very simple drop-down list since the
> page comes out with no elements in the drop-down but giving no errors.
> This is the code:
>
>
> <form name="year_search_form" method="post" action="results.php">
> <select name="select_year" id="select_year">
> <?
> $query="SELECT * FROM table ORDER BY year";
> $result = mysql_query($query) or die ("Error in query: $query. "
> .mysql_error());
>
> while ($line = mysql_fetch_array($result)) {
> print ("<OPTION value=".$line['year']."></OPTION>"); }
> ?>
> </select>
> </form>
>
> The connection with the DB is established and working..
> Thanks for your help!![/color]


Fixed it! The main problem were the quotes :

print ('<OPTION value="'.$line['year'].'">'.$line['year'].'</OPTION>');

here it works.
Thanks!
Geoff Berrow
Guest
 
Posts: n/a
#15: Sep 19 '05

re: very simple drop-down list...


I noticed that Message-ID: <IgAXe.8993$9l.272957@twister1.libero.it>
from mars contained the following:
[color=blue]
>Fixed it! The main problem were the quotes :
>
>print ('<OPTION value="'.$line['year'].'">'.$line['year'].'</OPTION>');[/color]

Personally I'd do it like this

print "<OPTION value='".$line['year']."'>".$line['year']."</OPTION>";
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Joseph S.
Guest
 
Posts: n/a
#16: Sep 19 '05

re: very simple drop-down list...


***********
(I am sorry to post in this fashion but I am trying to post this
message since the past three hours, but am unable to, inspite of the
fact that I have been regularly posting to at least five groups every
day and suddenly everything seems to stop working - Google groups also
shows me a confirmation of the post but somehow my posts do not appear
- neither am I blocked or any such thing)
***********

1)I get startup error messages:
"cannot load c:\php\php_curl.dll - the specified file cannot be found"
although the file is very much there at exactly that location
Not only for this file but for many extension files like php_mysql.dll,
php_oracle.dll, php_mssql.dll, php_exif.dll etc.

2)the extensions_dir setting is "c:\php" without an ending backslash.

3)The php.ini file is residing at c:\php

4)The php.ini file in c:\windows has all extensions disabled so it does
not look as though that php.ini file is the source of the messages

5)There is a extension entry for php_win32api.dll which also gives a
not found error.
Is it the older version of php_win32std.dll, php_win32service.dll and
php_win32scheduler.dll files which are present but
their names are not there by default in the php.ini ?

************************************************** ************************************************
6)How do I debug PHP like you can debug Java in Eclipse or NetBeans and
C/C++ in MS Visual Studio?
************************************************** ************************************************

7)database access through odbc works.

8)How do I install PHP as both a CGI extension under Apache 2.0.5x and
as a module (php5apache2.dll with a LoadModule in httpd.conf)

Joseph S.
Guest
 
Posts: n/a
#17: Sep 19 '05

re: very simple drop-down list...


test post please ignore

Guest
 
Posts: n/a
#18: Sep 19 '05

re: very simple drop-down list...


In article <9hoti1938kffldfd3ptpmqienldaten49a@4ax.com>,
Geoff Berrow <blthecat@ckdog.co.uk> wrote:
[color=blue]
>print "<OPTION value='".$line['year']."'>".$line['year']."</OPTION>";[/color]

Or:

printf("<OPTION value=\"%s\">%s</OPTION>",$line['year'],$line['year']);

--
http://yosemitenews.info/
Darkstar 3D
Guest
 
Posts: n/a
#19: Sep 20 '05

re: very simple drop-down list...


Am I to understand that it is working now? Did you just modify the 2nd
query and place it in the form code?

By HTML source, I meant what you are getting as a result in browser.

mars
Guest
 
Posts: n/a
#20: Sep 20 '05

re: very simple drop-down list...


Darkstar 3D probably wrote the following stuff on 20/09/2005 1.22:[color=blue]
> Am I to understand that it is working now? Did you just modify the 2nd
> query and place it in the form code?[/color]

now it is working with the code that I posted in the other message (the
problem was caused by myself messing up with single/double quotes). :-)
Bugz
Guest
 
Posts: n/a
#21: Sep 23 '05

re: very simple drop-down list...


Why not just change the print for an echo ?

Closed Thread