5 Replies - 410 Views - Last Post: 04 October 2012 - 06:48 AM Rate Topic: -----

#1 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

while() loop not working.

Posted 01 October 2012 - 11:50 PM

Hello all. I got an while() loop that is being a pain in the butt. I dont know why it isnt working. I am using the exact same code in another spot on the site and it works perfectly.

here is the code that isnt working.
   <?php
while($row_a = mysql_fetch_array($res))
{ 
?>
        <div id="rec_title">- <?php echo $row_a['title']; ?></div> <div id="status"><img src="/images/usercp/<?php echo $row_a['approved'];?>.png" /></div><br/>
		<?php } ?>



here is the exact same loop on another page doing the same thing and working
<?php
while($row_a = mysql_fetch_array($res))
{ 
?>
<div id="inbox_content">
<div id="from"><?php  echo $row_a['from_user']; ?></div>
<div id="title"><a href="view_pm.php?id=<?php echo $row_a['pm_id']; ?>">
  <?php  echo $row_a['title']; ?>
</a></div>
<div id="delete"><a href="delete_pm.php?id=<?php echo $row_a['pm_id']; ?>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('delete','','images/usercp/delete_button_over.png',1)"><img src="images/usercp/delete_button.png" alt="Delete" name="delete" width="55" height="18" border="0" id="delete2" /></a></div>
</div>
<?php } ?>


Is This A Good Question/Topic? 0
  • +

Replies To: while() loop not working.

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1001
  • View blog
  • Posts: 3,561
  • Joined: 05-June 09

Re: while() loop not working.

Posted 02 October 2012 - 02:04 AM

What do you mean by

Quote

isn't working
?

What is the value of $res, have you used var_dump to check that it is indeed a MySQL Result Resource?
Was This Post Helpful? 0
  • +
  • -

#3 Null::Void()  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-October 12

Re: while() loop not working.

Posted 04 October 2012 - 06:12 AM

Why did you do <?php } ?>, Your code is all messy, i am not sure why it works on the other one. Try to contain all your code in one <?php ?> and never do what you did with the braces, Also post the Query but i am pretty sure its the structure of your code.
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1001
  • View blog
  • Posts: 3,561
  • Joined: 05-June 09

Re: while() loop not working.

Posted 04 October 2012 - 06:25 AM

View PostNull::Void(), on 04 October 2012 - 02:12 PM, said:

Why did you do <?php } ?>, Your code is all messy, i am not sure why it works on the other one. Try to contain all your code in one <?php ?> and never do what you did with the braces

Because he broke out of PHP to output HTML. It's not the right way to achieve the result he wants, but it's certainly valid.

This post has been edited by RudiVisser: 04 October 2012 - 06:27 AM

Was This Post Helpful? 0
  • +
  • -

#5 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 164
  • View blog
  • Posts: 600
  • Joined: 12-October 09

Re: while() loop not working.

Posted 04 October 2012 - 06:27 AM

The issue is not with the loop, it is with the $res variable you are using in the loop. Make sure it contains what you expect it to.
Was This Post Helpful? 0
  • +
  • -

#6 Null::Void()  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-October 12

Re: while() loop not working.

Posted 04 October 2012 - 06:48 AM

View PostRudiVisser, on 04 October 2012 - 06:25 AM, said:

View PostNull::Void(), on 04 October 2012 - 02:12 PM, said:

Why did you do <?php } ?>, Your code is all messy, i am not sure why it works on the other one. Try to contain all your code in one <?php ?> and never do what you did with the braces

Because he broke out of PHP to output HTML. It's not the right way to achieve the result he wants, but it's certainly valid.

I know its valid but it seems like an easy way to get lost and have things not work as expected.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1