Jump to content

user records doesnt actualize everywhere


alexandre

Recommended Posts

for some reason, the user info example balance doesnt get updated for other pages until the user actually goes on the page of the script. i would like it to be automatic as when there is an update done the users info gets updated everywhere because if i was doing this way, the users who didnt claimed by going on the actual script page before the timer goes back on would lose what they sent since i have to drop the table and generate a new one after every end of a timer.  .if anyone have an idea ofwhat i could do to fix this i would appreciate thank you.

Edited by alexandre
Link to comment
Share on other sites

web servers are stateless. they don't know or care about anything outside of the current http request they are servicing. any data submitted to a page or any result calculated on a page, unless persistently stored in a common accessible location, e.g. a database, file, common memory cache,... doesn't exist once the server-side code on any page ends.

you are making an application where there are x winners calculated at some interval or on some set of submissions. you must persistently store the result of each 'round' so that anyone visiting the 'result' page(s) can view the results.

Link to comment
Share on other sites

13 hours ago, maxxd said:

I'm curious as to why you have to drop a table and recreate it after each round. Explain that, please - it smells off.

in order to restart a new round from zero i judged that it was the easiest way to do so since this table isnt vital so it could only be  representing a single round.

Link to comment
Share on other sites

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
	header('Location: index.html');
	exit;
}
include 'countdown-timer.php';
include './includes/connect_db2.php';
if ($rem = array_filter($remain)) {
		foreach ($rem as $k => $v) {
				if ($v > 0)  {
					$donationclash = true;
				}
		}
}
else {
		$donationclash = false;
}
if ($donationclash == true) {
$donationclashcompleted = false;


echo "<p class='p2'>the total pifcoin collected for thi week</p>";
				 $stmt = 'SELECT totalpifcoincollected, sum(totalpifcoincollected) as totalpifcoincollected FROM donationclashdetails';
				 $collected = mysqli_query($con, $stmt);
				 if (mysqli_num_rows($collected) > 0) {
						while ($COLLECTED_ROW = mysqli_fetch_assoc($collected)) {
							echo "<div class='rankingtrue'>
							<table class='rankingtable'>
									<tr>
											<td>total collected</td
									</tr>
									<tr>
											<td class='remain2'>" . $COLLECTED_ROW['totalpifcoincollected']. "</td>
									</tr>
							</table>
						 </div>";
}}

$stmt = "SELECT totalparticipant, sum(totalparticipant) as totalparticipant FROM donationclashdetails";
 $num_participant = mysqli_query($con, $stmt);
 if (mysqli_num_rows($num_participant) > 0) {
		 while ($num_row = mysqli_fetch_assoc($num_participant)) {
    echo "<div class='participant_num2'><p class='participant_num'>Total number of participants: " . $num_row['totalparticipant'] . '</p></div>';
}}
	$stmt = 'SELECT DISTINCT participationid, usernames, donationamount, totaldonated FROM donationclashdetails GROUP BY participationid ORDER BY totaldonated DESC';
	$result = mysqli_query($con, $stmt);
	if ((mysqli_num_rows($result) > 0) && mysqli_num_rows($result) < 100 ) {
	    while ($result_row = mysqli_fetch_assoc($result)) {
	        echo "<div class='rankingtrue'>
					<table class='rankingtable'>
	            <tr>
	                <td>Id</td><td>username</td><td>last donation</td><td>total donated</td>
	            </tr>
	            <tr>
	                <td class='remain2'>" . $result_row['participationid']. "</td>
	                <td class='remain2'>" . $result_row['usernames']. "</td>
	                <td class='remain2'>" . $result_row['donationamount']. "</td>
	                <td class='remain2'>" . $result_row['totaldonated']. "</td>
	            </tr>
	        </table>
				 </div>";
}
}
}
else if ($donationclash == false) {
	$donationclashcompleted = true;
}
if ($donationclashcompleted == true) {

$stmt = "SELECT totalparticipant, sum(totalparticipant) as totalparticipant FROM donationclashdetails";
 $num_participant = mysqli_query($con, $stmt);
 if (mysqli_num_rows($num_participant) > 0) {
		 while ($num_row = mysqli_fetch_assoc($num_participant)) {
    echo "<div class='participe'><p class='participant_num'>Total number of participants: " . $num_row['totalparticipant'] . '</p></div>';
		$participant_num = $num_row['totalparticipant'];
}}
if ($participant_num < 10) {
	$num_winners3 = 1;
}
else {
$num_winners3 = $participant_num * 10;
$num_winners3 = $num_winners3 / 100;
$num_winners3 = intval($num_winners3);
}
						 $stmt = 'SELECT totalpifcoincollected, sum(totalpifcoincollected) as totalpifcoincollected FROM donationclashdetails';
						 $collected = mysqli_query($con, $stmt);
						 if (mysqli_num_rows($collected) > 0) {
						 		while ($COLLECTED_ROW = mysqli_fetch_assoc($collected)) {
									echo "<div class='rankingtrue'>
									<table class='rankingtable'>
											<tr>
													<td>total Pifcoin collected</td
											</tr>
											<tr>
													<td class='remain2'>" . $COLLECTED_ROW['totalpifcoincollected']. "</td>
											</tr>
									</table>
								 </div><br>";
$winners_amount = intval($COLLECTED_ROW['totalpifcoincollected']);
}}
$stmt = 'SELECT DISTINCT participationid, usernames, totaldonated FROM donationclashdetails GROUP BY participationid ORDER BY totaldonated DESC';
$WINNERS_ = mysqli_query($con, $stmt);
if (mysqli_num_rows($WINNERS_) > 0 ) {
    while ($WINNERS_ROW = mysqli_fetch_assoc($WINNERS_)) {
        echo "<div class='rankingtrue'>
				<table class='rankingtable'>
						<tr>
								<td>Id</td><td>username</td><td>total donated</td>
						</tr>
						<tr>
								<td class='remain2'>".  $WINNERS_ROW['participationid']. "</td>
								<td class='remain2'>". $WINNERS_ROW['usernames']. "</td>
								<td class='remain2'>". $WINNERS_ROW['totaldonated']. "</td>
						</tr>
				</table>
			 </div>";
			 $WINNERSID[] = intval($WINNERS_ROW['participationid']);
}
}
$stmt = $con->prepare("SELECT funds_collected, foundation_funds FROM foundationsfunds");
$stmt->execute();
$stmt->bind_result($funds_collected, $foundations_funds);
$stmt->fetch();
$stmt->close();
$prizeamount = $winners_amount;
		$prizeamount = $prizeamount * 65;
		$prizeamount = $prizeamount / 100;
		$remaining_funds = $winners_amount * 35;
		$remaining_funds = $remaining_funds / 100;
		$foundations_funds = $foundations_funds + $remaining_funds;
		if (($donationclashcompleted == true) && $funds_collected == 0) {
			$funds_collected = 1;
		$stmt = $con->prepare("UPDATE foundationsfunds SET funds_collected = ?, foundation_funds = ?");
		$stmt->bind_param('di', $funds_collected , $foundations_funds);
		$stmt->execute();
	}
			$WINNERSAMOUNT = $prizeamount / intval($num_winners3);
		$stmt = $con->prepare("SELECT prizepaid FROM donationclashdetails WHERE participationid = ?");
	  $stmt->bind_param('i', $_SESSION['id']);
		$stmt->execute();
		$stmt->bind_result($prizepaid);
		$stmt->fetch();
		$stmt->close();
$winners1[] = array_slice($WINNERSID, 0, $num_winners3);
if ($winners = array_filter($winners1)) {
	foreach ($winners as $value) {
						if (in_array($_SESSION['id'], $value) && $prizepaid == false)  {
		  $stmt = $con->prepare("SELECT userbalance, totalpifcoingained, userlevel, userexperience FROM accounts WHERE id = ?");
	 $stmt->bind_param('i', $_SESSION['id']);
	 	$stmt->execute();
	 	$stmt->bind_result($userbalance, $totalpifcoingained, $userlevel, $userexperience);
	   $stmt->fetch();
	 	$stmt->close();
		$userxp = 2500;
$userexperience = $userexperience + $userxp;
if ($userexperience >= 50000) {
 $userlevel++;
 $userexperience = $userexperience - 50000;
	$userbalance = $userbalance + 100;
}
     $userbalance = $userbalance + $WINNERSAMOUNT;
		 $totalpifcoingained = $totalpifcoingained + $WINNERSAMOUNT;
		 $stmt = $con->prepare("UPDATE accounts SET userbalance = ?, totalpifcoingained = ?, userlevel = ?, userexperience = ? WHERE id = ?");
		 $stmt->bind_param('ddidi',$userbalance, $totalpifcoingained, $userlevel, $userexperience, $_SESSION['id']);
		 $stmt->execute();
		      echo "<p class='congrats'>congratulation to all the winners of this week  the top 10% of this week each gained: " . $WINNERSAMOUNT . " pifcoin, thank you for taking part in the donation wheel. i hope you enjoyed
		 		 paying it forward as much as i did. have an amazing time and get ready for next round. hihihi</p><br>";
 $prizepaid = true;
				 $stmt = $con->prepare("UPDATE donationclashdetails SET prizepaid = ? WHERE participationid = ?");
				 $stmt->bind_param('ii',$prizepaid, $_SESSION['id']);
				 $stmt->execute();
				 exit;
	 }
elseif (!in_array($_SESSION['id'], $value))  {
	echo "<p class='psorry'>sorry better chance next round, for this week there is " . $num_winners3 . " winners, each have gained: " . $WINNERSAMOUNT .' pifcoin</p>';
	exit;
}
else if (in_array($_SESSION['id'], $value) && $prizepaid == true) {
	$num_winners4 = $num_winners3 - 1;
	echo "<p class='already_claimed'>for this week you and " . $num_winners4 . " others, each have gained: " . $WINNERSAMOUNT .'</p>';
	exit;
}}}}
?>
	<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" href="donation-clash.css" type="text/css">
	</head>
	<body>
	</body>
	</html>
