otamendi Posted July 10, 2007 Share Posted July 10, 2007 Hi, i have a mysql database and a php script that uses that. I want to know how many results throw a query in order to know if they have reached a limit. I.E. $sql = mysql_query ("select * from classifieds where user='$username'"); while ($row = mysql_fetch_array($sql)) { } I want to check lets say that only 10 classifieds per 'username' can be created. If ten or more classifieds are in the database for that 'username' then show error message. Quote Link to comment Share on other sites More sharing options...
s0c0 Posted July 10, 2007 Share Posted July 10, 2007 $sql = "select * from classifieds where user='$username'"; $result = mysql_query($sql); $numRows = mysql_num_rows($result); while($row = mysql_fetch_array($result) { // your code here } the number of rows returned will be stored in the $numRows variable. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 select username, count(classifieds) from classifieds group by username maybe^^ Quote Link to comment Share on other sites More sharing options...
s0c0 Posted July 10, 2007 Share Posted July 10, 2007 That won't work, you can't count a table. If you wanted to do this inside the query (which is not a bad idea at all) you would do a count(username) instead of count(classified). Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 oops sorry but you know thats not my intention instead the its the fields any way you know its wrong and you know wht to change right? Quote Link to comment Share on other sites More sharing options...
otamendi Posted July 10, 2007 Author Share Posted July 10, 2007 the number of rows returned will be stored in the $numRows variable. Nice, thanks a lot am going to try it! 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.