I am having a problem with some of this code:
<?php
$q = "SELECT * FROM entries";
$r = mysql_query($q);
if(mysql_num_rows($r)>0):
while($row = mysql_fetch_assoc($r)):
$net_vote = $row['votes_up'] - $row['votes_down'];
$row_id = $row['id'];
?>
<div class='entry'>
<span class='link'>
<a href='<?php echo $row['link']; ?>'> <?php echo $row['title']; ?> </a>
</span>
<span class='votes_count' id='votes_count<?php echo $row['id']; ?>'><?php echo $net_vote." votes"; ?></span>
<span class='vote_buttons' id='vote_buttons<?php echo $row['id']; ?>'>
<?php
$p = "SELECT * FROM entries";
$s = mysql_query($p);
$ip = $_SERVER['REMOTE_ADDR'];
while($rowp = mysql_fetch_assoc($r)) {
if ($row['user_ip'] == $ip) {
noVote();
break;
} else {
$plyList = htmlspecialchars($row_id, ENT_QUOTES);
checkCookieVote($plyList);
break;
}
}
?>
</span>
</div>
<?php
endwhile;
endif;
?>
What is is supposed to do is check if the users IP in the table 'uservotes' and if it is, see what storyid's are on the rows their IP occurs on, and not display the voting system on the story the user has already voted on (i.e. Their IP got logged when they voted).
First problem is that the first while loop is only displaying the first 3 records from the table 'entries' when it should be displaying all 5.
Secondly, it is showing the voting system beside each story after a refresh of the page.
The SQL tables are as follows:
entries:
- id
- title
- link
- votes_up
- votes_down
uservotes:
- user_ip
- story_id
Thanks guys,
Colm