Jump to content

num_rows not showing


learningcurve

Recommended Posts

I have a query that is working beautifully (thanks to some stellar help form this forum).  At this point, there is only one problem.  I want a statement to print in the results right before a table that contains the results "Your query returned $num_rows responses."  Right now it is printing the statement as such "Your query returned responses." and not even leaving a place where num_rows should be.  I am not getting any errors either.  Any ideas?  I am fairly new to php, soooo.....

 

<html>
<head>
</head>
<body>
<?php
//db connections or error returns
$connect = mysql_connect(DELETED);
if (!$connect)
{
   exit('<p>Unable to connect to the server at this time.</p>');
}
mysql_select_db("surveys");
if (!mysql_select_db("surveys"))
{
    exit ('<p>Unable to locate the database at this time.</p>');
}

//if the "submit" variable does not exist, the form has not been submitted - display initial page 
if (!isset($_POST['submit'])) {
    
//form
?>
<form name="sgid" id="sgid" method="post" action="sgidsurveyquery.php">
<h1>SGID Satisfaction Survey Results</h1>
<h2>Results can be filtered by evaluation party and semester/year given.</h2></br>
Please choose:
<?php
//pull evaluator drop down choices from db as array
$query="SELECT q1 FROM surveys.SGID_satisfaction";
$result=mysql_query($query);
$options="";
while ($row=mysql_fetch_array($result)){
    $evaluator=$row("q1");
    $options.="<OPTION VALUE=>$evaluator</option";

}
?>

<select name="evaluator">
<option value=0>
    <? echo $options?>
</select>

for
<?php
//pull date drop down choices from db as array
$query="SELECT q2 FROM surveys.SGID_satisfaction";
$result=mysql_query($query);
$options="";
while ($row=mysql_fetch_array($result)){
    $date=$row("q2");
    $options.="<OPTION VALUE=>$date</option";
}
?>

<select name="date">
<option value=0>
    <? echo $options?>
</select>

<input type="submit" name ="submit" value="Show Results">
</form>
<?php
}
else {
    
//display results 
  print"<h2>SGID Satisfaction Survey Results</h2><br/>";

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

echo "<h3>Results of SGID Satisfaction Survey for $evaluator and $date</h3></br>";
$num_rows = mysql_num_rows($result);
echo "Your query returned $num_rows responses.";

//Start a table
print "<table CELLPADDING=10 border =1 >";
print "<tr>";
print "<th style='width:150px'>Which organization did your SGID?</th>";
print "<th style='width:100px'>Please specify the semester and year the SGID was done.</th>";
print "<th style='width:300px'>What about this service was helpful for your teaching?</th>";
print "<th style='width:300px'>What about this service could be improved to support your teaching?</th>";
print "<th style='width:300px'>Would you be willing for us to contact you later about what, if anything, you have changed and how that has affected student learning?</th>";
print "</tr>";

$result = mysql_query ($query) or die(mysql_error());
while ($row = @mysql_fetch_array($result)) {

        print "<table CELLPADDING=10 border = 1>";
        print "<tr>";
print "<td style='width:150px'>".$row['q1']."</td>";
print "<td style='width:100px'>".$row['q2']."</td>";
print "<td style='width:300px'>".$row['q3']."</td>";
print "<td style='width:300px'>".$row['q4']."</td>";
print "<td style='width:300px'>".$row['q5']."</td>";
print "</tr>";
print "</table>";
}

//close results
mysql_close();  
}
?>
</body>
</html>


Link to comment
Share on other sites

$query = "SELECT q1, q2, q3, q4, q5
FROM surveys.SGID_satisfaction
WHERE q1='$evaluator'
AND q2= '$date'
ORDER BY created";

echo "<h3>Results of SGID Satisfaction Survey for $evaluator and $date</h3></br>";
$num_rows = mysql_num_rows($result);
echo "Your query returned $num_rows responses.";

 

By the looks of it here, your not getting the number of rows because $result variable does not exist; you have not ran the query!

 

After $query =  you need to run $result = mysql_query($query);

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.