While loop

I have an odd result that I am missing. I am trying to echo a query that should be showing a number of results, instead I get 1 result echo’d twice.

Here is the code



<?php
$maxRows_profile_app = 5;
$pageNum_profile_app = 0;
if (isset($_GET['pageNum_profile_app'])) {
  $pageNum_profile_app = $_GET['pageNum_profile_app'];
}
$startRow_profile_app = $pageNum_profile_app * $maxRows_profile_app;

mysql_select_db($database_assess, $assess_remote);
$query_profile_app = "SELECT appraiser.app_fname
     , appraiser.app_intl
     , appraiser.app_lname
     , appraiser.app_image
     , appraiser.app_firm_name
     , appraiser.app_city
     , appraiser.app_state
     , appraiser.app_url
	 , appraiser.app_logo
  FROM appraiser
   WHERE appraiser.app_status = '2' ORDER BY app_submitted DESC ";
$query_limit_profile_app = sprintf("%s LIMIT %d, %d", $query_profile_app, $startRow_profile_app, $maxRows_profile_app);
$profile_app = mysql_query($query_limit_profile_app, $assess_remote) or die(mysql_error());
$row_profile_app = mysql_fetch_assoc($profile_app);
?>
<?php

while($row = mysql_fetch_array($profile_app))	{
	
?>

<p class="afrmname"><?php echo $row_profile_app['app_firm_name'].'<br />' ; ?>

<?php echo $row_profile_app['app_fname'];?>
<?php echo $row_profile_app['app_lname']; ?> <br/>
<?php echo $row_profile_app['app_state'];?>

</p>
<p ><a href=" <?php echo $row_profile_app['app_url']; ?>" target="_blank"><?php if(!empty($row_profile_app['app_firm_name'])) echo 'Please Visit'.'<br />'.  $row_profile_app[app_firm_name].'\\'s '.'<br />'.'
Web Site'.'<br />'.' <hr/>';
}
?></a>

Can anyone see what I am missing?

Thank you

Gary

I love this place…everytime I post a question, I read my own question and get my own answer…

I changed:



while($row = mysql_fetch_array($profile_app))


to




while($row_profile_app = mysql_fetch_array($profile_app))


Thanks for readying

Happy New Year

Gary

Unless you didn’t post the complete code, there’s something else that might have to be corrected:


$row_profile_app = mysql_fetch_assoc($profile_app);
?>
<?php 

while($row = mysql_fetch_array($profile_app))    {
    
?> 

Apart from the sequential closing and opening of the php tags, doing that mysql_fetch_assoc before arriving at the loop means you will never display the first row returned by the query.

Guido

Thank you for your reply, I don’t really understand your first sentence, I thought I had posted all of the relevant code.

To your second point, I had run into that issue some time back and forgot the solution, so thank you, that is the final piece to the puzzle. I moved the mysql_fetch_assoc after the loop and it works perfect…

Thanks much!

Gary

What I meant is this: if you have a php closing tag followed by a php opening tag, with no code whatsoever in between


?>
<?php  

then these tags are useless. Just delete them.

But it could have been that you actually do have (html) code between them, but you cut it out to post only the code relevant to your problem.

I understand now. I do that a bit, sometimes a by product of an edit, other times to signal the starting and stopping of a new script / process, but I can see how you thought that I had removed code that I thought irrelevant when perhaps it might have been.

Thanks again.

Gary