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?

Link to comment
Share on other sites

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>";

 

 

 

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.