Forum Moderators: coopster

Message Too Old, No Replies

Print before loop

         

adamnichols45

10:23 am on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi guys why cant i get this to print before the while loop

if(mysql_num_rows($sql) == 0);
print($countie);
while ($row = mysql_fetch_array($boo)){

simply results in error

Parse error: parse error, unexpected T_ELSE in /content/search.php on line 42

grandpa

10:34 am on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What is your IF supposed to be doing? It's terminated without doing anything, and the print may appear to be an unexpected else condition?

Anyway, you might try this instead..

if(mysql_num_rows($sql) == 0) {
print($countie);
while ($row = mysql_fetch_array($boo)){
// processing while
} // endWHILE
} // endIF

Is that what you had in mind? If not, what's on line 42?

adamnichols45

11:02 am on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



excellent grandpa,

thats exactly what i neeed! Looks like i needed them extra braces.

Thanks alot

adamnichols45

11:26 am on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi grandpa again can i ask how i would print a couple of varibles here.

print("No cars VAR1 VAR2 were found");

grandpa

12:27 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I use echo
echo "No cars $VAR1 $VAR2 were found";

This will work:
$VAR1 = "Blue";
$VAR2 = "Red";
print "No cars $VAR1 $VAR2 were found";

No cars Blue Red were found

<edit widgetized>

adamnichols45

12:54 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cool that works great, would you mind telling me the difference between echo and print please

grandpa

1:11 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What makes you think I know the difference between print [us2.php.net] and echo [us2.php.net]...
I just know where to find them. Happy hunting.

FWIW- I just like using echo. The first thing I did in PHP was: echo "Hello World"; It's been that way every since.

hakre

2:43 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo is faster then print. print does return a value, echo not.
more info: [faqts.com...]

ergophobe

11:04 pm on Feb 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Back to the original question...

You have an extra semicolon. You needed the braces for the logic but that was not why you got a parse error. Adding the braces changes the logic.

In the first case (no braces), it would print the message if the if condition were met and it would execute the while regardless.

In the second case, it prints the message and executes the while if the condition is met, and does nothing if $sql!= 0.

Your error message tells you where to look

"unexpected T_ELSE"

That means it was something wrong with an if/else sequence, so you know your if statement is wrong.