Jump to content

showing number of rows


Evanthes

Recommended Posts

hey guys i think I have a relatively easy question.

I want to be able to see how many records for a primary key there are. I have a table that is filled with all this information. but the number of records doesnt update when i add a new one. check out my code and see what i mean:

[code=php:0]
$zone = $searchterm; // var created for link back to search
$query = "select * from tbl_sites where zone = '".$searchterm."'" ;
$result = mysql_query($query);

$num_results = mysql_num_rows($result);
echo "<center>";
echo "<br><br><a href='test.php'>Return to list of Zones</a>";
echo '<p> number of records found:' .$num_results. '</p>';
echo "<center>";
echo '<table border="1" align="center">';
echo '<tr><td>';
echo 'Site ID</td><td>Net</td><td>State</td><td>Zone</td><td>City</td><td>Address</td><td>Jobs</td>';
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
$siteid = $row['site_id'];
echo '<tr><td>';
echo '<tr><td>';
echo htmlspecialchars(stripslashes($row['site_id']));
echo '</td><td>';
echo stripslashes($row['net']);
echo '</td><td>';
echo stripslashes($row['state']);
echo '</td><td>';
echo "</a>";
echo stripslashes($row['zone']);
echo '</td><td>';
echo "</a>";
echo stripslashes($row['city']);
echo '</td><td>';
echo "</a>";
echo "<a href='siteinfo.php?searchterm=$siteid&zone=$zone'>";
echo stripslashes($row['address']);
echo '</td><td>';
echo "</a>";
echo stripslashes($row['jobs']);
echo '</td>';
echo "</tr>";
[/code]
this statement basically fills my table with data of each record. I'm trying to show the number of jobs and have it update when a new one is added, just like the numer of threads in a topic for a message board like this. although its not working, im guessing i need some sort of mysql_num_rows statement but i guess i dont understand how i can change this. thanks for anyhelp
Link to comment
https://forums.phpfreaks.com/topic/21182-showing-number-of-rows/
Share on other sites

i don't really understand what you're after. you're showing us one row of a table. we don't know what your query is or how you're populating that table at all. mysql_num_rows() simply returns the number of rows that a query has returned. i'm not sure how that's going to help with what you're trying to do. can you be a little more specific? here is an example of a usage of mysql_num_rows():
[code]
<?php
$sql = mysql_query("SELECT * FROM tableName");
$count = mysql_num_rows($sql);
echo "There were $count rows returned.";
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/21182-showing-number-of-rows/#findComment-94181
Share on other sites

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.