Jump to content

Recommended Posts

$stmt = 'SELECT DISTINCT participationid, usernames, totaldonated FROM donationclashdetails GROUP BY participationid ORDER BY totaldonated DESC';
$final = mysqli_query($con, $stmt);
if ((mysqli_num_rows($final) > 0) && mysqli_num_rows($final) <= intval($num_winners3)) {
		while ($FINALROW = mysqli_fetch_assoc($final)) {
				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'>". $FINALROW['participationid']. "</td>
								<td class='remain2'>". $FINALROW['usernames']. "</td>
								<td class='remain2'>". $FINALROW['totaldonated']. "</td>
						</tr>
				</table>";
			 '</div>';
			 $WINNERS[] = intval($FINALROW['participationid']);//i need to get this WINNERS array defined for lower
			  var_dump($WINNERS);
		 }}
$prizeamount = $winners_amount;
		$prizeamount = $prizeamount * 65;
		$prizeamount = $prizeamount / 100;
		$remaining_funds = $winners_amount * 35;
		$remaining_funds = $remaining_funds / 100;
		$stmt = $con->prepare("UPDATE foundationsfunds SET foundation_funds = ?");
		$stmt->bind_param('d', $remaining_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();
if (in_array(intval($_SESSION['id']), $WINNERS) && $prizepaid == false) { // here is where it is used
		  $stmt = $con->prepare("SELECT userbalance, totalpifcoingained, userlevel, userexperience FROM accounts WHERE id = ?");
	   // In this case we can use the account ID to get the account info.
	 	$stmt->execute([ $_SESSION['id'] ]);
	 	$stmt->bind_result($userbalance, $totalpifcoingained, $userlevel, $userexperience);
	   $stmt->fetch();
	 	$stmt->close();

for some reason the array is not getting populated or i am handeling the data in the wrong way, this is just strange because its not even showing anything on the var_dump() this is the last step of my script if anyone can help me it would be great .

 

Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in C:\xampp\htdocs\container\donation-clash\donationclashhome.php:141 Stack trace: #0 C:\xampp\htdocs\container\donation-clash\donationclashhome.php(141): in_array(35, NULL) #1 {main} thrown in

this is the only error i get apart of the undefined variable itself

Edited by alexandre
Link to comment
https://forums.phpfreaks.com/topic/315364-trying-to-get-an-array-defined/
Share on other sites

sorry i didnt see that there was a reply. but i just fixed it by doing this 

 $WINNERSID[] = intval($WINNERS_ROW['participationid']);
$winners1[] = array_slice($WINNERSID, 0, $num_winners3);
if ($winners = array_filter($winners1)) {
	foreach ($winners as $value) {
						if (in_array($_SESSION['id'], $value) && $prizepaid == false)  {

 

On 9/24/2022 at 9:48 AM, alexandre said:
SELECT DISTINCT participationid, usernames, totaldonated FROM donationclashdetails GROUP BY participationid ORDER BY totaldonated DESC

I would suggest taking another look (or two) at this query.  

"select distinct" - This is big Red Flag for me. 
I usually see this used as a "sticking plaster" over a bad query that is "somehow" getting "duplicate" records, but "distinct" makes them go away.  It can be a hugely expensive operation for the database to go through all the values to be returned and prune out those "duplicates", which are most often caused by incorrect table joins.  

"select a, b, c group by a" - Most DBMSs will simply throw an error at this. 
Exactly which value of b and c would you expect the query to return for each "grouped by" value of a?  You haven't told the database how to work out those values (using Aggregate Functions, like max() & min()).  MySQL will hand you any old value it happens to find and that could change every time you run the query. 
Other, more sensible, DBMSs can tell that they can't work this out for themselves and throw an error instead.  

You can (and, I would suggest, probably should) configure MySQL to work in the same, definitive fashion. 

I'd expect to see something more like: 

select 
  participationid
, group_concat( usernames ) unames 
, sum( totaldonated ) ttl 
group by participationid 
order by 3 desc ; 

Regards, 
   Phill  W. 

14 hours ago, Phi11W said:

I would suggest taking another look (or two) at this query.  

"select distinct" - This is big Red Flag for me. 
I usually see this used as a "sticking plaster" over a bad query that is "somehow" getting "duplicate" records, but "distinct" makes them go away.  It can be a hugely expensive operation for the database to go through all the values to be returned and prune out those "duplicates", which are most often caused by incorrect table joins.  

"select a, b, c group by a" - Most DBMSs will simply throw an error at this. 
Exactly which value of b and c would you expect the query to return for each "grouped by" value of a?  You haven't told the database how to work out those values (using Aggregate Functions, like max() & min()).  MySQL will hand you any old value it happens to find and that could change every time you run the query. 
Other, more sensible, DBMSs can tell that they can't work this out for themselves and throw an error instead.  

You can (and, I would suggest, probably should) configure MySQL to work in the same, definitive fashion. 

I'd expect to see something more like: 

select 
  participationid
, group_concat( usernames ) unames 
, sum( totaldonated ) ttl 
group by participationid 
order by 3 desc ; 

Regards, 
   Phill  W. 

in fact it have the behavior that i was looking for because it makes me able to use those duplicates to calculate other things that i need it for. and also there is no way simpler for me to use variables to select a number of rows from the database.

Edited by alexandre

i dont know if there will be errors for users using my website but for me i have finished the script is working perfectly on my side except the fact that i still dont understand why the user actually have to go on the script page to get their reward or else their balance wont get updated even if they refresh, it doesnt change.. i feel like it is simply php that is not dynamic at the point of making things automatic.

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.