18 hours ago, mac_gyver said:

web servers are stateless. they don't know or care about anything outside of the current http request they are servicing. any data submitted to a page or any result calculated on a page, unless persistently stored in a common accessible location, e.g. a database, file, common memory cache,... doesn't exist once the server-side code on any page ends.

you are making an application where there are x winners calculated at some interval or on some set of submissions. you must persistently store the result of each 'round' so that anyone visiting the 'result' page(s) can view the results.

by that i guess you mean kind of the same as my ranking page right? like where the result of the "game" is appearing. this is all in place and this is the actual page they have to visit in order to claim the reward, 

Edited by alexandre
Link to comment
Share on other sites

Do you not keep historical data? If not, how do you track and/or display past rounds, settle any disputes over past rounds that may arise, or make decisions about the future architecture based on past demand and performance?

I may be misunderstanding what you're saying but if I'm not it sounds to me like cutting off your nose to spite your face, hence my comment about the smell.

Link to comment
Share on other sites

the data that needs to be kept is kept and the rest for what it is of the table this is a simple registration to the event so once the event is done i have to drop the table to put everything to zero and start the event back . and maxx you better stop answering me with your attitude like if you know everything and just keep judging my way of proceeding. in fact you can pass your way i dont need your help 

Link to comment
Share on other sites

10 hours ago, ginerjm said:

Could you use some punctuation when you write English.  It is very difficult to read what appears to be a run-on sentence when you post.  It might also help all of us who you are asking for help to understand you better.  

i will try but if you have a complaint , you might have to tell all the cellphones companies who have made us dumber and dumber by trying to always facilitate every aspect of our lifes, when you have an application correcting you always you dont learn anymore by correcting your errors and soon you know nothing.

i didnt finish what is for you highschool and i try to learn as i can. but punctuations are like a dark beast for me i never know where to put them so i just end up writing a text in one and single sentence.. this is more happening on my pc since i am not using any correctors. but anyways i am not planning on posting much anymore. i am exposing my weakness to everyone and i am scared now xD

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.