SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: While loop

  1. #1
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    SEPA
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 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

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    SEPA
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I love this place...everytime I post a question, I read my own question and get my own answer..

    I changed:

    PHP Code:

    while($row mysql_fetch_array($profile_app)) 
    to

    PHP Code:


    while($row_profile_app mysql_fetch_array($profile_app)) 
    Thanks for readying

    Happy New Year

    Gary

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Unless you didn't post the complete code, there's something else that might have to be corrected:
    PHP Code:
    $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.

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    SEPA
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by gwpaul View Post
    I don't really understand your first sentence, I thought I had posted all of the relevant code.
    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 Code:
    ?>
    <?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.

  6. #6
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    SEPA
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •