3v4l.org

run code in 300+ PHP versions simultaneously
// viewprofiles.php <?php include_once("header.php"); echo $user.' is currently logged in<br><br>'; echo <<<_END <form method="post" action="viewprofiles.php"><pre> <input type="submit" name ="choice" value="LIKE" /> <input type="submit" name ="choice" value="NEXT PROFILE" /> </pre></form> _END; $allusers = array(); //Create the $allusers array, comprised of all users except me $result = queryMysql("SELECT * FROM members"); $num = mysql_num_rows($result); for ($j = 0 ; $j < $num ; ++$j) { $row = mysql_fetch_row($result); if ($row[0] == $user) continue; $allusers[$j] = $row[0]; } //Create the $i_like_these_users array, comprised of all users i liked $result = queryMysql("SELECT * FROM likeprofile WHERE user='$user'"); $num = mysql_num_rows($result); for ($j = 0 ; $j < $num ; ++$j) { $row = mysql_fetch_row($result); $i_like_these_users[$j] = $row[1]; } //Create the $i_dislike_these_users array, comprised of all users i disliked $result = queryMysql("SELECT * FROM dislikeprofile WHERE user='$user'"); $num = mysql_num_rows($result); for ($j = 0 ; $j < $num ; ++$j) { $row = mysql_fetch_row($result); $i_dislike_these_users[$j] = $row[1]; } //Create the $usersiviewed array, comprised of all users i have either liked or disliked if (is_array($i_like_these_users) && is_array($i_dislike_these_users)) { $usersiviewed = array_merge($i_like_these_users,$i_dislike_these_users); } elseif(is_array($i_like_these_users)) { $usersiviewed = $i_like_these_users; } else { $usersiviewed = $i_dislike_these_users; } // this removes from the array $allusers (i.e., profiles i can view) all $usersviewed (i.e., all the profiles i have already either liked/disliked) if (is_array($usersiviewed)) { $peopleicanview = array_diff($allusers, $usersiviewed); $peopleicanview = array_values($peopleicanview); // this re-indexes the array } else { $peopleicanview = $allusers; $peopleicanview = array_values($peopleicanview); // this re-indexes the array } $current_user_profile = $peopleicanview[0]; echo 'check out '.$current_user_profile.'s picture <br />'; if (file_exists("$current_user_profile.jpg")) {echo "<img src='$current_user_profile.jpg' align='left' />";} // if i like or dislike this person, the likeprofile or dislikeprofile table is updated with my name and the name of the person who liked or disliked if (isset($_POST['choice']) && $_POST['choice'] == 'LIKE') { $ilike = $current_user_profile; $query = "INSERT INTO likeprofile VALUES" . "('$user', '$ilike')"; if (!queryMysql($query)) echo "INSERT failed: $query<br />" . mysql_error() . "<br /><br />"; } if (isset($_POST['choice']) && $_POST['choice'] == 'NEXT PROFILE') { $idontlike = $current_user_profile; $query = "INSERT INTO dislikeprofile VALUES" . "('$user', '$idontlike')"; if (!queryMysql($query)) echo "INSERT failed: $query<br />" . mysql_error() . "<br /><br />"; } ?>

preferences:
27.56 ms | 402 KiB | 5 Q