Web Analytics Made Easy -
StatCounter Search Pagination - CodingForum

Announcement

Collapse
No announcement yet.

Search Pagination

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Search Pagination

    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)
    PHP Code:
    <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);
            
    $num mysql_num_rows($result);
        }




    $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($sqlMYSQL_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.

  • #2
    I just have to say

    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"
    Is that really valid sql code?? (sorry dunno much about mysql)
    PHP Idea Factory

    Comment


    • #3
      That isn't the problem because the actual search function works www.ericschuppe.com/searchtest.php

      Comment


      • #4
        i wasn't sarcastic or something. i just learned something about SQL that i didn't know before
        and about pagination, coincidence is that few days back i wrote a script that deals with it pretty sweet way. it's under "Post snippet" sub forum, near the top few posts
        PHP Idea Factory

        Comment

        Working...
        X