Jump to content

Recommended Posts

Ok here's the code I have come up with so far and what I'd like to be able to do is count the number of posts by each user. The querys I would like to use out of the videos table to count them is: user. But currently all I can get it to count to is 1. So I know I did something wrong. Please Help...

// COUNT ALL USERS ///////////////////////////////////////////////////////////
$selectCount = myQ("SELECT SQL_CALC_FOUND_ROWS * 
FROM `[x]videos`
WHERE `user`='{$_GET["id"]}' 

");
$countRowsSelectCount = myQ("SELECT FOUND_ROWS()");
$countRowsResultCount = mysql_fetch_row($countRowsSelectCount);
$totalRowsCount = $countRowsResultCount[0];

$tpl -> AssignArray(array(
	"video.total" => $totalRowsCount,
	"dbCount.sample" => $totalRows,
));

Link to comment
https://forums.phpfreaks.com/topic/86597-solved-post-counting-problems/
Share on other sites

$query = mysql_query("SELECT COUNT(id field of the table) AS total FROM `[x]videos` WHERE `user`='{$_GET["id"]}' ");

$result = mysql_fetch_assoc($query);

 

your total would be in this variable: $result['total']

 

Using a COUNT(id of table) is a litle better than using "*". If you have a table with a lot of fields and/or rows, using the star causes your database to slow down A LOT.

I just reliezed a flaw in my code of the first post it should actually be like this but I still have the same problem.

 

// COUNT VIDEO POSTS ///////////////////////////////////////////////////////////
$selectCount = myQ("SELECT SQL_CALC_FOUND_ROWS * 
FROM `[x]videos`
WHERE `user`='".me('id')."' 

");
$countRowsSelectCount = myQ("SELECT FOUND_ROWS()");
$countRowsResultCount = mysql_fetch_row($countRowsSelectCount);
$totalRowsCount = $countRowsResultCount[0];

$tpl -> AssignArray(array(
	"video.total" => $totalRowsCount,
	"dbCount.sample" => $totalRows,
));

instead of using a mysql database function use a normal count like a normal person what does found_rows() return ? if its a number you cant count it, whats the point of

 

// COUNT ALL USERS ///////////////////////////////////////////////////////////

$selectCount = myQ("SELECT SQL_CALC_FOUND_ROWS *

FROM `[x]videos`

WHERE `user`='{$_GET["id"]}'

 

it dosent do anything

im sure this wont work

 

$countRowsSelectCount = myQ("SELECT FOUND_ROWS()");

$countRowsResultCount = mysql_fetch_row($countRowsSelectCount);

 

to count things in a table you do somthing like this:

 

$sql = "SELECT COUNT(*) AS whatever FROM table"

 

$result = mysql_query($sql);

 

$row = mysql_fetch_row($result);

 

echo $row[0]; // somtimes u can do echo $row['whatever '];

 

 

BASICALY what timmah1  said

TRY

 

$countRowsSelectCount = myQ("SELECT FOUND_ROWS() AS somthing");

$countRowsResultCount = mysql_fetch_row($countRowsSelectCount);

$totalRowsCount = $countRowsResultCount[0];

 

TRY

myQ("SELECT FOUND_ROWS()");

$countRowsSelectCount = myQ("SELECT @read_the_function_to_see_the_var");

$countRowsResultCount = mysql_fetch_row($countRowsSelectCount);

$totalRowsCount = $countRowsResultCount[0];

Here's the new code I tried:

 

// COUNT VIDEO POSTS ///////////////////////////////////////////////////////////
$query = mysql_query("SELECT COUNT(*) AS total FROM `[x]videos` WHERE `user`='".me('id')."'
$result = mysql_fetch_assoc($query);

$tpl -> AssignArray(array(
	"video.total" => $result,
));

 

But I get this error:

Parse error: syntax error, unexpected T_STRING in /home/sites/spadespace.com/public_html/modules/users/desktop.php on line 227

 

And line 227 is one of these two:

 

$query = mysql_query("SELECT COUNT(*) AS total FROM `[x]videos` WHERE `user`='".me('id')."'
$result = mysql_fetch_assoc($query);

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.