Jump to content

[SOLVED] Query not returning any results


greencoin

Recommended Posts

HI! was getting another error but read about the mysql functions and since modified my code. Now I'm getting "No Results Found" which is one of the "else" returns as you'll see.

 

<?php 

// db connect stuff goes here 

$name2 = $_POST['state'];
for($name2array=0; $name2array < sizeof($name2); $name2array++)
{
if($name2array < (sizeof($name2)-1)) { $name2_cond = " OR "; }
else { $name2_cond = ""; }
$name2q = $name2q."\"area\" LIKE '%".$name2[$name2array]."%' $name2_cond";

}
$name2q = "($name2q)";
$sql = "SELECT * FROM GC_Tracker WHERE $name2q";
if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {
        $i = 0;
        echo "<TABLE width=\"850\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">\n";
        echo "<TR bgcolor=\"ccffcc\"><TD>ID</TD><TD width=130>Customer</TD><TD width=75>Area</TD><TD width=75>City</TD><TD width=100>Phone</TD><TD width=75>Amount</TD><TD>Units</TD></TR>\n";
        while ($row = mysql_fetch_array($result)) {
          if ($i % 2) {
            echo "<TR bgcolor=\"ccffcc\">\n";
          } else {
            echo "<TR bgcolor=\"white\">\n";
          }
          echo "<TD>".$row['cid']."</TD><TD>".$row['customer']."</TD><TD>".$row['area']."</TD><TD>".$row['city']."</TD>
	  <TD>".$row['phone']."</TD><TD>".$row['amount']."</TD>
	  <TD>".$row['prod1'].", ".$row['prod2'].", ".$row['prod3'].", ".$row['prod4'].", ".$row['prod5'].", ".$row['prod6'].", ".$row['prod7'].", ".$row['prod8'].", ".$row['prod9'].", ".$row['prod10']."</TD>\n";
          echo "</TR>\n";
          $i++;
        }
        echo "</TABLE>\n";
	echo "<br>\n";
	echo "<input type=Button name=printit value=print onclick=javascript:window.print();>\n";
      } else {
        echo "No results found"; // this is what it's spitting out
      }
    } else {
      echo "Query failed<br />" . $sql . "<br />" . mysql_error();
  }
?>

 

Could someone point me in the right direction to debug or point out the flaw in my code. The database is loaded so I should've had a result based on the input.

Link to comment
https://forums.phpfreaks.com/topic/57597-solved-query-not-returning-any-results/
Share on other sites

I recycled this code from a working page on the same website that queries MySQL for all records of a specific field. I don't think I'll need the == as I'm not comparing.

 

I created an array that posts all row data with corresponding field data (supposed to). ~Rich

"Parse error: parse error, unexpected T_IF in http://./././track_area_results.php on line 16"

 

<?php

$name2 = $_POST['state'];
for($name2array=0; $name2array < sizeof($name2); $name2array++)
{
if($name2array < (sizeof($name2)-1)) { $name2_cond = " OR "; }
else { $name2_cond = ""; }
$name2q = $name2q."\"area\" LIKE '%".$name2[$name2array]."%' $name2_cond";

}
$name2q = "($name2q)";
$sql = "SELECT * FROM GC_Tracker WHERE $name2q";
die ($sql)
if ($result = mysql_query($sql)) {                               // This is line 16
      if (mysql_num_rows($result)) {
        $i = 0;
        echo "<TABLE width=\"850\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">\n";
        echo "<TR bgcolor=\"ccffcc\"><TD>ID</TD><TD width=130>Customer</TD><TD width=75>Area</TD><TD width=75>City</TD><TD width=100>Phone</TD><TD width=75>Amount</TD><TD>Units</TD></TR>\n";
        while ($row = mysql_fetch_array($result)) {
          if ($i % 2) {
            echo "<TR bgcolor=\"ccffcc\">\n";
          } else {
            echo "<TR bgcolor=\"white\">\n";
          }
          echo "<TD>".$row['cid']."</TD><TD>".$row['customer']."</TD><TD>".$row['area']."</TD><TD>".$row['city']."</TD>
	  <TD>".$row['phone']."</TD><TD>".$row['amount']."</TD>
	  <TD>".$row['prod1'].", ".$row['prod2'].", ".$row['prod3'].", ".$row['prod4'].", ".$row['prod5'].", ".$row['prod6'].", ".$row['prod7'].", ".$row['prod8'].", ".$row['prod9'].", ".$row['prod10']."</TD>\n";
          echo "</TR>\n";
          $i++;
        }
        echo "</TABLE>\n";
	echo "<br>\n";
	echo "<input type=Button name=printit value=print onclick=javascript:window.print();>\n";
      } else {
        echo "No results found";
      }
    } else {
      echo "Query failed<br />" . $sql . "<br />" . mysql_error();
  }
?>

 

Thanks Wildbug ~Rich

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.