Jump to content

Recommended Posts

I am trying to use after market pagination and was hoping someone could tell me what I am doing wrong or better yet what to do right.

 

Here is the page I am testing.

http://www.artsandcraftsnetwork.com/show_submits/2ny.php

 

Here is my original script.

It works well but the page will get really long when the database fills up.

 

<?php

include('../show_submits/includes/config.db.php');

if ($link)

{

$sql = "select * from craft_shows WHERE venue_state='NY'";

$result = mysql_query($sql) or die(mysql_error());

echo "<table class='table7' width='100%' cellpadding='5' cellspacing='1'>";

echo "<tr><td> </td><td>Show</td><td>Address</td><td>City</td><td>State</td><td>Date</td><td>Time</td></tr>";

echo "<tr><td colspan='7'><hr></td></tr>";

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

    $id = $row['id'];

echo "<tr><td>";

echo "<form name='show_details' method='post' action='../show_submits/show_detail.php' onsubmit='return submitForms(this);'/>";

echo "<input type='hidden' name='id' value='$id' />";

echo "<input type='submit' name='submit' value='Details' />  ";

echo "</form>";

echo "</td><td>";

echo $row['show_name'];

echo "</td><td>";

echo $row['venue_address'];

echo "</td><td>";

echo $row['venue_city'];

echo "</td><td>";

echo $row['venue_state'];

echo "</td><td>";

if ($row['start_date'] == $row['start_date'])

{

echo $row['start_date'];

}

    else

    {

echo $row['start_date'];

echo "-";

echo $row['end_date'];

}

echo "</td><td>";

echo $row['start_time'];

echo $row['start_ampm'];

echo "-";

echo $row['end_time'];

echo $row['end_ampm'];

    echo "</td></tr>";

    }

    echo "</table>";

}

?>

 

 

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// Here is the first part of the pagination script.

// I have this on the page right under my script just as it is here.

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

<?php

include('../show_submits/includes/config.db.php');

$rpp = 10; // results per page

$adjacents = 4;

 

$page = intval($_GET["page"]);

if(!$page) $page = 1;

 

$reload = $_SERVER['PHP_SELF'];

 

// count total number of appropriate listings:

$tcount = mysql_num_rows($result);

 

// count number of pages:

$tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number

 

$count = 0;

$i = ($page-1)*$rpp;

while(($count<$rpp) && ($i<$tcount)) {

    mysql_data_seek($result,$i);

    $query = mysql_fetch_array($result);

 

    // output each row:

    echo "<p>" . $query['table_field_1'] . ", " . $query['table_field_2'] . "</p>\n";

 

    $i++;

    $count++;

}

?>

 

 

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// And the part that calls the actual pagination script with the formatting.

// Again I have this right under the last part as it appears here with out the comments.

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

<?php

include("pagination1.php");

echo paginate_one($reload, $page, $tpages);

?>

 

 

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// And the script with the formatting.

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

<?php

/*************************************************************************

php easy :: pagination scripts set - Version One

==========================================================================

Author:      php easy code, www.phpeasycode.com

Web Site:    http://www.phpeasycode.com

Contact:    webmaster@phpeasycode.com

*************************************************************************/

function paginate_one($reload, $page, $tpages) {

 

$firstlabel = "First";

$prevlabel  = "Prev";

$nextlabel  = "Next";

$lastlabel  = "Last";

 

$out = "<div class=\"pagin\">\n";

 

// first

if($page>1) {

$out.= "<a href=\"" . $reload . "\">" . $firstlabel . "</a>\n";

}

else {

$out.= "<span>" . $firstlabel . "</span>\n";

}

 

// previous

if($page==1) {

$out.= "<span>" . $prevlabel . "</span>\n";

}

elseif($page==2) {

$out.= "<a href=\"" . $reload . "\">" . $prevlabel . "</a>\n";

}

else {

$out.= "<a href=\"" . $reload . "&page=" . ($page-1) . "\">" . $prevlabel . "</a>\n";

}

 

// current

$out.= "<span class=\"current\">Page " . $page . " of " . $tpages . "</span>\n";

 

// next

if($page<$tpages) {

$out.= "<a href=\"" . $reload . "&page=" .($page+1) . "\">" . $nextlabel . "</a>\n";

}

else {

$out.= "<span>" . $nextlabel . "</span>\n";

}

 

// last

if($page<$tpages) {

$out.= "<a href=\"" . $reload . "&page=" . $tpages . "\">" . $lastlabel . "</a>\n";

}

else {

$out.= "<span>" . $lastlabel . "</span>\n";

}

 

$out.= "</div>";

 

return $out;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/221563-pagination-problem/
Share on other sites

Ok, maybe this is a better way to ask this question.

 

Below is the script that displays the information from my database.

This is just a basic information display and the form button on each line leads to the page for the detailed results, map, weather etc.

Is it possible to use some kind of pagination with this table and form?

I am really new to this and would appropriate any help.

Thanks.

 

<?php

include('../show_submits/includes/config.db.php');

if ($link)

{

$sql = "select * from craft_shows WHERE venue_state='NY'";

$result = mysql_query($sql) or die(mysql_error());

echo "<table class='table7' width='100%' cellpadding='5' cellspacing='1'>";

echo "<tr><td> </td><td>Show</td><td>Address</td><td>City</td><td>State</td><td>Date</td><td>Attendance</td></tr>";

echo "<tr><td colspan='7'><hr></td></tr>";

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

    $id = $row['id'];

echo "<tr><td>";

echo "<form name='show_details' method='post' action='../show_submits/show_detail.php' onsubmit='return submitForms(this);'/>";

echo "<input type='hidden' name='id' value='$id' />";

echo "<input type='submit' name='submit' value='Details' />  ";

echo "</form>";

echo "</td><td>";

echo $row['show_name'];

echo "</td><td>";

echo $row['venue_address'];

echo "</td><td>";

echo $row['venue_city'];

echo "</td><td>";

echo $row['venue_state'];

echo "</td><td>";

echo $row['start_date'];

    echo "</td><td>";

echo $row['num_visitors'];

    echo "</td></tr>";

    }

    echo "</table>";

}

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/221563-pagination-problem/#findComment-1147192
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.