Created
November 6, 2014 17:27
-
-
Save kaosb/1ce9c3d99351b66a916f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| include("conexion.php"); | |
| if(isset($_POST['ref']) && !empty($_POST['ref']) && $_POST['ref'] != 'undefined' && isset($_COOKIE['heladero']) && !isset($_COOKIE['heladerorefvote'])){ | |
| // En vaso de tener la cookie y estar referido busco a mi amigo para votar por el. | |
| $ref = $_POST['ref']; | |
| $result = mysql_query( " SELECT * FROM participantes WHERE userID = $ref", $link); | |
| }else{ | |
| // En caso de tratarse de un usuario sin la cookie eso quiere decir que no viene referido. | |
| $exclude = (isset($_POST['userID']) && !empty($_POST['userID']) && $_POST['userID'] != 'undefined') ? $_POST['userID'] : '' ; | |
| $exclude = (isset($_POST['ref']) && !empty($_POST['ref']) && $_POST['ref'] != 'undefined') ? $exclude.", ".$_POST['ref'] : $exclude ; | |
| $offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS offset FROM participantes ", $link); | |
| $offset_row = mysql_fetch_object( $offset_result ); | |
| $offset = $offset_row->offset; | |
| $result = mysql_query( " SELECT * FROM participantes WHERE userID NOT IN ($exclude) LIMIT $offset, 1 ", $link); | |
| } | |
| if($result){ | |
| echo json_encode(mysql_fetch_object($result)); | |
| }else{ | |
| echo json_encode("error"); | |
| die(mysql_error()); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment