perezf Posted April 26, 2007 Share Posted April 26, 2007 I need help in having a limit on the items shown from mysql so that it will create a next and previous link to go to the dynamically created pages <?php $connection = mysql_connect ("localhost", "username", "password") or die ("I cannot connect to the database"); mysql_select_db ("database", $connection) or die ("Unable to select the database"); $query = "SELECT * FROM items ORDER by name"; $result = mysql_query($query); $num = mysql_numrows($result); mysql_close(); $i = 0; while ($i < $num) { $name = mysql_result($result, $i, "name"); $link = mysql_result($result, $i, "link"); $aboutsite = mysql_result($result, $i, "about"); $picturename = mysql_result($result, $i, "picturename"); ?> <div class="portitem"> <!--title--> <div class="aboutus"> <p class="titlebg"><span class="brown-title"> <?php echo $name; ?></span></p> <!-- end of title --> <div style="margin-top:-15px; "> <a href="http://<?php echo $link; ?>" target="_blank"> <img src="portfolio/<?php echo $picturename; ?>" alt="<?php echo $name; ?>" width="143" height="97" border="0" align="left" style="padding-right:10px;" /></a> <strong class="brown-title"><a href="http://<?php echo $link; ?>" target="_blank" class="brown-title"><?php echo $link ?></a></strong><br /> <?php echo $aboutsite; ?> </div> </div> </div> <?php $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/48724-help-with-limiting-amount-of-records-shown/ Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 $query = "SELECT * FROM items ORDER by name"; to $query = "SELECT * FROM items ORDER by name LIMIT 0,30"; Start at items starting from 0, then show the next 30.. wanna show 30 - 60? Do limit 30, 30 .. starts at the 30, and shows the next 30 after that. If you cant do page integration on your own, ask its pretty simple once you know about LIMIT on your sql statements. <?php $connection = mysql_connect ("localhost", "username", "password") or die ("I cannot connect to the database"); mysql_select_db ("database", $connection) or die ("Unable to select the database"); $query = "SELECT * FROM items ORDER by name LIMIT 0,30"; $result = mysql_query($query); mysql_close(); while ($r = mysql_fetch_array($query)) { $name = $r[name]; $link = $r[link]; $aboutsite = $r[about]; $picturename = $r[picturename]; ?> <div class="portitem"> <!--title--> <div class="aboutus"> <p class="titlebg"><span class="brown-title"> <?php echo $name; ?></span></p> <!-- end of title --> <div style="margin-top:-15px; "> <a href="http://<?php echo $link; ?>" target="_blank"> <img src="portfolio/<?php echo $picturename; ?>" alt="<?php echo $name; ?>" width="143" height="97" border="0" align="left" style="padding-right:10px;" /></a> <strong class="brown-title"><a href="http://<?php echo $link; ?>" target="_blank" class="brown-title"><?php echo $link ?></a></strong><br /> <?php echo $aboutsite; ?> </div> </div> </div> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/48724-help-with-limiting-amount-of-records-shown/#findComment-238789 Share on other sites More sharing options...
perezf Posted April 26, 2007 Author Share Posted April 26, 2007 seems to be getting an error on line 17 Link to comment https://forums.phpfreaks.com/topic/48724-help-with-limiting-amount-of-records-shown/#findComment-238805 Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 oh shit, my bad. There you go. <?php $connection = mysql_connect ("localhost", "username", "password") or die ("I cannot connect to the database"); mysql_select_db ("database", $connection) or die ("Unable to select the database"); $query = "SELECT * FROM items ORDER by name LIMIT 0,30"; $result = mysql_query($query); mysql_close(); while ($r = mysql_fetch_array($result)) { $name = $r[name]; $link = $r[link]; $aboutsite = $r[about]; $picturename = $r[picturename]; ?> <div class="portitem"> <!--title--> <div class="aboutus"> <p class="titlebg"><span class="brown-title"> <?php echo $name; ?></span></p> <!-- end of title --> <div style="margin-top:-15px; "> <a href="http://<?php echo $link; ?>" target="_blank"> <img src="portfolio/<?php echo $picturename; ?>" alt="<?php echo $name; ?>" width="143" height="97" border="0" align="left" style="padding-right:10px;" /></a> <strong class="brown-title"><a href="http://<?php echo $link; ?>" target="_blank" class="brown-title"><?php echo $link ?></a></strong><br /> <?php echo $aboutsite; ?> </div> </div> </div> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/48724-help-with-limiting-amount-of-records-shown/#findComment-238813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.