Jump to content

All Results Returned


Recommended Posts

Hello again,

 

I created a search query that should only return results that are like the one entered in the "search field" of the search page. However, when ever i enter any value in the search field it returns all records in my table.

 

Here is my SQL statement:

 

<?php

$currentPage = $_SERVER["PHP_SELF"];

 

$maxRows_rs1 = 50;

$pageNum_rs1 = 0;

if (isset($_GET['pageNum_rs1'])) {

$pageNum_rs1 = $_GET['pageNum_rs1'];

}

$startRow_rs1 = $pageNum_rs1 * $maxRows_rs1;

 

$sterm_rs1 = "1";

if (isset($_GET['sterm'])) {

$sterm_rs1 = (get_magic_quotes_gpc()) ? $_GET['sterm'] : addslashes($_GET['sterm']);

}

mysql_select_db($database_msds, $msds);

$query_rs1 = sprintf("SELECT * FROM msds WHERE msds.`ref` LIKE 'stermterm%%' OR msds.description LIKE '%%%s%%' OR msds.manufacturer LIKE '%%%%s%%' ORDER BY msds.`ref`ASC", $sterm_rs1);

$query_limit_rs1 = sprintf("%s LIMIT %d, %d", $query_rs1, $startRow_rs1, $maxRows_rs1);

$rs1 = mysql_query($query_limit_rs1, $msds) or die(mysql_error());

$row_rs1 = mysql_fetch_assoc($rs1);

 

if (isset($_GET['totalRows_rs1'])) {

$totalRows_rs1 = $_GET['totalRows_rs1'];

} else {

$all_rs1 = mysql_query($query_rs1);

$totalRows_rs1 = mysql_num_rows($all_rs1);

}

$totalPages_rs1 = ceil($totalRows_rs1/$maxRows_rs1)-1;

?>

 

Any ideas how to filter down?

 

All the best,

 

-F

Link to comment
https://forums.phpfreaks.com/topic/1975-all-results-returned/
Share on other sites

f (isset($_GET['totalRows_rs1'])) {

$totalRows_rs1 = $_GET['totalRows_rs1'];

} else {

$all_rs1 = mysql_query($query_rs1);

$totalRows_rs1 = mysql_num_rows($all_rs1);

 

Then your error must be in the above. Echo total rows after this snippet to see if it is present.

Link to comment
https://forums.phpfreaks.com/topic/1975-all-results-returned/#findComment-6477
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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