Jump to content

Urgent help needed with arrays


gibigbig

Recommended Posts

not working with my code

 

Warning: array_count_values() [function.array-count-values]: Can only count STRING and INTEGER values! in [path]/downloads2.php on line 270

 

Let me explain a bit more, I have a table in the database named posts. A field in the posts is named "added_by_userid" and I would like to get the "added_by_userid" with the most records in that table. Maybe this can be done with SQL?

Yeah, you wouldn't want to build a huge array with every post ID... that sucks resources.

 

Try this:  (I didn't run this so excuse any typos, but it is close)...

 

$result = mysql_query("SELECT added_by_userid, COUNT(added_by_userid) AS userid FROM posts GROUP BY added_by_userid ORDER BY userid DESC LIMIT 1");
$row = mysql_fetch_assoc($result);

echo "<p>The most popular userid listed is " . row['added_by_userid'] . "</p>";

 

 

 

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.