When I include the following bit of code on a page my site seems to break. It doesnt get past this part of the code and also I cannot load any other part of the site... This is until I close the browser and open it again, however the same problem occurs when I run this script. Any ideas why this is so? This piece of code was working fine though like once or twice without the problems mentioned.
<?php
$ip=$_SERVER['REMOTE_ADDR'];
$query=mysql_query("SELECT * FROM votes WHERE voter='$ip'") or die(mysql_error());
$query_total=mysql_query("SELECT * FROM polls") or die(mysql_error());
$num_of_polls=mysql_num_rows($query_total);
$selected_poll=mt_rand(1,$num_of_polls);
$x=1;
while($row=mysql_fetch_array($query))
{
$voted_poll[$x]=$row['poll_id'];
$x+=1;
}
$loop="1";
while(isset($loop))
{
if(in_array($selected_poll,$voted_poll))
{
$selected_poll=mt_rand(1,$num_of_polls);
}
else
{
unset($loop);
}
}
$query=mysql_query("SELECT * FROM polls WHERE id='$selected_poll'")or die(mysql_error());
$row=mysql_fetch_array($query);
echo $row['question'];
?>
Question
~Matt~
When I include the following bit of code on a page my site seems to break. It doesnt get past this part of the code and also I cannot load any other part of the site... This is until I close the browser and open it again, however the same problem occurs when I run this script. Any ideas why this is so? This piece of code was working fine though like once or twice without the problems mentioned.
<?php $ip=$_SERVER['REMOTE_ADDR']; $query=mysql_query("SELECT * FROM votes WHERE voter='$ip'") or die(mysql_error()); $query_total=mysql_query("SELECT * FROM polls") or die(mysql_error()); $num_of_polls=mysql_num_rows($query_total); $selected_poll=mt_rand(1,$num_of_polls); $x=1; while($row=mysql_fetch_array($query)) { $voted_poll[$x]=$row['poll_id']; $x+=1; } $loop="1"; while(isset($loop)) { if(in_array($selected_poll,$voted_poll)) { $selected_poll=mt_rand(1,$num_of_polls); } else { unset($loop); } } $query=mysql_query("SELECT * FROM polls WHERE id='$selected_poll'")or die(mysql_error()); $row=mysql_fetch_array($query); echo $row['question']; ?>Link to comment
Share on other sites
3 answers to this question
Recommended Posts