Jump to content

HaikelChong

Members
  • Posts

    10
  • Joined

  • Last visited

HaikelChong's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Hello again. Let me give you a rundown on how the codes are supposed to work. When you first enter the page, it will random out a question and 2 names. Based on the question, for example 'Who is fatter?', you have to click either of the 2 hyperlinks based on your answer. One hyperlink will pass in one userID of the name and sames goes for the 2nd hyperlink. That hyperlink will then call a php function to add 1 to the totalCount of that userID. Also, after clicking the hyperlink, it refreshes the page and another set of random question and 2 names will be displayed. And the process continues.With the help i've gotten here, i managed to get all the parts working. Except for one. Problem: After randoming the first set of a question and 2 names and clicking the hyperlink based on my answer, it updated the totalCount of the second set instead of the first set like it was supposed to. My assumption: What i think is that, when i click the hyperlink, it randoms the second set first before calling the php function thus updating the totalCount of the second set, instead of the other way round.Is there any solutions besides using ajax? Guess it's the way how i call the php function using the hyperlink. Thanks in advance. <body><div id="page-wrapper"> <div id="header"> <div class="header-content"> <?php function updateCount1($id) { mysql_query("UPDATE tblUser SET totalCount = totalCount + 1 WHERE userID = '" . $id . "'"); } //end of updateCount1 function updateCount2($id2) { mysql_query("UPDATE tblUser SET totalCount = totalCount + 1 WHERE userID = '" . $id2 . "'"); } //end of updateCount2 //random question $randQuestion = rand(1,6); mysql_connect("localhost","root",""); mysql_select_db("game"); $resultQuestion = mysql_query("SELECT * FROM tblQuestion WHERE questionIDQS = '" . $randQuestion . "'"); while ($row = mysql_fetch_assoc($resultQuestion)) { $question = $row['question']; }?> <h1><?php echo $question; ?></h1> </div> </div> <div id="content"> <div class="content-left"><a href="index.php?run=first"><img src="images/pick_left.png" width="167" height="74" alt="Pick me!" /></a></div> <div class="content-mid"> <?php //random first person $randUser = rand(1,6); $captureID1 = $randUser; $resultUser = mysql_query("SELECT * FROM tblUser WHERE userID = '" . $randUser . "'"); while ($row = mysql_fetch_assoc($resultUser)) { $name = $row['name']; } ?> <div class="profilepic-left"><?php echo $name; ?></div> <?php //random second person $randUser = rand(1,6); $captureID2 = $randUser; //check for duplicates while ($captureID1 == $captureID2) { $randUser = rand(1,6); $captureID2 = $randUser; } $resultUser = mysql_query("SELECT * FROM tblUser WHERE userID = '" . $randUser . "'"); while ($row = mysql_fetch_assoc($resultUser)) { $name = $row['name']; } ?> <div class="profilepic-right"><?php echo $name; ?></div> </div> <?php //runs update function if (isset($_GET['run'])){ $linkchoice=$_GET['run']; } else $linkchoice=''; switch ($linkchoice) { case 'first': updateCount1($captureID1); break; case 'second': updateCount2($captureID2); break; default : echo 'no run'; } ?> <div class="content-right"><a href="index.php?run=second"><img src="images/pick_right.png" width="166" height="74" alt="Pick me!" /></a></div> </div> <br class="clear" /></div></body>
  2. Thank you! Sorry. I didn't post the calling function cause i thought it wouldn't be of much help. Anyhow, thank you so much for your much appreciated help
  3. I'm so sorry for disturbing. But this really means a lot to me. The value in $randUser is the same as $captureID1. I CAN echo $captureID1 and $randUser. But when i put either variables into the update mysql query, it didn't update it. It does update though when i put any number. Any idea why? Thank you!<?php //random first person $randUser = rand(1,6); $resultUser = mysql_query("SELECT * FROM tblUser WHERE userID = '" . $randUser . "'"); while ($row = mysql_fetch_assoc($resultUser)) { $name = $row['name']; } $captureID1 = $randUser; function updateCount1() { mysql_query("UPDATE tblUser SET totalCount = totalCount + 1 WHERE userID = '" . $captureID1 . "'"); } //end of updateCount1 ?> <div class="profilepic-left"><?php echo $captureID1; ?></div>
  4. Thank you ingolme! Although i still couldn't find the problem. I decided to do this instead since it prints out the same thing.$captureID1 = $randUser
  5. Ingolme, I'm not really sure what you meant. I tried printing $userID the same way i did for $name. It works for $name but not for $userID. $userID shows nothing.thescientist, the code to connect to the database? I managed to print $name so there shouldn't be any problem with the connection to the database right? Correct me if i'm wrong.This is how i tried printing the variable. <div class="profilepic-right"><?php echo $name; ?></div>Yes it does display $name. But if i replaced it with $userID, it displays nothing. Thank you for any further help.
  6. Yes thank you for that. But it still doesn't work. I guess the way i call the function works. But not the function itself. In the following codes, I'm able to print out $name. But not $userID. Is there a reason why? FYI userID is the primary key in tblUser.<?php //random first person $randUser = rand(1,6); $resultUser = mysql_query("SELECT * FROM tblUser WHERE userID = '" . $randUser . "'"); while ($row = mysql_fetch_assoc($resultUser)) { $userID = $row['userID']; //$image = $row['image']; $name = $row['name']; } //$captureID1 = $userID;?>
  7. Thank you, the scientist. Don't mind me asking another. I'm trying to get a hyperlink to call a php function. Is this the way to do it? I tested and it printed out 'no run'.<?phpfunction updateCount1(){mysql_query("UPDATE tblUser SET totalCount = totalCount + 1" . "WHERE userID = '" . $captureID1 . "'");echo $captureID1;} //end of updateCount1//random first person$randUser = rand(1,6);$resultUser = mysql_query("SELECT * FROM tblUser WHERE userID = '" . $randUser . "'");while ($row = mysql_fetch_assoc($resultUser)){$userID = $row['userID'];//$image = $row['image'];$name = $row['name'];}$captureID1 = $userID;if (isset($_GET['run'])) $linkchoice=$_GET['run'];else $linkchoice='';switch ($linkchoice){case 'first':updateCount1();break;case 'second':updateCount2();break;default :echo 'no run';}?><a href="?run=updateCount1">
  8. Code:<?php $resultName = mysql_query("SELECT name FROM tblUser ORDER BY totalCount DESC"); while($name = mysql_fetch_array($resultName)){ echo $name['name']; } ?>Hi. As you can see, I'm trying to get 'name' by order of totalCount DESC into variable $resultName. What my codes does is that it echoes out all the names. What i want to do is to echo the first value of name which has the highest totalCount. Then echo second value which has the second highest totalCount. and so on. Any help would be greatly appreciated. Thanks in advance.
×
×
  • Create New...