Jump to content

php/mysql query not showing results in a table


learningcurve

Recommended Posts

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. 

post-132200-13482403593429_thumb.jpg

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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?  :'(

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";
}

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.