Jump to content

Archived

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

links1573

PHP and Mysql help

Recommended Posts

I have created a database driven Web Site where users can search the database based on the Items description. Trying to find a way to search the database based on multiple fields; I.E.

Description, Zip Code, Serial number, Name, etc...

Below is a snippet of the PHP code that I have functioning currently. Any help would be greatly appreciated.

[color=red]<?php require_once('../Connections/js.php'); ?>
<?php
if ( !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ) {
  header ('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  exit();
}

$currentPage = $_SERVER["PHP_SELF"];
$editFormAction = $_SERVER['PHP_SELF'];

if ( !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ) {
  header ('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  exit();
}

if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$maxRows_Recordset1 = 20;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$colname_Recordset1 = "Please Enter your Search Criteria";

if (isset($_POST['stolen']) || $_GET['type']=='search') {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['stolen'] : addslashes($_POST['stolen']);
}

mysql_select_db($database_js, $js);
$query_Recordset1 = sprintf("SELECT * FROM items WHERE freeze <> '1' AND tracks LIKE '%%%s%%' ORDER BY tracks ASC", $colname_Recordset1);
sprintf("SELECT * FROM items WHERE freeze <> '1' AND tracks LIKE '%%%s%%' ORDER BY tracks ASC", $colname_Recordset1);
sprintf("SELECT * FROM items WHERE freeze <> '1' AND tracks LIKE '%%%s%%' ORDER BY tracks ASC", $colname_Recordset1);

$Recordset1 = mysql_query($query_Recordset1, $js) or die(mysql_error());

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $js) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false &&
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>[/color]


Thanks in advance,

~Links1573

Share this post


Link to post
Share on other sites
//connect to database for data result useing like and %wildcard

$db=mysql_connect("localhost","xxx","xxx");
mysql_select_db("promotor" , $db);



$query="select * from xxxxx where xxx like '%".$xxx."%'and xxx like '%".$xxx."%'
and xxxx like '%".$xxxx."%'";
$result=mysql_query($query);

Share this post


Link to post
Share on other sites
Thanks for the response, but I tried using wild cards and LIKE, but I get an empty qwery everytime I run it with multiple tables being queried.

Here is a snippet of code from my search qwery within the HTML;

[color=red]<table border="1" align="center">
                    <tr class="style9">
                      <td class="style13">Records Matching Your Search Criteria </td>
                      <td width="62" class="style16"><div align="center" class="style13">Email</div></td>
                      <td class="style13"><div align="center">Agency Name</div></td>
  <td class="style13"><div align="center">Agency Phone number</div></td>
  <td class="style13"><div align="center">Police/Incident
                          Report number</div></td>
  <td class="style13"><div align="center">Reported Stolen</div></td>
                      <td class="style13"><div align="center">Reported Lost</div></td>
                      <td class="style13"><div align="center">Image</div></td>
                    </tr>
                    <?php do { ?>
                    <tr class="style10">
                      <td width="303" class="style26"><?php if ($totalRows_Recordset1 == 0){echo 'No Results Found, Please search again';}else{echo $row_Recordset1['tracks'];} ?></td>
                      <td valign="middle"><div align="center"><a href="mailto:<?php if ($totalRows_Recordset1 == 0){echo 'default@juststolen.net';}else{ echo $row_Recordset1['email'];} ?>?bcc=info@juststolen.net">Notify Owner</a></div></td>
                      <td width="91" class="style26"><?php if ($totalRows_Recordset1 == 0){echo 'No Results Found, Please search again';}else{echo $row_Recordset1['agency'];} ?>
                      &nbsp;</td>
                      <td width="75" class="style26"><div align="center"><span class="style22"><?php if ($totalRows_Recordset1 == 0){echo 'No Results Found, Please search again';}else{echo $row_Recordset1['agency_phone'];} ?>
                      &nbsp;</span></div></td>
                      <td width="89" class="style26"><div align="center"><span class="style22"><?php if ($totalRows_Recordset1 == 0){echo 'No Results Found, Please search again';}else{echo $row_Recordset1['case_num'];} ?>
                      &nbsp;</span></div></td>
                        <td width="89" class="style26"><div align="center"><span class="style22">
                          <?php if (!(strcmp($row_Recordset1['stolenline'],1))) {echo "STOLEN";} ?>
                          </span> </div></td>
  <td width="75" class="style26"><div align="center"><span class="style22">
                          <?php if (!(strcmp($row_Recordset1['lost'],1))) {echo "LOST";} ?>
                          &nbsp; </span> </div></td>
  <td width="75" class="style26"><div align="center"><span class="style22">
                          <?php if ($totalRows_Recordset1 == 0){echo '';}else{
  $email = $row_Recordset1['email'];
  $item = $row_Recordset1['item_number'];  
  $imgquery = "select id_files from images where img_email='$email' and img_item_number='$item'";
  $imgresult = mysql_query($imgquery);
  $id = mysql_result($imgresult,0,0);

if ($id && ($row_Recordset1['item_number'] != '')){
print "<a href='full.php?email=".$row_Recordset1['email']."&item=".$row_Recordset1['item_number']."'>
<img src='../thumb.php?email=".$row_Recordset1['email']."&item=".$row_Recordset1['item_number']."&w=75' border=0><br>View Full Size</a>";
} else
{ print "No Image";
}
}
?>
                          &nbsp; </span> </div></td>
                    </tr>
                    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
                  </table>[/color]

Thanks in advance for your help.

~Links1573

Share this post


Link to post
Share on other sites

×

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.