Skip navigation
Currently Being Moderated

Problems displaying results after search

May 14, 2013 6:16 AM

I am new to webdesign so I apologize in advance if the anwer is obvios. As you can probably see I rely a lot on dreamweaver to write the code.

Here is the problem:

I have a mysql database where I would like to search 3 columns (it contains 38 column in total). I have a search page with a form that has a text input field. (See code below)

My database is just in test stage, however the columns will not change

 

Category
Product
Model
Color
Korg Digital Piano
New
PA3X
Black
Kawai Digital Piano
New
CVP509
Rosewood
Etc.








 

<form id="form1" name="form1" method="get" action="Manage_Products_results.php">
  <label for="Search">Search</label>
  <input name="Search" type="text" id="Search" size="100" maxlength="100" />
  <input type="submit" name="Search2" id="Search2" value="Submit" />
</form>

 

 

 

On the results page I have the following code:

 

<?php require_once('../Connections/dBconn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_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_getResults = 10;
$pageNum_getResults = 0;
if (isset($_GET['pageNum_getResults'])) {
  $pageNum_getResults = $_GET['pageNum_getResults'];
}
$startRow_getResults = $pageNum_getResults * $maxRows_getResults;


$Category_getResults = "-1";
if (isset($_GET['Category'])) {
  $Category_getResults = $_GET['Category'];
}
$Model_getResults = "-1";
if (isset($_GET['Model'])) {
  $Model_getResults = $_GET['Model'];
}
$Color_getResults = "-1";
if (isset($_GET['Color'])) {
  $Color_getResults = $_GET['Color'];
}
mysql_select_db($database_dBconn, $dBconn);
$query_getResults = sprintf("SELECT id, %s, Manufacturer, %s, %s, Product FROM products WHERE %s LIKE %s OR %s LIKE %s OR %s LIKE %s", GetSQLValueString($Category_getResults, "text"),GetSQLValueString($Model_getResults, "text"),GetSQLValueString($Color_getResults, "text"),GetSQLValueString($Category_getResults, "text"),GetSQLValueString("%" . $Category_getResults . "%", "text"),GetSQLValueString($Model_getResults, "text"),GetSQLValueString("%" . $Model_getResults . "%", "text"),GetSQLValueString($Color_getResults, "text"),GetSQLValueString("%" . $Color_getResults . "%", "text"));
$query_limit_getResults = sprintf("%s LIMIT %d, %d", $query_getResults, $startRow_getResults, $maxRows_getResults);
$getResults = mysql_query($query_limit_getResults, $dBconn) or die(mysql_error());
$row_getResults = mysql_fetch_assoc($getResults);


if (isset($_GET['totalRows_getResults'])) {
  $totalRows_getResults = $_GET['totalRows_getResults'];
} else {
  $all_getResults = mysql_query($query_getResults);
  $totalRows_getResults = mysql_num_rows($all_getResults);
}
$totalPages_getResults = ceil($totalRows_getResults/$maxRows_getResults)-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=UTF-8" />
<title>Untitled Document</title>
</head>


<body>
<p>Your Search Results</p>


<p> </p>
<table border="1">
  <tr>
    <td>id</td>
    <td>Category</td>
    <td>Manufacturer</td>
    <td>Model</td>
    <td>Color</td>
    <td>Product</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_getResults['id']; ?></td>
      <td><?php echo $row_getResults['Category']; ?></td>
      <td><?php echo $row_getResults['Manufacturer']; ?></td>
      <td><?php echo $row_getResults['Model']; ?></td>
      <td><?php echo $row_getResults['Color']; ?></td>
      <td><?php echo $row_getResults['Product']; ?></td>
    </tr>
    <?php } while ($row_getResults = mysql_fetch_assoc($getResults)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($getResults);
?>

 

I would like input e.g. korg in the search page and  the results page will display all the record with korg either in the category or model column. At the moment there is no result on the result page.

Thanks

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points