Evanthes Posted September 18, 2006 Share Posted September 18, 2006 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 Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 18, 2006 Share Posted September 18, 2006 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] Quote Link to comment Share on other sites More sharing options...
Evanthes Posted September 18, 2006 Author Share Posted September 18, 2006 i updated my first post, basically there are multiple records that have the same work_id and i want to display the number of records for each work_id...im gonna keep fiddling with this Quote Link to comment Share on other sites More sharing options...
craygo Posted September 18, 2006 Share Posted September 18, 2006 So you are looking to group the results and then count how many records in that group. correct??? And the grouping is on the work_id??Ray Quote Link to comment Share on other sites More sharing options...
Evanthes Posted September 18, 2006 Author Share Posted September 18, 2006 yeah exactly, hopefully within the for loop, so it goes in the right spot on my table, and it knows that record we're dealing with Quote Link to comment Share on other sites More sharing options...
Evanthes Posted September 18, 2006 Author Share Posted September 18, 2006 sweet i got it, your statement worked out really well obsidian, thanks a lot! 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.