Jump to content

help with limiting amount of records shown


perezf

Recommended Posts

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++;
}

?>

$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 :P 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

}

?>

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

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.