mike239 Posted February 3, 2009 Share Posted February 3, 2009 Hi All I am having trouble with the php script for my database results. When I perform a search of a particular item my results page shows the same two items even if I leave the search box blank. Any help will be greatly appreciated. Thanks mike239 Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/ Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 Code? Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753224 Share on other sites More sharing options...
mike239 Posted February 3, 2009 Author Share Posted February 3, 2009 <?php require_once('Connections/circle.php'); ?> <?php if (!function_exists("PostSQLValueString")) { function PostSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = post_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_ToolResults = 2; $pageNum_ToolResults = 0; if (isset($_POST['pageNum_ToolResults'])) { $pageNum_ToolResults = $_POST['pageNum_ToolResults']; } $startRow_ToolResults = $pageNum_ToolResults * $maxRows_ToolResults; mysql_select_db($database_circle, $circle); $query_ToolResults = "SELECT * FROM tooltable"; $query_limit_ToolResults = sprintf("%s LIMIT %d, %d", $query_ToolResults, $startRow_ToolResults, $maxRows_ToolResults); $ToolResults = mysql_query($query_limit_ToolResults, $circle) or die(mysql_error()); $row_ToolResults = mysql_fetch_assoc($ToolResults); if (isset($_POST['totalRows_ToolResults'])) { $totalRows_ToolResults = $_POST['totalRows_ToolResults']; } else { $all_ToolResults = mysql_query($query_ToolResults); $totalRows_ToolResults = mysql_num_rows($all_ToolResults); } $totalPages_ToolResults = ceil($totalRows_ToolResults/$maxRows_ToolResults)-1; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Circle Tool Results</title> <style type="text/css"> <!-- body { background-color: #00CCCC; } body,td,th { color: #000000; } a:link { color: #000000; text-decoration: none; } a:visited { text-decoration: none; color: #000000; } a:hover { text-decoration: none; } a:active { text-decoration: none; } --> </style></head> <body> <table border="1"> <tr> <td>ToolNumber</td> <td>ToolLocation</td> <td>Quantity</td> <td>Owner</td> <td>Notes</td> </tr> <?php do { ?> <tr> <td><?php echo $row_ToolResults['ToolNumber']; ?></td> <td><?php echo $row_ToolResults['ToolLocation']; ?></td> <td><?php echo $row_ToolResults['Quantity']; ?></td> <td><?php echo $row_ToolResults['Owner']; ?></td> <td><?php echo $row_ToolResults['Notes']; ?></td> </tr> <?php } while ($row_ToolResults = mysql_fetch_assoc($ToolResults)); ?> </table> <p> <a href="/search.php"> <label> </label> </a></p> <table width="123" border="1"> <tr> <td width="127"><a href="/search.php">SEARCH MORE</a> </td> </tr> </table> </body> </html> <?php mysql_free_result($ToolResults); ?> Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753227 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 That doesn't have any search functionality at all also use [ code] [ /code] tags Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753229 Share on other sites More sharing options...
mike239 Posted February 3, 2009 Author Share Posted February 3, 2009 Thanks for the fast replay Gevans--I hate to admit I am very new to php and need ask what are and how to use them in the script Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753238 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 oh, its for posting it goes in here your code would look like this <?php require_once('Connections/circle.php'); ?> <?php if (!function_exists("PostSQLValueString")) { function PostSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = post_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_ToolResults = 2; $pageNum_ToolResults = 0; if (isset($_POST['pageNum_ToolResults'])) { $pageNum_ToolResults = $_POST['pageNum_ToolResults']; } $startRow_ToolResults = $pageNum_ToolResults * $maxRows_ToolResults; mysql_select_db($database_circle, $circle); $query_ToolResults = "SELECT * FROM tooltable"; $query_limit_ToolResults = sprintf("%s LIMIT %d, %d", $query_ToolResults, $startRow_ToolResults, $maxRows_ToolResults); $ToolResults = mysql_query($query_limit_ToolResults, $circle) or die(mysql_error()); $row_ToolResults = mysql_fetch_assoc($ToolResults); if (isset($_POST['totalRows_ToolResults'])) { $totalRows_ToolResults = $_POST['totalRows_ToolResults']; } else { $all_ToolResults = mysql_query($query_ToolResults); $totalRows_ToolResults = mysql_num_rows($all_ToolResults); } $totalPages_ToolResults = ceil($totalRows_ToolResults/$maxRows_ToolResults)-1; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Circle Tool Results</title> <style type="text/css"> <!-- body { background-color: #00CCCC; } body,td,th { color: #000000; } a:link { color: #000000; text-decoration: none; } a:visited { text-decoration: none; color: #000000; } a:hover { text-decoration: none; } a:active { text-decoration: none; } --> </style></head> <body> <table border="1"> <tr> <td>ToolNumber</td> <td>ToolLocation</td> <td>Quantity</td> <td>Owner</td> <td>Notes</td> </tr> <?php do { ?> <tr> <td><?php echo $row_ToolResults['ToolNumber']; ?></td> <td><?php echo $row_ToolResults['ToolLocation']; ?></td> <td><?php echo $row_ToolResults['Quantity']; ?></td> <td><?php echo $row_ToolResults['Owner']; ?></td> <td><?php echo $row_ToolResults['Notes']; ?></td> </tr> <?php } while ($row_ToolResults = mysql_fetch_assoc($ToolResults)); ?> </table> <p> <a href="/search.php"> <label> </label> </a></p> <table width="123" border="1"> <tr> <td width="127"><a href="/search.php">SEARCH MORE</a> </td> </tr> </table> </body> </html> <?php mysql_free_result($ToolResults); ?> but its still the wrong code Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753241 Share on other sites More sharing options...
mike239 Posted February 3, 2009 Author Share Posted February 3, 2009 What type of code would you suggest? Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753245 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 What type of code would you suggest? It's not for me to suggest, you need to show the code you're having a problem with. You say you have a problem when you search, that code isn't using anything that looks like a search. Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753249 Share on other sites More sharing options...
mike239 Posted February 3, 2009 Author Share Posted February 3, 2009 Here is my search code--I thought since my results were displayed wrong it would have been in the result script-my bad still learning <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Tool Search</title> <style type="text/css"> <!-- .style1 { font-size: 36px; font-weight: bold; font-style: italic; } body { background-color: #00CCFF; } body,td,th { color: #FFFFFF; } --> </style> </head> <body> <div align="center" class="style1">CIRCLE TOOL SEARCH</div> <form action="/results.php" method="get" name="form1" target="_parent" id="form1"> <label> <input type="text" name="textfield" /> </label> TYPE THE DESIRED TOOL NUMBER <label> <input type="submit" name="Submit" value="Submit" /> </label> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753254 Share on other sites More sharing options...
Philip Posted February 3, 2009 Share Posted February 3, 2009 Place you're code in here when posting That'll format it to: Place you're code in here It's just easier for us to read your code with the syntax highlighting, and we don't have to scroll down the page. As stated before, are you sure this is the search form code - not the actual form, but the code once you process it? In the code above, all I saw was $query_ToolResults = "SELECT * FROM tooltable"; with no WHERE clause Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753260 Share on other sites More sharing options...
mike239 Posted February 3, 2009 Author Share Posted February 3, 2009 This is the one the previous IT guy left on the server before he dumped the databse and quit. Maybe he deleted some of the code also ??? Link to comment https://forums.phpfreaks.com/topic/143557-php-mysql-result-script/#findComment-753285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.