Jump to content

help with 'count'


davieboy

Recommended Posts

um well you ca do it in SQL, but ill have to look it up

 

in php youd go

 

SQL = "Select image, hits from etc...."

 

loop through query results

 

while $result = ,mysql_fetch_array{

$total_hits = $result['hits'] + $total_hits;

}

ehco $total_hits

 

 

SQL would be easier...

 

 

ill look it up l8a, remind me with a PM

Link to comment
https://forums.phpfreaks.com/topic/46554-help-with-count/#findComment-226609
Share on other sites

how would i then get it with the totals

 

$query = "SELECT *, SUM(hits) FROM photos GROUP by hits DESC LIMIT 5"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while ($r=mysql_fetch_array($result))
{  
$id=$r["id"];
$copyright =$r["copyright"];
$hits= $r["hits"];
$airline = $r["airline"];
echo "<a href=\"photographer.php?photographer=$copyright\">$hits / $copyright<br>";
//

}

Link to comment
https://forums.phpfreaks.com/topic/46554-help-with-count/#findComment-228268
Share on other sites

Use print_r() for getting Array content.

For instance:

<?php
   $arr['key'] = 'value';
   print_r($arr);
?>
You see something like
[code]Array (
   [key] => value
)

 

Now you can get the result of query like that:

<?php
   //...
   $result = mysql_query($query) or die(mysql_error());
   $row = mysql_fetch_assoc($result);
   print_r($row);
?>

and now you'll know how to use that query.[/code]

Link to comment
https://forums.phpfreaks.com/topic/46554-help-with-count/#findComment-228300
Share on other sites

figured part of it out

 

$query = "SELECT *, COUNT(hits) AS COUNT FROM photos GROUP BY copyright LIMIT 5"; 
//$query = "SELECT device_id, COUNT(week) AS count FROM failed WHERE week = '$week' GROUP BY device_id";
$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) 

{ 
echo $row['id'] . ' <a href=\"/photographer.php?photographer=' . $row['copyright'] .'\">' . $row['copyright'] . '</a><br>'; 
$copyright = $row['copyright'];
$hits = $row['hits'];

 

giving an odd number at the top thought

2460

3111 user1

2477 user2

2094 user3

2062 user4

 

not sure why or where from

Link to comment
https://forums.phpfreaks.com/topic/46554-help-with-count/#findComment-228459
Share on other sites

actually ive changed it a we bit.

 

trying to find out the total number of images in the database from certain people ordered by the most number first.

 

SELECT *, COUNT(id) AS COUNT FROM photos WHERE status ='accepted' and in_screening = '1' GROUP BY copyright DESC LIMIT 5

 

and its not working :(

Link to comment
https://forums.phpfreaks.com/topic/46554-help-with-count/#findComment-228497
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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