Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

page numbering for multiple results

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

page numbering for multiple results

Postby justin » Mon Dec 09, 2002 8:48 pm

hello All,
I need a page numbering system for PHP, I have some code that displays my db results and it works fine, All the tutorials I have found are like 3 pages and super advanced and i can't make heads or tails of them, ( 1 have one for ASP and its 10 lines of code) This is my code, if someone can help me modify it to add page numbering for all results over 5 ( or a EASY tutorial ) I would be very grateful ( it doesn't have to be fancy)

$sql = "SELECT * FROM $table_name WHERE catID = '$_REQUEST[id]' AND active = '1' ORDER BY busName ";

$result = @mysql_query($sql, $connection) or die("Error3 - ".mysql_error());


while($row = mysql_fetch_array($result)) {

$busID = $row['busID'];
$catID = $row['catID'];
$busName = $row['busName'];
$busEmail = $row['busEmail'];
$busLogo = $row['busLogo'];
$busPhone = $row['busPhone'];
$busUrl = $row['busUrl'];

$contact_list .= "<tr><td width='150' align='center' rowspan='2'>";
if($busLogo != "") { $contact_list .= "<img src='logo/$busLogo'>";}
$contact_list .= "</td>";
$contact_list .= "<td colspan='2' valign='top'><b>$busName</b></td></tr><tr>";
$contact_list .= "<td valign='top'><b>Email: </b><a href='mailto:$busEmail' class='buttons'>$busEmail</a><br><b>Tel: </b> $busPhone<br></td><td valign='top'>";
if($busUrl != "") { $contact_list .= "<b>Website : </b><a href='http://www.$busUrl' class='buttons' target='blank'>$busUrl</a> <br>";}
$contact_list .= "<a href='businessDetails.php?id=$busID' class='buttons'>More Details.....</a></td></tr>";
$contact_list .= "<tr><td colspan='3'><hr width='75%' color='#cccccc'></td></tr>";
} // end while
justin
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sun Oct 13, 2002 8:30 pm
Location: toronto

Postby Oleg Butuzov » Tue Dec 10, 2002 4:04 am

This is exemple that i wrote few mothes ago, so you can change it =)

<?
include("config.php");

if (!isset($pagenum)) { $pagenum="1";}
$startpage=$pagenum*$step-$step;

$num_query=mysql_query("SELECT * FROM `uins`");

$query=mysql_query("SELECT * FROM `uins` ORDER BY `uin` LIMIT $startpage, $step");

if (mysql_num_rows($num_query) > $step) {
echo "<font class=main><b>PAGE #:<b> ";
$num=ceil(mysql_num_rows($num_query)/$step);

for($i=1; $i <= $num; $i++ )
{
echo " <a href=$PHP_SELF?pagenum=$i>$i</a> ";
}

while ($data=mysql_query($query))
{
echo "data[results]";
}



?>
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby justin » Tue Dec 10, 2002 7:49 pm

Ok, I got got going mostly, but it is a bit buggy, It is set for 2 returns now, but if their are 2 returns exactly, it will display a button for page 2 which is blank. one more thing, I can't successfully display the word "page" before it, when I try it will say
page 1 page 2 page 3
i need it to say page 1 2 3
now it just says
1 2 3


$db = @mysql_select_db($db_name, $connection) or die("Error2 - ".mysql_error());


if(!$page_num || $page_num == "")
{
$page_num = 1;
}

$min = ($page_num - 1) * 2;
$max = ($page_num * 2) - 1;
$addquery = " LIMIT $min, 2";

$current_page = $page_num;

$sql = "SELECT * FROM $table_name WHERE catID = '$_REQUEST[id]' AND active = '1' ORDER BY busName $addquery";
$sql3 = "SELECT * FROM $table_name WHERE catID = '$_REQUEST[id]' AND active = '1' ";

$result = @mysql_query($sql, $connection) or die("Error 2 - PLEASE TRY LATER".mysql_error());

$result3 = @mysql_query($sql3, $connection)
or die("Error3 - ".mysql_error());

$total_items = @mysql_num_rows($result3);
$page_num = ($total_items / 2) + 1;

while($row = mysql_fetch_array($result)) {

$busID = $row['busID'];
$catID = $row['catID'];
$busName = $row['busName'];
$busEmail = $row['busEmail'];
$busLogo = $row['busLogo'];
$busPhone = $row['busPhone'];
$busUrl = $row['busUrl'];

$contact_list .= "<tr><td width='150' align='center' rowspan='2'>";
if($busLogo != "") { $contact_list .= "<img src='logo/$busLogo'>";}
$contact_list .= "</td>";
$contact_list .= "<td colspan='2' valign='top'><b>$busName</b></td></tr><tr>";
$contact_list .= "<td valign='top'><b>Email: </b><a href='mailto:$busEmail' class='buttons'>$busEmail</a><br><b>Tel: </b> $busPhone<br></td><td valign='top'>";
if($busUrl != "") { $contact_list .= "<b>Website : </b><a href='http://www.$busUrl' class='buttons' target='blank'>$busUrl</a> <br>";}
$contact_list .= "<a href='businessDetails.php?id=$busID' class='buttons'>More Details.....</a></td></tr>";
$contact_list .= "<tr><td colspan='3'><hr width='75%' color='#cccccc'></td></tr>";
} // end while

?>
<?
for($i=1;$i<=$page_num;$i++)
{
if($i != $current_page)
echo "<a href=\"showCategory.php?id=$_REQUEST[id]&page_num=$i\">$i</a> ";
else
echo "";
}

?>
</td></tr>

<? echo "$contact_list" ?>
</table>
justin
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sun Oct 13, 2002 8:30 pm
Location: toronto

Postby Oleg Butuzov » Wed Dec 11, 2002 2:18 am

my code already do this.
Code: Select all
if (mysql_num_rows($num_query) > $step) {
echo "<font class=main><b>PAGE #:<b> ";
$num=ceil(mysql_num_rows($num_query)/$step);

for($i=1; $i <= $num; $i++ )
{
echo " <a href=$PHP_SELF?pagenum=$i>$i</a> ";
}
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron