Jump to content

Recommended Posts

I've been trying to get my search script(www.ericschuppe.com/searchtest.php) to paginate the results of this search searching all the results displayed in the checkout database

 

here is the code( nothing displays when tested : viewed at www.ericschuppe.com/searchtest2.php)

 

<link href="styles.css" rel="stylesheet" type="text/css">
<form action="searchtest2.php" method="post">
Search - <input type="text" name="search" value="<?php if($_POST['search']) echo $_POST['search']; ?>" /><br />
<input type="submit" name="searchbtn" value="Search" />
</form>
<?php


include ('dbc.php'); // Connect to the data base.
if($_POST['searchbtn']) {
        echo '<br /><br />';
        if(!get_magic_quotes_gpc()) {
            $search = addslashes($_POST['search']);
        }else{
            $search = $_POST['search'];
        }
        $query = "SELECT full_name,user_idnum,DATE_FORMAT(`date`, '%m/%d/%Y %I:%i %p'),book,returned, MATCH (full_name) AGAINST ('".$search."' IN BOOLEAN MODE) AS user_idnum FROM `checkout` WHERE MATCH (user_idnum) AGAINST ('".$search."' IN BOOLEAN MODE) ORDER BY `full_name` DESC";
        $result = mysql_query($query);
        $query = "SELECT full_name,user_idnum,DATE_FORMAT(`date`, '%m/%d/%Y %I:%i %p'),book,returned, MATCH (full_name) AGAINST ('".$search."' IN BOOLEAN MODE) AS user_idnum FROM `checkout` WHERE MATCH (user_idnum) AGAINST ('".$search."' IN BOOLEAN MODE) ORDER BY `full_name` DESC";
        $num = mysql_num_rows($query);
        
    }




$max = 10; //amount of articles per page. change to what to want

$p = $_GET['p'];

if(empty($p))

{

$p = 1;

}

$limits = ($p - 1) * $max;

//view the news article!

if(isset($_GET['act']) && $_GET['act'] == "view")

{

$id = $_GET['id'];

$sql = mysql_query("SELECT * FROM checkout WHERE id = '$id'");

while($r = mysql_fetch_array($sql))

{

$full_name = $r['full_name'];

$user_idnum = $r['user_idnum'];

$date = $r['date'];

$book = $r['book'];

$returned = $r['returned'];

echo "<div><p>$full_name</p><p>$user_idnum</p><p>$date</p><p>$book</p><p>$returned</p></div>";

}



}else{



//view all the news articles in rows

$sql = $result;

//the total rows in the table

$totalres = ($num,0);

//the total number of pages (calculated result), math stuff...

$totalpages = ceil($totalres / $max);

//the table

echo '<table align="center" cellspacing="2" cellpadding="2"><tr><td align="left"><b>Name</b></td><td align="center"><b>ID</b></td><td align="center"><b>Date</b></td><td align="center"><b>Book</b></td><td align="center"><b>Returned</b></td></tr><tr>';

   while ($r = mysql_fetch_array($sql, MYSQL_NUM)) {
         echo "<tr><td align=\"left\">" .
         stripslashes($r[0]) . "</td>
         <td align=\"left\">$r[1]</td>
         <td align=\"left\">$r[2]</td>
         <td align=\"left\">$r[3]</td>
         <td align=\"left\">$r[4]</td><tr>\n";

  }

}

//close up the table

echo "</tr></table>";

echo( "<div style='text-align: center;'>" );

for($i = 1; $i <= $totalpages; $i++){

//this is the pagination link

$counter = "<a href='searchtest2.php?p=$i'>$i</a>";
echo "<span class=\"csstables\">$counter</span>";

}

echo( "</div>" );


?>

Thank you again.

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

The problem is probably $num = mysql_num_rows($query); I didn't bother reading past that. $query isn't holding any mysql result set, it's just holding the query information that is being sent to the database using mysql_query(). The result set from that query is being stored into $result.

 

Replace:

$query = "SELECT full_name,user_idnum,DATE_FORMAT(`date`, '%m/%d/%Y %I:%i %p'),book,returned, MATCH (full_name) AGAINST ('".$search."' IN BOOLEAN MODE) AS user_idnum FROM `checkout` WHERE MATCH (user_idnum) AGAINST ('".$search."' IN BOOLEAN MODE) ORDER BY `full_name` DESC";
$result = mysql_query($query);
$query = "SELECT full_name,user_idnum,DATE_FORMAT(`date`, '%m/%d/%Y %I:%i %p'),book,returned, MATCH (full_name) AGAINST ('".$search."' IN BOOLEAN MODE) AS user_idnum FROM `checkout` WHERE MATCH (user_idnum) AGAINST ('".$search."' IN BOOLEAN MODE) ORDER BY `full_name` DESC";
$num = mysql_num_rows($query);

 

With:

$query = "SELECT full_name,user_idnum,DATE_FORMAT(`date`, '%m/%d/%Y %I:%i %p'),book,returned, MATCH (full_name) AGAINST ('".$search."' IN BOOLEAN MODE) AS user_idnum FROM `checkout` WHERE MATCH (user_idnum) AGAINST ('".$search."' IN BOOLEAN MODE) ORDER BY `full_name` DESC";
$result = mysql_query($query);
$num = mysql_num_rows($result);

Link to comment
https://forums.phpfreaks.com/topic/152176-search-pagination/#findComment-799386
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.