mcfmullen Posted March 7, 2010 Share Posted March 7, 2010 Here's an odd one I can't figure out for the life of me.. I have the following code that DOES work: <?php $sql3 = "SELECT animalMethods.nameMethod FROM animalMethods WHERE nameAnimal = '{$_GET['animal']}'"; $methods = mysql_query($sql3); if (trim($row['nameMethod']) != '') while($row3 = mysql_fetch_array($methods)){ echo $row3['nameMethod']; echo '<br>'; } else echo 'None'; ?> This code DOES work as well: <?php $sql3 = "SELECT cropMethods.nameMethod FROM cropMethods WHERE nameCrop = '{$_GET['crop']}'"; $methods = mysql_query($sql3); if (trim($row['nameMethod']) != '') while($row3 = mysql_fetch_array($methods)){ echo $row3['nameMethod']; echo '<br>'; } else echo 'None'; ?> This code also DOES work: <?php $sql3 = "SELECT treeMethods.nameMethod FROM treeMethods WHERE nameTree = '{$_GET['tree']}'"; $methods = mysql_query($sql3); if (trim($row['nameMethod']) != '') while($row3 = mysql_fetch_array($methods)){ echo $row3['nameMethod']; echo '<br>'; } else echo 'None'; ?> However, this code does NOT work: <?php $sql3 = "SELECT vehicleMethods.nameMethod FROM vehicleMethods WHERE nameVehicle = '{$_GET['vehicle']}'"; $methods = mysql_query($sql3); if (trim($row['nameMethod']) != '') while($row3 = mysql_fetch_array($methods)){ echo $row3['nameMethod']; echo '<br>'; } else echo 'None'; ?> Where the above three working codes display the methods used to acquire animals, crops, or trees, (or "None" if there is no method) the fourth code always displays "None" rather the the method required to obtain the vehicle (even if there is a method). Table and field names are correct. I even changed the table and field names and get the same result. Running the query in MySQL gets me the correct results. It is in the PHP where I am having a problem but the code is exactly the same as the working samples! Each of these samples exists in a separate php page (animalspec.php, cropspec.php, treespec.php, vehiclespec.php) and those pages are virtually identical. The GET calls does work in vehiclespec.php because I do get the page result of the right vehicle... I even changed WHERE nameVehicle = '{$_GET['vehicle']}'"; to WHERE nameVehicle = 'Tractor'"; and still get "None" as a result and I know that not to be true. Am I overlooking something?? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2010 Share Posted March 7, 2010 Your code has no error checking or error reporting logic in it to get it to tell you why it is failing, so it will also be a little hard for anyone on a forum to tell you why either. For debugging purposes, echo mysql_error(); on the next line after your mysql_query() line to get php/mysql to tell you why the query is failing. Quote Link to comment Share on other sites More sharing options...
mcfmullen Posted March 7, 2010 Author Share Posted March 7, 2010 I've tried that, there is no error to report. If I change the condition from != to == it suddenly displays the methods but won't display "None" if there are no methods. This makes no sense. Quote Link to comment Share on other sites More sharing options...
mcfmullen Posted March 7, 2010 Author Share Posted March 7, 2010 Problem solved! I sheepsihly forget to include a call in my first sql query... sorry to bother you all. 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.