Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Problem Switching SQL Statements
Old 09-09-2006, 09:09 PM Problem Switching SQL Statements
Junior Talker

Posts: 3
Name: Renee
Trades: 0
Hello,

I'm trying to build a search results page. I would appreciate it if someone would kindly give me a tip on what might be wrong with this code.

I want this conditional statement to show items on a page based on whether a particular form variable or URL variable exists. If neither variable is set, I want it to show everything.

Problems: It seems as though the existance of the form variable is being ignored as my results page defaults to showing everything when I pass the form variable. On the other hand, when I pass the URL variable, my results page returns no records at all.

Code:

$currentPage = $_SERVER["PHP_SELF"];
$maxRows_All_Items = 10;
$pageNum_All_Items = 0;
if (isset($_GET['pageNum_All_Items'])) {
$pageNum_All_Items = $_GET['pageNum_All_Items'];
}
$startRow_All_Items = $pageNum_All_Items * $maxRows_All_Items;
mysql_select_db($database_Sale, $Sale);
if(isset($_POST['KeyWords'])){
$query_All_Items = sprintf("SELECT * FROM Items WHERE Listing_Title LIKE '%%%s%%' or Description LIKE '%%%s%%' ORDER BY Price ASC", $colname_All_Items,$colname_All_Items);}
else if(isset($_GET['Category'])){
$query_All_Items = sprintf("SELECT * FROM Items WHERE Category = '%s' ORDER BY Price ASC", $colname_All_Items);}
else{
$query_All_Items = "SELECT * FROM Items ORDER BY Price ASC";}
$query_limit_All_Items = sprintf("%s LIMIT %d, %d", $query_All_Items, $startRow_All_Items, $maxRows_All_Items);
$All_Items = mysql_query($query_limit_All_Items, $Sale) or die(mysql_error());
$row_All_Items = mysql_fetch_assoc($All_Items);
if (isset($_GET['totalRows_All_Items'])) {
$totalRows_All_Items = $_GET['totalRows_All_Items'];
} else {
$all_All_Items = mysql_query($query_All_Items);
$totalRows_All_Items = mysql_num_rows($all_All_Items);
}
$totalPages_All_Items = ceil($totalRows_All_Items/$maxRows_All_Items)-1;
$queryString_All_Items = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_All_Items") == false &&
stristr($param, "totalRows_All_Items") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_All_Items = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_All_Items = sprintf("&totalRows_All_Items=%d%s", $totalRows_All_Items, $queryString_All_Items);

Any help would be greatly appreciated.
tekgirl6 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-10-2006, 11:51 AM Re: Problem Switching SQL Statements
Extreme Talker

Posts: 246
Trades: 3
My troubleshooting method would be as follows:

Echo the sql statement along with the results. When you don't see the results you expect, analyze the sql statement, and see what's wrong with it. When you find what's wrong with it, either modify the sql, or the logic. Maybe you're assigning the sql statement in a section of code that you didn't expect the "if" clause to be true. Or vice versa.

I noticed that you're using both $_GET and $_POST variables... is that intentional?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
CouponGuy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem Switching SQL Statements
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43808 seconds with 12 queries