djscoop Posted December 26, 2010 Share Posted December 26, 2010 Hey guy's, have been stuck at this hurdle for a little whole now and I can't seem to find the right solution and would very much appreciate anyones help on this. Ok, so I have a table of votes and each time a user votes, they're added to this table. Now, I have a 'pool' table which will display certain items. What I'm trying to do is display the 'pool' items, but if this specific user has already voted on this particular item, then I want it to skip the item in the 'pool' and go to the next item, until the argument of has that user voted is false. The current code I'm pasting will obviously not work, it isn't even in the right position, but I've separated it so that you can hopefully understand what I'm trying to do in order to help. Below is the code I use to check if a user has already voted on a particular photo: <?php $result=mysql_query("SELECT * FROM votes WHERE vVoter='$_SESSION[userID]' AND vPhoto='$_SESSION[currentphoto]'"); $rowCheck = mysql_num_rows($result); $alreadyv = 0; if($rowCheck > 0){ $alreadyv = 1; //user has already voted on this photo, need to use this info to be able to skip it in the 'pool' } else { //do nothing } ?> totalVoted is basically how many times a user has voted, so that people who vote more, get more votes: <?php $result=mysql_query("SELECT * FROM pool ORDER BY totalVoted DESC LIMIT 1"); $rowCheck = mysql_num_rows($result); if($rowCheck > 0){ while($row = mysql_fetch_array($result)){ $photoid = $row['photoInPool']; $result2=mysql_query("SELECT * FROM photos WHERE pID='$photoid'"); $rowCheck2 = mysql_num_rows($result2); if($rowCheck2 > 0){ while($row2 = mysql_fetch_array($result2)){ if($alreadyv == 1) { //I NEED THIS TO SHOW THE NEXT PHOTO IN THE ARRAY, HOWEVER, IF THEY HAVE ALREADY VOTED ON THE NEXT PHOTO, IT WILL STILL DISPLAY IT, THIS IS MY PROBLEM I NEED HELP WITH PLEASE } elseif ($alreadyv != 1) { $fname = $row2['pFileName']; } } } $_SESSION[currentphoto] = $row['photoInPool']; echo "<center><img src='user_images/$fname'></center>"; } } ?> I hope I've explained this well enough and hope somebody can help. Many thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/222664-skipping-a-row-in-mysql_fetch_array-until-an-argument-is-valid/ Share on other sites More sharing options...
solon Posted December 26, 2010 Share Posted December 26, 2010 Hey djscoop, could you provide us with some more database information? how does you script store the votes in the db? if possible show us the structure of your database tables to see if there is another way of extracting the information you want with a mysql query! Quote Link to comment https://forums.phpfreaks.com/topic/222664-skipping-a-row-in-mysql_fetch_array-until-an-argument-is-valid/#findComment-1151517 Share on other sites More sharing options...
djscoop Posted December 26, 2010 Author Share Posted December 26, 2010 Hey solon, pool table: poolID pVoterID - user who made vote on someone elses photo lastPoolVote - date of vote totalVoted - total that a user has voted on others photos pPriority - the priority has not yet been assigned and may not be needed photoInPool - This is the users primary photo which will be voted on by others votedOn - total amount of times other users have voted on users photoInPool photo votes table: vID vPhoto - the photo that has been voted on vAge - the age that has been voted for that photo vVoter - the user who voted vMember - wether or not the person voting is a visitor or user photos table: I have pID here and pOwner which will be needed to associate with the other tables. pID being the photo id and pOwner being the owner of the photo When a guest votes, the pool is not affected, but stores session data so that can vote on each photo once during session. When a user votes, it inserts data into the pool table When another user votes on another users photo, it updates the tables accordingly, i.e. if user A votes on user B, user B's votedOn will be incremented by 1. The photos being listed are selected from the 'pool' table. Although, if a user has already voted on a particular photo, I need it to skip that photo in the 'pool' table and go to the next row in the 'pool' table as I am ordering it by totalVoted DESC, so that users who vote most get their photo's voted on more. I will be changing the algorithm slightly so that once a user has not voted in X amount of time and has received a % of votes based on how many votes they have made, then they will be removed from 'pool'. I use $_SESSION['currentphoto'] to store the current photo being displayed to the user. If you require anymore info please ask. Many thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/222664-skipping-a-row-in-mysql_fetch_array-until-an-argument-is-valid/#findComment-1151520 Share on other sites More sharing options...
spaceman12 Posted December 26, 2010 Share Posted December 26, 2010 if(!$alreadyv == 1) and it will automatically skip by itself provided you remove off the "ELSE " Quote Link to comment https://forums.phpfreaks.com/topic/222664-skipping-a-row-in-mysql_fetch_array-until-an-argument-is-valid/#findComment-1151524 Share on other sites More sharing options...
djscoop Posted December 26, 2010 Author Share Posted December 26, 2010 Hi spaceman12, yeah if I use if(!$alreadyv == 1) then it will only echo the photo if that argument is true, but if it is false it will do nothing, but I need it to go to the next row in the table that !$alreadyv==1 is false Thanks Quote Link to comment https://forums.phpfreaks.com/topic/222664-skipping-a-row-in-mysql_fetch_array-until-an-argument-is-valid/#findComment-1151525 Share on other sites More sharing options...
djscoop Posted December 26, 2010 Author Share Posted December 26, 2010 solved so easily, knew there was a way to skip... continue; :-) Quote Link to comment https://forums.phpfreaks.com/topic/222664-skipping-a-row-in-mysql_fetch_array-until-an-argument-is-valid/#findComment-1151553 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.