Jump to content
  • 0
fictionx

Creating MvP Cards Ranking

Question

Hi, i wondering if someone can help me to fix the following code that i have from php.


The problem that i have, it's that isn't counting the total card in the server, always stated in null valor.

image.thumb.png.9bede79a82576ecd155bc7fe5efcd6e2.png

Spoiler
<?php
$data = $CACHE->get('MVPCard', FALSE, 1440);
$total = array();
if (!$data )
{
	$total = array();
	foreach( $GV->Global_MVPCard as $val )
	{

		$consult = 
		"
			SELECT 
				SUM(`INVENTARIO`+`CARRO`+`ALMACEN`+`RENTAALMACEN`+`GUILDSTORAGE`) AS `total` 
				FROM ( 
					SELECT (
						SELECT IFNULL(SUM(`amount`),0) 
						FROM `inventory` 
						WHERE `nameid` = ? OR `card1` = ?
					) AS `INVENTARIO`, 
					(
						SELECT IFNULL(SUM(`amount`),0) 
						FROM `cart_inventory` 
						WHERE `nameid` = ? OR `card1` = ?
					) AS `CARRO`, 
					(
						SELECT IFNULL(SUM(`amount`),0) 
						FROM `storage` 
						WHERE `nameid` = ? OR `card1` = ?
					) AS `ALMACEN`, 
					(
						SELECT IFNULL(SUM(`amount`),0) 
						FROM `rentstorage` 
						WHERE `nameid` = ? OR `card1` = ?
					) AS `RENTAALMACEN`, 
					(
						SELECT IFNULL(SUM(`amount`),0) 
						FROM `guild_storage` 
						WHERE `nameid` = ? OR `card1` = ?
					) AS `GUILDSTORAGE`) 
				AS T 
		";
		$filled_array = array_fill(0,10, $val[0]);
		$result = $DB->execute($consult, $filled_array);
		$row = $result->fetch();
		$DB->free($result);
		array_push($total, [
			'id'	=>	$val[0], 
			'total'	=>	$row['total']
		]);
	}
	$CACHE->put('MVPCard', $total);
	$data = $CACHE->get('MVPCard', FALSE, 1440);
}

echo '
	<div class="row">
		<h4 class="oboro_h4"><i class="fa fa-bar-chart fa-2x" style="vertical-align: middle;"> </i> <span> Cartas MvP en el Servidor</span></h4>
		<div class="text-align-center">¡Esta información es actualizada todo los días!</div>
		
';
foreach($data as $arr)
{
	echo "
		<div class='col-lg-2'>
			<img class='oboro_mvpimg' src=\"./images/mvpcards/".$arr["id"].".jpg\">
			<div><b>Cantidad</b>: ".$arr["total"]." Cartas</div>
		</div>
	";
}
echo "</div>";
?>

 

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

You did not mention the results of any previously made troubleshooting attempts.
More information is required to resolve this issue.

I have compressed the PHP source code snippet to better explain my claim:

$data = $CACHE->get('MVPCard', FALSE, 1440);
$total = array();

if (!$data ) {
	$total = array();
	foreach( $GV->Global_MVPCard as $val ) {
		$consult = "{{SELECT_STATEMENT}}";
		$filled_array = array_fill(0,10, $val[0]);
		$result = $DB->execute($consult, $filled_array);
		$row = $result->fetch();
		$DB->free($result);
		array_push($total, [
			'id'	=>	$val[0], 
			'total'	=>	$row['total']
		]);
	}
	$CACHE->put('MVPCard', $total);
	$data = $CACHE->get('MVPCard', FALSE, 1440);
}

 

I recommend that you isolate and double-check the return values for each of the following:

 - Line 1: "$data = $CACHE->get('MVPCard', FALSE, 1440);"
    Cached data might contain NULL values.

 - Line 6: "foreach( $GV->Global_MVPCard as $val ) {"
    Does $GV->Global_MVPCard contain the expected values?

 - Line 10: "$row = $result->fetch();"
    Is the MySQL query fetching NULL values from the database?

Running the PHP source code snippet through a PHP Syntax Checker returned no errors.
I would consider the presence of a Logic Error or missing data entries.

Edited by WooZy
Corrected Line 1 statement
Link to comment
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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

By using this site, you agree to our Terms of Use and Privacy Policy.