SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: do...while?

  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    do...while?

    I need to know if this is right
    PHP Code:
    <?php do { 
    echo 
    "<li><a href=\"profiles.php?id="$row_dollcollection['id'].">";
    echo 
    "<img src=\"dolls/"$row_dollcollection['thumb'}."  alt=".$row_dollcollection['dollsName'].">"
    echo "</a></li>";
    } while (
    $row_dollcollection mysql_fetch_assoc($dollcollection)); ?>
    where Im trying to make each doll (record in the table) display as a <li>,
    the part Im really struggling on is
    PHP Code:
    <?php } while ($row_dollcollection mysql_fetch_assoc($dollcollection)); ?>
    as that seems really complicated, when im just trying to stay in that loop while there are records in the table so would something like this work?
    PHP Code:
    <?php 
    do {
    echo 
    "<li><a href=\"profiles.php?id="$row['id']."\">";
    echo 
    "<img src=\"dolls/"$row['thumb']."\"  alt=".$row_dollcollection['dollsName'].">";
    echo 
    "</a></li>";
    } while (
    $row mysql_fetch_assoc($dollcollection)); 
    ?>
    Thanks
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    It works (but seems to produce an error?
    http://localhost/nikelantiquedolls/wordpress/?page_id=4
    Is there a way to not have the error
    "Oh, and Jenkins--apparently your mother died this morning."

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    actually it not, heres the source
    HTML Code:
     <li><a href="profiles.php?id="><img src="dolls/"  alt=></a></li>
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,131
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    You don't want to use a do while loop in this scenario.

    Do While loops are meant to perform an iteration then determine if another iteration should occur. In your situation, you are trying to perform output of a list item using mysql data, but you have yet to retrieve the mysql data. The retrieval happens after your first iteration, so your first list item will always throw a warning/error.

    You want a while loop, as it checks the condition first, if it is true/returns data, then it executes the creating of a list item.
    PHP Code:
    <?php 
    while ($row mysql_fetch_assoc($dollcollection)) {
    echo 
    "<li><a href=\"profiles.php?id="$row['id']."\">";
    echo 
    "<img src=\"dolls/"$row['thumb']."\"  alt=".$row_dollcollection['dollsName'].">";
    echo 
    "</a></li>";

    ?>

  5. #5
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    ohhh.
    I was always wondering about the difference there.
    Thanks
    "Oh, and Jenkins--apparently your mother died this morning."

  6. #6
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    wjhen I run that code, I get this warning...
    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\wamp\www\nikelantiquedolls\wordpress\wp-content\plugins\exec-php\includes\runtime.php(42) : eval()’d code on line 5

    The table does have 1 record in it
    "Oh, and Jenkins--apparently your mother died this morning."

  7. #7
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    opps, forgot to set the query
    "Oh, and Jenkins--apparently your mother died this morning."


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
  •