Jump to content

[SOLVED] count, not seeming to work correctly (I am doing something wrong)


Ninjakreborn

Recommended Posts

I have an area on a clients website where people are allowed to upload a max of 4 photo's.  I need to let them upload them, and return an error when they are over 4 images so they can not upload anymore than 4.  I have this

<?php
$select4 = "SELECT * FROM user_images WHERE userid = '" . $_SESSION['userinfo']['id'] . "';";
$query4 = mysql_query($select4);
if (count(mysql_fetch_array($query4)) <= 3) {
// do the image upload
}else {
echo "You have already reached your max upload number.<br />";
echo "The file has been discarded.<br />";
}
?>

This looks logical to me.  However they upload 1 image, the other 3 give an error, and they had only uploaded one.

Can someone see what I am doing wrong?

Link to comment
Share on other sites

mysql_fetch_array selects the current row and moves the pointer forward. To do what you're trying you need to loop through it. There are examples of how to use that function on the php.net page for it

http://php.net/mysql_fetch_array.

 

If you just want their number, use SELECT count(*) FROM ...

Or use your current query and use mysql_num_rows()

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.