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
https://forums.phpfreaks.com/topic/264511-num_rows-not-showing/
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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.