Nightseer Posted September 27, 2006 Share Posted September 27, 2006 OK. I am very new at this, and need the info below to display as a table.......This is the original:$loop = mysql_query("SELECT * FROM dogs WHERE ownerid='$mid'")or die ('cannot select this members dogs');$count = mysql_num_rows($loop);while ($row = mysql_fetch_array($loop)){$dogid = $row['dogid'];$name = getName($dogid);$breed = getBreed($row['breed']);$age = getAge($dogid);$groom = ($row['groomed']);echo "<tr> <td align=\"left\" valign=\"top\" width=\"25%\"><a href=dog.php?dogid=$dogid>$name</a>, $breed age $age <br>Grooming $groom%" . "</td>";}//end whileand I tried this, which workedfor the first 4, but kept repeating the last command:$loop = mysql_query("SELECT * FROM dogs WHERE ownerid='$mid'")or die ('cannot select this members dogs');$count = mysql_num_rows($loop);while ($row = mysql_fetch_array($loop)){$dogid = $row['dogid'];$name = getName($dogid);$breed = getBreed($row['breed']);$age = getAge($dogid);$groom = ($row['groomed']);echo "<tr> <td align=\"left\" valign=\"top\" width=\"25%\"><a href=dog.php?dogid=$dogid>$name</a>, $breed age $age <br>Grooming $groom%" . "</td>";while ($row = mysql_fetch_array($loop)){$dogid = $row['dogid'];$name = getName($dogid);$breed = getBreed($row['breed']);$age = getAge($dogid);$groom = ($row['groomed']);echo " <td align=\"left\" valign=\"top\" width=\"25%\"><a href=dog.php?dogid=$dogid>$name</a>, $breed age $age <br>Grooming $groom%" . "</td>";while ($row = mysql_fetch_array($loop)){$dogid = $row['dogid'];$name = getName($dogid);$breed = getBreed($row['breed']);$age = getAge($dogid);$groom = ($row['groomed']);echo " <td align=\"left\" valign=\"top\" width=\"25%\"><a href=dog.php?dogid=$dogid>$name</a>, $breed age $age <br>Grooming $groom%" . "</td>";while ($row = mysql_fetch_array($loop)){$dogid = $row['dogid'];$name = getName($dogid);$breed = getBreed($row['breed']);$age = getAge($dogid);$groom = ($row['groomed']);echo " <td align=\"left\" valign=\"top\" width=\"25%\"><a href=dog.php?dogid=$dogid>$name</a>, $breed age $age <br>Grooming $groom%" . "</td><tr>";}}}}//end whileMy question is how do I make it go back to the top? I know it's possible, but after searching for 2 days, I'm stumped.......and I know it's probably something really simple that I've missed Quote Link to comment Share on other sites More sharing options...
sanfly Posted September 27, 2006 Share Posted September 27, 2006 Sorry, im a little confused here. Are you trying to display 4 results per row? Quote Link to comment Share on other sites More sharing options...
sanfly Posted September 27, 2006 Share Posted September 27, 2006 If so, try this:[code=php:0]<?php$loop = mysql_query("SELECT * FROM dogs WHERE ownerid='$mid'") or die ('cannot select this members dogs');$count = mysql_num_rows($loop); $i = 1; $cols = 4; while ($row = mysql_fetch_array($loop)){ $dogid = $row['dogid']; $name = getName($dogid); $breed = getBreed($row['breed']); $age = getAge($dogid); $groom = ($row['groomed']); if($i == 1){ echo "<tr>"; }echo "<td align=\"left\" valign=\"top\" width=\"25%\"> <a href=dog.php?dogid=$dogid>$name[/url], $breed age $age Grooming $groom%" . " </td>"; if($i == $cols){ echo "</tr>"; $i = 1; } else{ $i++; } }//end while?>[/code] Quote Link to comment Share on other sites More sharing options...
tomfmason Posted September 27, 2006 Share Posted September 27, 2006 ^ that would work but here is one with pagination.Ok first when posting code the dosn't have the <?php ?> tags rap them in these [nobbc][php]yourcodehere[/php][/nobbc] and for code with the tags use these [nobbc][code][/code][/nobbc].Now as far as the loop gos All you have to do is this.[code=php:0]while ($row = mysql_fetch_array($loop)) { echo '<td align="left" valign="top" width="25%"><a href="dog.php?dogid=' . $row['dogid'] . '>'. getname($rw['dogid'] . '</a>, ' . getBreed($row['dogid']) . ' age ' . getage($rw['dogid']) . ' Grooming ' groomed($rw['dogid']) . '%</td><tr>';[/code]Now if you are want to display a certain number of result perpage(pagination) then you could adjust the sql query accordingly.[code=php:0]$page = $_GET['page'];$max = 4;//this is assumeing you want four results perpage.$sql = mysql_query("SELECT * FROM `dogs` WHERE `ownerid` = '$whatever'");$total = mysql_num_rows($sql);if (!$page) { $page = 1;}$limit = $page * $max - ($max);$loop = mysql_query("SELECT * FROM dogs WHERE ownerid='$mid' LIMIT '$limit', '$max'")or die ('cannot select this members dogs');//place the while statement that I posted here.[/code]Now to allow the user to go to the next page of results you would do this.[code=php:0]//somwhere at the bottom of the page.//you can rap this in a table.if ($page !== 1) { $prev--; echo '<a href="yourpage.php?page=' . $prev . '">Prev</a>';}else{ echo "Prev";}$pages = $total / $max;for ($i = 1; $i <= $total; $i++;) { if ($i = $page) { echo $i; }else{ echo '<a href="thispage.php?page=' . $i . '>' . $i . '</a>'; }}if (($total % $max) != 0) { if(($totalrows % $limit) != 0){ if($i == $page){ echo $i.; }else{ echo '<a href="thispage.php?page=' . $i . '"> ' . $i . '</a>'; } } if(($total - ($max * $page)) > 0){ $next = $page++; echo '<a href="thispage.php?page=' . $next . '">Next</a>'; }else{ echo "Next"; }[/code]So this way you would link to this page like this yourpage.php?page=thepage or just yourpageNow if you want to also link the userid just do this.yourpage.php?userid=thereuserid&page=thepagejust add this to your query.$userid = mysql_real_escape_string(trim(strip_tags($_GET['userid'])));Then you add the $userid to the WHERE clause in the sql query.Hope this helps,Tom Quote Link to comment Share on other sites More sharing options...
Nightseer Posted September 27, 2006 Author Share Posted September 27, 2006 Thanks sooo much:) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.