Jump to content


Photo

Help! I am stuck...


  • Please log in to reply
3 replies to this topic

#1 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 06 June 2006 - 04:29 PM

I have a search program that includes pagination, I have not been able to figure out where I need to put my search variables into the href's for my results, so now, I get the first page but nothing after that. This is the line that I am pretty sure needs to be included amongst the hrefs:
&metode=$metode&search=$search&metode2=$metode2&search2=$search2&metode3=$metode3&search3=$search3


If anyone could explain to me where I need to put that or if I need to do something completely different to pass my search results through the rest of the pages that would be awesome, thanks!


php:
<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="60"><b>DT_STRING</b></td>
<td width="100"><b>ACCOUNT</b></td>
<td width="30"><b>ACCOUNT_TYPE</b></td>
<td width="150"><b>CLIENT_ID</b></td>
<td width="150"><b>USER_ID</b></td>
</tr>
<tr>
<td>



<?php





// Database and Sever Values
$user_db = 'root'; // Server Username    
$pass_db = 'rootroot'; // Server Password
$host_db = 'mysql'; //Server (e.g. localhost)
$db = 'AUDITMED'; // Database Name
//

// Connect Information - No need to edit
@mysql_connect ($host_db, $user_db, $pass_db);
@mysql_select_db ($db);
//

$metode = $_REQUEST['metode'];
$search = $_REQUEST['search'];
$metode2 = $_REQUEST['metode2'];
$search2 = $_REQUEST['search2'];
$metode3 = $_REQUEST['metode3'];
$search3 = $_REQUEST['search3'];



$table = 'AUDIT'; // The name of your table in the database
$limit = '100'; // How many results should be shown at a time
$scroll = '1'; // Do you want the scroll function to be on (1 = YES, 2 = NO)
$scrollnumber = '10'; // How many elements to the record bar are shown at a time when the scroll function is on

// Get the total number of rows in a database
$query1 = mysql_query ("SELECT * FROM $table WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' AND $metode3 LIKE '%$search3%' ORDER by CLIENT_ID");

$numrows = mysql_num_rows ($query1);
//

if (!isset ($_GET['show'])) {

    $display = 1;
    
} else {

    $display = $_GET['show'];
    
}

// Return results from START to LIMIT
$start = (($display * $limit) - $limit);

$query2 = mysql_query ("SELECT * FROM $table WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' AND $metode3 LIKE '%$search3%' ORDER by CLIENT_ID LIMIT $start,$limit"); // Add ORDER BY field ASC or DESC to order the results

while ($row = mysql_fetch_array ($query2)) { 
 $variable1=$row["DT_STRING"];
        $variable2=$row["ACCOUNT"];
        $variable3=$row["ACCOUNT_TYPE"];
        $variable4=$row["CLIENT_ID"];
        $variable5=$row["USER_ID"];
        //table layout for results

        echo ("<tr>");
        echo ("<td>$variable1</td>");
        echo ("<td>$variable2</td>");
        echo ("<td>$variable3</td>");
        echo ("<td>$variable4</td>");
        echo ("<td>$variable5</td>");
        echo ("</tr>");
         }; 
         

//

$paging = ceil ($numrows / $limit);

// Display the navigation
if ($display > 1) {
    
    $previous = $display - 1;
    
?>

<a href="<?= $_SERVER['PHP_SELF']; ?>?show=1"><< First</a> | 

<a href="<?= $_SERVER['PHP_SELF'] ?>?show=<?= $previous; ?>">< Previous</a> |

<?php

}

if ($numrows != $limit) {
    
    if ($scroll == 1) {
    
        if ($paging > $scrollnumber) {
            
            $first = $display;
            
            $last = ($scrollnumber - 1) + $display;
            
        }
    
    } else {
    
        $first = 1;
            
        $last = $paging;
            
    }
    
    if ($last > $paging ) {
            
        $first = $paging - ($scrollnumber - 1);
            
        $last = $paging;
            
    }
    
    for ($i = $first;$i <= $last;$i++){
        
        if ($display == $i) {
            
?>

[ <b><?= $i ?></b> ]

<?php
            
        } else {
            
?>

[ <a href="<?= $_SERVER['PHP_SELF']; ?>?show=<?= $i; ?>"><?= $i; ?></a> ] 
            
<?php

        }
    }
}
if ($display < $paging) {
    $next = $display + 1;
?>

| <a href="<?= $_SERVER['PHP_SELF']; ?>?show=<?= $next; ?>">Next ></a> | 

<a href="<?= $_SERVER['PHP_SELF']; ?>?show=<?= $paging; ?>">Last >></a>

<?php

}
//
?>
</table>
</center>

Thanks again!
EDIT BY OBER: PLEASE USE BB CODE TAGS!

#2 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 06 June 2006 - 06:58 PM

If you're using PHP 5 then [a href=\"http://php.net/http_build_query\" target=\"_blank\"]http_build_query()[/a] should be useful. I assume you want to add the values to these lines
| <a href="<?= $_SERVER['PHP_SELF']; ?>?show=<?= $next; ?>">Next ></a> |

<a href="<?= $_SERVER['PHP_SELF']; ?>?show=<?= $paging; ?>">Last >></a>
eg:
<a href="<?= $_SERVER['PHP_SELF']; ?>?show=<?="$next&metode=$metode&search=$search&metode2=$metode2&search2=$search2&metode3=$metode3&search3=$search3"; ?>">Next ></a>
I did a copy and paste, so you may need to work out any problems yourself. You'll also want to check whether or not any data was sent using a function such as [a href=\"http://www.php.net/isset\" target=\"_blank\"]isset()[/a]. Where, if there was no data sent you can either remove the argument from the query string or have it be equal to ''.

$query1 = mysql_query ("SELECT * FROM $table WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' AND $metode3 LIKE '%$search3%' ORDER by CLIENT_ID");

Instead of running the above query twice (once with and without the LIMIT clause). You can use [a href=\"http://dev.mysql.com/doc/refman/4.1/en/information-functions.html\" target=\"_blank\"]FOUND_ROWS()[/a] (Do a "find"/"search" with your browser), to determine what the number of rows returned would have been without a LIMIT.

You should also take a look at the function [a href=\"http://www.php.net/mysql_real_escape_string\" target=\"_blank\"]mysql_real_escape_string[/a]. To get a basic understanding of securing your PHP scripts consider reading this [a href=\"http://phpsec.org/projects/guide/\" target=\"_blank\"]security guide[/a]. Read the entire guide,but I'd direct you first to the SQL INJECTION section.

#3 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 07 June 2006 - 06:07 PM

Well, I did try all of those things, but I still can't get it to send the query through the href. I know that it sends the query through originally, but not through the page number variables or the first, last, next, previous links. Any other suggestions??? Anybody?

Thanks again!

#4 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 07 June 2006 - 07:52 PM

You should post the code you're currently working with, but before doing so you should also [a href=\"http://php.net/urlencode\" target=\"_blank\"]urlencode[/a] the text before adding it to the link.
eg:
<a href="<?= $_SERVER['PHP_SELF']; ?>?show=<?="$next&metode=".urlencode($metode)."&search=".urlencode($search)."&metode2=".urlencode($metode2) etc etc"; ?>">Next ></a>
When you're finished, post the code you're currently using and the HTML output being generated when you do a search. I'm assuming everything else in your code works except for the next and prev links btw. I don't plan on checking the rest of the code unless something jumps out at me, or you point out additional problems.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users