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
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

Link to comment
Share on other sites

"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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.