Jump to content

Recommended Posts

Ok so im trying to learn some PhP and MySQL.. but bleh!

 

Ive made a site where people submit their email and name eatch time they add something to my database.

 

I would really like it to output how many times they have submited info to the database.

But i have no idea how to do it, i can ofcourse get the output but then it just goes like this:

joe - [email protected]

joe - [email protected]

bla - [email protected]

bla - [email protected]

joe - [email protected]

joe - [email protected]

bla - [email protected]

 

where i would like it to output:

joe - [email protected] has submitted 4 articles

bla [email protected] has submitted 3 articles

 

Sorry if this should be in the PHP area, as said im kind of new to it all :)

 

Thanks in advance.

a couple of mysql commands you might be interested in

 

<a href="http://www.tizag.com/mysqlTutorial/mysqlcount.php"> MySql Count() command </a>

 

<a href="http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html"> MySql DISTINCT() command </a>

 

 

Something like this should work....keeping in mind that I'm new to this so there is probably an easier way...

 

$query_name = "SELECT DISTINCT name FROM database ORDER BY name";

$result_name = mysql_query($query_name) or die ("couldn't execute query:  . mysql_error()");

while ($row = mysql_fetch_array($result_name,MYSQL_ASSOC) )
{
foreach ($row as $name_found) 
{
$query2 = "SELECT * FROM database	WHERE name ='$name_found'";

$result2 = mysql_query($query2) or die ("couldn't execute query");

$numofrows_name = @mysql_num_rows($result2);

echo "$name_found has submitted $numofrows_name articles";
} // end foreach
} // end while

 

That hasn't been tested, but should give you an idea of what to do.

 

 

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.