learningcurve Posted June 14, 2012 Share Posted June 14, 2012 I have a form(sgid5form.php): <form name="sgid" id="sgid" method="post" action="sgid5.php"> <h1>Results from SGID satisfaction survey. Results can be filtered by evaluation party or semester/year given.</h1></br> Please choose: <select name="evaluator"> <option value="ALT (John, Tim and Bob)">ALT (John, Tim and Bob)</option> <option value="CELTUA (Geoff or Joe)">CELTUA (Geoff or Joe)</option> <option value="CTL MUM (MUM Faculty)">CTL MUM (MUM Faculty)</option> <option value="CTL VOA (VOA or MUM Faculty)">CTL VOA (VOA or MUM Faculty)</option> </select> for <select name="date"> <option value="Fall 2010">Fall 2010</option> <option value="Fall 2011">Fall 2011</option> <option value="Fall 2012">Fall 2012</option> <option value="Fall 2013">Fall 2013</option> <option value="Spring 2010">Spring 2010</option> <option value="Spring 2011">Spring 2011</option> <option value="Spring 2012">Spring 2012</option> <option value="Spring 2012">Spring 2013</option> </select> <input type="submit" name ="submit" value="Show Results"> </form> That submits to this php page (sgid5.php): <html> <head> </head> <body> <?php $connect = mysql_connect(#####DELETED####); mysql_select_db("surveys"); print "SGID Satisfaction Survey Results"; $evaluator=$_POST['evaluator']; $date=$_POST['date']; $query = "SELECT q1, q2, q3, q4, q5 FROM surveys.SGID_satisfaction WHERE q1='$evaluator' AND q2= '$date' ORDER BY created"; $result = mysql_query ($query); while ($row = @mysql_fetch_array($result)) //Start a table print "<center>"; print "<table CELLPADDING=10 border =1 >"; print "<tr>"; print "<th>q1</th>"; print "<th>q2</th>"; print "<th>q3</th>"; print "<th>q4</th>"; print "<th>q5</th>"; print "</tr>"; print "<tr>"; print "<td>".$row['q1']."</td>"; print "<td>".$row['q2']."</td>"; print "<td>".$row['q3']."</td>"; print "<td>".$row['q4']."</td>"; print "<td>".$row['q5']."</td>"; print "</tr>"; print "</table>"; mysql_close(); ?> </body> </html> That should return the results in a real simple table. I am not getting any errors, but no results are posting either. I have attached a jpeg of what appears on my screen. I am really new to php and need all the help I can get. Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 14, 2012 Share Posted June 14, 2012 You're suppressing errors with the @ symbol. Remove that, and ensure error reporting is on and set to E_ALL. Quote Link to comment Share on other sites More sharing options...
learningcurve Posted June 14, 2012 Author Share Posted June 14, 2012 Okay, thanks for the heads up. I removed the @. Errors were already turned on and I was getting them earlier in my coding. After removing the @, condition is the - no errors and same output. thanks! Quote Link to comment Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 Did you make sure it is even returning anything? You can check with mysql_num_rows($result);. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted June 14, 2012 Share Posted June 14, 2012 Try echo'ing your $query to make sure it's what you're expecting: $query = "SELECT q1, q2, q3, q4, q5 FROM surveys.SGID_satisfaction WHERE q1='$evaluator' AND q2= '$date' ORDER BY created"; echo $query; And check for query errors: $result = mysql_query ($query) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 14, 2012 Share Posted June 14, 2012 echo your $query before running it and see if it looks the way you expect. Try running it in a tool like phpmyadmin and see if it works. What does your data look like Quote Link to comment Share on other sites More sharing options...
learningcurve Posted June 14, 2012 Author Share Posted June 14, 2012 Great suggestions! echo returns just what it should and looks good running the query in sequel pro returns results when I substitute the variable for one of the choices adding mysql_num_rows tells me the query created six rows for the example I ran where I knew data would return. Any more suggestions? :'( Quote Link to comment Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 Can you eliminate other output in your script and post back the exact results of this? $query = "SELECT q1, q2, q3, q4, q5 FROM surveys.SGID_satisfaction WHERE q1='$evaluator' AND q2= '$date' ORDER BY created"; $result = mysql_query ($query) or die('Query: ' . $query . '<br>Error: ' . mysql_error()); echo 'Query: ' . $query . '<br>'; echo 'Rows returned: ' . mysql_num_rows($result) . '<br>'; echo '<pre>'; while($row = mysql_fetch_assoc($result)) { print_r($row); } echo '</pre>'; Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted June 14, 2012 Share Posted June 14, 2012 Great suggestions! echo returns just what it should and looks good running the query in sequel pro returns results when I substitute the variable for one of the choices adding mysql_num_rows tells me the query created six rows for the example I ran where I knew data would return. Any more suggestions? :'( You shouldn't need to substitute anything. Take exactly what was echo'd to the screen and put it directly in your sequel pro. Quote Link to comment Share on other sites More sharing options...
learningcurve Posted June 14, 2012 Author Share Posted June 14, 2012 Scootstah, Did what you wanted and here is what came back. Looks good - just what I want to appear in my table. SGID Satisfaction Survey ResultsQuery: SELECT q1, q2, q3, q4, q5 FROM surveys.SGID_satisfaction WHERE q1='CELTUA (Geoff or Joe)' AND q2= 'Spring 2012' ORDER BY created Rows returned: 4 Array ( [q1] => CELTUA (Geoff or Joe) [q2] => Spring 2012 [q3] => This service is very useful; it is much more useful than the end-semester evaluations. In particular, the strength and weakness of the teaching are given in very detail, thus it is very easy to follow the suggestions to make improvement in teaching. I have absolutely benefited from this program. [q4] => It is almost perfect. [q5] => yes, I would like to be contacted. ;; ) Array ( [q1] => CELTUA (Geoff or Joe) [q2] => Spring 2012 [q3] => Discussing the 'improvement' part of the comments with SGID facilitator was helpful. The facilitator gave me some suggestions for improvements based on his experience. [q4] => [q5] => Yes. ;; ) Array ( [q1] => CELTUA (Geoff or Joe) [q2] => Spring 2012 [q3] => Getting a mid-term update on what the class is thinking. [q4] => [q5] => ) Array ( [q1] => CELTUA (Geoff or Joe) [q2] => Spring 2012 [q3] => Helpful feedback. It was also helpful to discuss the results in-person with the SGID leader. [q4] => The only thing that I can think of is maybe to advertise it more widely so that more people know about it. Most of my students have commented that they have never done this before. ;; ;; Also, it may be helpful to have it take less than 1/2 hr. or have choices for a 1/2 hr session or a 15 min. session. ;; ;; I would also be interested to know what students think about it. [q5] => ) So what does this mean? I am really, really appreciating all the help I am getting here. Quote Link to comment Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 Upon closer inspection it appears you did not use any opening/closing brackets on your while loop, which I believe is your problem. Does this work? while ($row = @mysql_fetch_array($result)) { //Start a table print "<center>"; print "<table CELLPADDING=10 border =1 >"; print "<tr>"; print "<th>q1</th>"; print "<th>q2</th>"; print "<th>q3</th>"; print "<th>q4</th>"; print "<th>q5</th>"; print "</tr>"; print "<tr>"; print "<td>".$row['q1']."</td>"; print "<td>".$row['q2']."</td>"; print "<td>".$row['q3']."</td>"; print "<td>".$row['q4']."</td>"; print "<td>".$row['q5']."</td>"; print "</tr>"; print "</table>"; } Quote Link to comment Share on other sites More sharing options...
learningcurve Posted June 14, 2012 Author Share Posted June 14, 2012 You, sir, are an absolute fricking genius! That was it. The table is kinda wobbly and ugly looking, but I can tidy it up now that it is working. BRAVO and THANK YOU! Quote Link to comment Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 All that work for missing brackets... Oh, and as a side note: you don't need to (and shouldn't) run mysql_close(). PHP will automatically close the MySQL connection for you. 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.