SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    While Loop mysteriously Stops at 1st row!!!

    Hello,

    We have a really bit of mystery on our hand here which I am hoping you can help with.

    We have a While Loop which when it has more than 1 rows it, it is still STOPPING at row 1 and not printing the other rows!

    You can see in this example that it has 7 rows:
    echo 'Num Rows are: ' . mysql_num_rows($query_get_ans);

    it prints out: Num Rows are: 7

    But the while Loop which is listed below only prints out the 1st Row! What is the problem?

    while ($result_get_ans = mysql_fetch_array($query_get_ans)) {

    $ans_id = $result_get_ans['a_id'];
    $q_id = $result_get_ans['qa_id'];
    $ans_date_added = $result_get_ans['date_added'];
    $q_head_line = $result_get_ans['head_line'];
    $ans_body = $result_get_ans['body'];
    $admin_status = $result_get_ans['admin_status'];

    ?>
    <tr bgcolor="#ffffff">
    <td align="center">
    <?php echo $num; ?>
    </td>
    <td align="center">
    <?php echo $ans_date_added; ?>
    </td>
    <td align="left">
    <?php echo $q_head_line; ?>
    </td>
    <td align="left">
    <?php echo '<a href="qanda.php?q_id=' . $q_id . '">' . $ans_body . '</a>'; ?>
    </td>
    <td align="center">
    <?php echo $admin_status; ?>
    </td>
    </tr>


    <?php
    }//CLOSES While Loop
    ?>


    ThanX,

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    are you doing anything else with $query_get_ans before this loop begins?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Just this:

    if (mysql_num_rows($query_get_ans) == 0) {

    echo
    '<tr bgcolor="#ffffff">
    <td colspan="7" valign="middle" align="center">
    <div class="anx_text_lbl">
    No Answers Posted by me yet - <a href="qs_by_cat.php">View Recent Questions</a>
    </div>
    </td>
    </tr>
    ';
    } else {

    while ($result_get_ans = mysql_fetch_array($query_get_ans)) {

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I figured what the problem is.
    Something really stupid. A typo really. What you get when 1 person (me) is doing 10 peoples work

    ThanX anyway & have a great day

    Anoox search engine volunteer

    www.anoox.com


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
  •