Jump to content

[SOLVED] php mysql totals for statistics


monkeytooth

Recommended Posts

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

Link to comment
Share on other sites

$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..

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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