greencoin Posted June 28, 2007 Share Posted June 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 28, 2007 Share Posted June 28, 2007 i think it could be if ($result = mysql_query($sql)) { but $result isnt defined anywhere and if you comparing shouldnt you use == ~ Chocopi Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 28, 2007 Share Posted June 28, 2007 Print out the $sql query that's being built. Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 "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 Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 28, 2007 Share Posted June 28, 2007 You need a semi-colon after the "die ($sql)" statement; the parser is running into the if() and isn't expecting it. Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 ack! I keep forgettin my semicolons... here's what you're lookin for; SELECT * FROM GC_Tracker WHERE ("area" LIKE '%ak%' OR "area" LIKE '%LA%' ) whatcha think? ~Rich Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 29, 2007 Author Share Posted June 29, 2007 *Bump* ~Rich Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 29, 2007 Share Posted June 29, 2007 SELECT * FROM GC_Tracker WHERE ("area" LIKE '%ak%' OR "area" LIKE '%LA%' ) ^^ does that thing work??? Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 29, 2007 Author Share Posted June 29, 2007 Ahhh... you tell me. I believe the syntax is correct and the field + variables are correct too. Am going to bed now. Ttyl ~Rich Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 29, 2007 Author Share Posted June 29, 2007 Ok back - anyone have any suggestions? ~Rich Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 29, 2007 Share Posted June 29, 2007 Yeah, take the double quotes off the "area"; you're specifying the string "area" by enclosing it in quotes; you want the column area. If you really, really want to quote the column, use backticks (`area`), not double or single quotes. Quote Link to comment Share on other sites More sharing options...
greencoin Posted June 29, 2007 Author Share Posted June 29, 2007 I am humbled and ashamed... the original code used bar ticks but I changed them trying to figure out the problem. Wildbug.. You da schiz-nit! Thanks for your help, again. ~Rich Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.