Blank Drop Menu

Hi Everyone

I hope someone can realy help me, I’ve tried several forums and no one is been able to help me.
The problem with this script is that all I’m getting is a blank drop menu.
I’ve checked the rows number and I have it right.
Please help

[php]

<?PHP mysql_connect("localhost", "xxxx_xxxx", "xxxx") or die(mysql_error()); mysql_select_db("xxxx") or die(mysql_error()); $sql = "SELECT DISTINCT date FROM `ihsreg` ORDER BY 'date' DESC"; if (!(@ $result = mysql_query($sql))) { print "There was an error running your query:

n". $sql . "

n"; } print '
n'; print ' Choose One '; while ($row = mysql_fetch_row($result)) { $id = $row[0]; $date = $row[26]; print " $date
n"; } print ''; ?>

[/php]

Admin Edit: Added [PHP] Code tags for readability. Please see http://phphelp.com/guidelines.php for posting guidelines

Are you closing your tags?

First of all get rid of the @ while debugging. This suppresses errors and you want to see errors while debugging.

Next

I find a problem with this statement:

[php]
if (!(@ $result = mysql_query($sql))) {
print “There was an error running your query:

n”. $sql . “

n”;
}
[/php]

If you put this into words (ignoring the fact that you are suppressing the errors)

IF ( The next portion is not true (Assign to $ result the outcome of the function of mysql_query($sql) ) {
print a statement
}

Since mysql_query() is a valid function, and will typically ALWAYS return a result (even if the result is an empty set), it should successfully get assigned to $result, thus your if statement will NEVER evaluate to true.

I suspect the error may be in your sql statement, and because you are suppressing errors with the @ sign, you might miss something else.

To get the mysql errors, use the mysql_error or mysql_errno functions.

http://us2.php.net/mysql_error
http://us2.php.net/mysql_errno

one more sugesstion:
view and maybe post the resulting HTML-source
the
may be the prob as well.
At that point the browser may think that ur was missing the closing tag and close ur select at that point, ignoring the following option tags.

@paul: doesn’t a assignment alway evaluate to the assigned value?
i have never seen an @ at this point (and of cause not while debugging) but i should work.

I could be wrong, but I believe what I have stated above is correct. When you have the assignment as the condition it validates as TRUE if the assignment was successful and FALSE if the assignment failed.

If you want to evaluate if the VALUE of the assignment was successful you should do something more like:

[php]
$result = mysql_query($sql);
if (!$result ) {
print “There was an error running your query:

n”. $sql . “

n”;
}
[/php]

Indeed even http://php.net does it this way in their examples.
Just have a look at the example at http://us2.php.net/manual/en/function.mysql-query.php

found it:

The assignment itself evaluates to the assigned value, in this case 5. In practice, it means that '$a = 5', regardless of what it does, is an expression with the value 5.
http://php.net/manual/en/language.expressions.php

but the @ is misplaced (it woun’t ever hide the error):
@ has a higher precedence than =
http://de2.php.net/manual/en/language.o … precedence

meaning:
@ $result = mysql_query()
is the same as:
(@$result) = mysql_query()
[edit: my foult, it would be @($result = mysql_query()) ]

the right way would be:
$result = @mysql_query()

but as paul said, not wile debugging!

Indeed I just tested it as
[php]
if (!($result = mysql_query($sql))) {
print “There was an error running your query:

n”. $sql . “

n”;
}
[/php]

(with a query that fails to provide adequate data) and it works. So I stand corrected.

HOWEVER, I have also tried it with a FLAWED function
[php]
if (!(@ $result = mysql_queryH($sql))) {
print “There was an error running your query:

n”. $sql . “

n”;
}
[/php]
And the error was suppressed. Additionally I tried it like these ways

[php]
if (!( $result = @mysql_queryH($sql))) {
print “There was an error running your query:

n”. $sql . “

n”;
}
[/php]

And

[php]
if (!@ $result = mysql_queryH($sql)) {
print “There was an error running your query:

n”. $sql . “

n”;
}
[/php]
And each time the error was suppressed.

Don’t really have time to look into reasons right now, but wanted you to be aware.

good 2 know.

this seems to counts for @ as well:

Note: Although = has a lower precedence than most other operators, PHP will still allow expressions similar to the following: if (!$a = foo()), in which case the return value of foo() is put into $a.
http://php.net/manual/en/language.expressions.php
Sponsor our Newsletter | Privacy Policy | Terms of Service