monkeytooth Posted December 26, 2007 Share Posted December 26, 2007 Ok for starters I know this has had to be answered somewhere, but I have spent the last 2 hours playing with a small piece of code doing anything from changing it completely 100 times over to just modifying the existing 100 times over.. Unfortunately I am just getting back into web design. So I'm a bit rusty and what used to work with php 4/5 and mysql 4 for me doesn't with mysql 5. Not to mention alot of new functions and a lot of old ones tossed.. So long story short I don't know what type of function I am looking for exactly anymore. So I am using.. PHP Version: 4.3.11 MySQL Version: 5.0.27 Hosting: Godaddy / Linux Based account. what I am trying to do is generate a total count of rows in a particular table in my database via php script so I can just keep an over all tally of entries. or if I am grabbing a specific row i want to show "xx of zz" above it zz being the total row count. Eventually I will break it down further by category so it counts only xx of zz within a certain WHERE field but I can't get over this one hump of getting the full count first. Then eventually I will want to do the xx of zz / page 1 2 3 4 5 type of stuff but im getting a head of myself.. Again im pulling my hair out im frustrated cause this is something I used to do with ease, and I am feelin a bit dumb at the moment. Ive search google and various forums for a few good hours while tempting to tweak what I have looking for what ever error i may have made between old versions Im used to to new, and then looking for samples of new versions compatible with what im using and im not getting anywhere.. pleas help I would use a sample of code I have been using but theres been so many different attempts i dunno.. Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/ Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Did you try SELECT COUNT ? Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423484 Share on other sites More sharing options...
monkeytooth Posted December 26, 2007 Author Share Posted December 26, 2007 $query = "SELECT COUNT(*) AS numrows FROM Prjct"; $result = mysql_query($query) or die('Error, query failed: '. mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; above was my last attempt before I gave up an decided to post.. this is one of another varations.. $query="SELECT * FROM Prjct"; $result=mysql_query($query); $numba=mysql_numrows($result); Prjct is the table name.. database name is mt_soulz dunno if that could help any either.. Also I have checked I am connected to the DB no problem, and have atleast 1 or 2 entries in the table im looking to get a count on.. Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423487 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 On your 2nd one, change $numba=mysql_numrows($result); to $numba=mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423491 Share on other sites More sharing options...
monkeytooth Posted December 26, 2007 Author Share Posted December 26, 2007 well, im glad that was pointed out.. however I am still getting errors.. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in index_insert_db.php on line 22 where line 22 is: $numba=mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423494 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Change $result=mysql_query($query); to $result=mysql_query($query) or die ("Error in query: $query. " . mysql_error()); and post the error. Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423502 Share on other sites More sharing options...
monkeytooth Posted December 26, 2007 Author Share Posted December 26, 2007 oh man.. that saved me a migraine and a half.. once i saw the error and checked over my code i come to realize my dumb@ss forgot to put a mysql_select_db statement in the connection side of the script.. so everything was in haste, I'm so sorry to have gotten you all with something this simple especially due to the outcome. But at the same time, thank you for helping me debug it so I could find my ultimate error.. once I got the mysql_select_db statement in place... worked like a charm.. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423513 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Enjoy Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423516 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Also, now you want to get your COUNT to work instead, because you really don't want to read all the fields when all you want is just a count. Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423531 Share on other sites More sharing options...
monkeytooth Posted December 26, 2007 Author Share Posted December 26, 2007 how would I do that? Im not to familiar with count per say.. Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423534 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 $query = "SELECT COUNT(*) FROM Prjct"; $result = mysql_query ($query) or die ("Error in query: $query. " . mysql_error()); echo mysql_result ($result,0,0); Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423551 Share on other sites More sharing options...
monkeytooth Posted December 26, 2007 Author Share Posted December 26, 2007 $query = "SELECT COUNT(*) FROM Prjct"; $result = mysql_query ($query) or die ("Error in query: $query. " . mysql_error()); echo mysql_result ($result,0,0); Now out of curiosity, I was actually looking more info up on google an through this form on the count concept.. but I notice, that alot of people have (*) as (Something) and some people even have the ($result,0,0) part diffrent with example ($result,2,6) but they don't breat that down.. maybe you could help? I really do appreciate all help youve given thus far.. its a no function on me, so I just want to know more indebpth if possible, even on php.net theres not a huge break down of what the diffrent parts are as far as those parts mentioned go Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423557 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 This may help http://us.php.net/mysql_result You can also use the AS something if you wanted to alias it and use that number in another mysql statement. Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423558 Share on other sites More sharing options...
monkeytooth Posted December 26, 2007 Author Share Posted December 26, 2007 well, thank you.. you are indeed an extremely helpful person, and that page on php.net i didnt stumble upon that one in my searchs but from the looks its got what i need an more ill have to read up some more.. thanks ever so much yet again.. Quote Link to comment https://forums.phpfreaks.com/topic/83251-solved-php-mysql-totals-for-statistics/#findComment-423564 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.