2

I am not sure as to why. But the code I have created below is not working. The variable: "$num_rows" is not even being set and has no value (not even 0). Anyone know as to why this issue is occurring?

$result2 = mysql_query("SELECT * FROM `mycity_vehicles` WHERE `id` = '$vehID'");
while($row2 = mysql_fetch_array($result2))
$num_rows = mysql_num_rows($result2);
{
    if(empty($num_rows)) {
        echo "empty";
    }
    else {
        echo $num_rows;
    }
6
  • 1
    im surprised you don't get any syntax errors Commented Dec 19, 2013 at 18:41
  • 1
    You have a brace in the wrong place - you need to move it from the line after $num_rows = mysql_num_rows($result2); to the line before. Commented Dec 19, 2013 at 18:41
  • @Dagon: My guess is he does, but has error reporting off. Commented Dec 19, 2013 at 18:42
  • ok, wasent 100% sure if it was invalid (while being sure it was wrong) or not Commented Dec 19, 2013 at 18:44
  • Actually... Aside from a missing trailing brace at the end, I think it's valid syntax. Commented Dec 19, 2013 at 18:52

2 Answers 2

2

Your syntax is off.

while($row2 = mysql_fetch_array($result2))
$num_rows = mysql_num_rows($result2);
{

should probably be

$num_rows = mysql_num_rows($result2);
while($row2 = mysql_fetch_array($result2))
{
Sign up to request clarification or add additional context in comments.

Comments

2

You did it the wrong order.

$result2 = mysql_query("SELECT * FROM `mycity_vehicles` WHERE `id` = '$vehID'");
$num_rows = mysql_num_rows($result2);
while($row2 = mysql_fetch_array($result2)) {
    if(empty($num_rows)) {
        echo "empty";
    }
    else {
        echo $num_rows;
    }

3 Comments

I wonder why this got downvoted. If it's because it's the same as John Conde's answer, the reason for it would (probably) be that both answers were given at approximately the same time. (Downvoter, see timestamps).
@Fred-ii-, I wonder the same thing.. Probably he has more "Reputation" than me so people feel the need to downvote this, altough I posted mine 6-7 seconds after he did (without knowing it). Anyways it doesn't matter to me as long as the person got the right answer.
Yes, knowing that the correct answer is given to an OP is indeed the important thing. I will upvote this, because you deserve it just as much AND that you did not deserve the downvote. Cheers ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.