/    Sign up×
Community /Pin to ProfileBookmark

Why is the scrip telling me the veriable is an array?

Hi

Me again not to good with php as you may have noticed.

Here is part of my code:

[CODE]
#################################
# Getting Hi Score #
#################################
$i = 0;
while($i < 16){
$New=”SELECT * FROM playerstats WHERE id_Player=’$id_player[$i]’ ORDER BY Hi_Score DESC”;
$result = mysql_query($New);
$nom = mysql_num_rows($result);
$HiScore=0;
if ($nom != 0) {
$HiScore = mysql_result($result,0,”Hi_Score”);
}
if ($Score > $HiScore){
$HiScore = $Score;
}
echo $HiScore . “<br>”;

$i++;

if($id_player[$i] == “”){
$i = 100;
}
}

[/CODE]

Now my problem is that [B][I]$HiScore [/I][/B]is never defined as an array. [B][I]($id_player[] is an array)[/I][/B] If I echo [B][I]$HiScore [/I][/B]before the [B][I]If() [/I][/B]statments or even in the [B][I]If() [/I][/B]statments [B][I]{}[/I][/B]it gives me a value. But when I echo it after the [B][I]If() [/I][/B]statment it prints the word [B][I]ARRAY[/I][/B] meaning thet [B][I]$HiScore [/I][/B]is an array. How is this possible ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MrCoderFeb 01.2007 — [code=php]$HiScore = $Score;[/code]

What is $Score?
Copy linkTweet thisAlerts:
@NightShift58Feb 01.2007 — $Score comes from a POST, in which form it is defined as $Score[], which converts to an array.

Somewhere in the script prior to this point, there is an instruction which says $Score = $_POST['Score'] and from that point on, we're doomed...
Copy linkTweet thisAlerts:
@gogelpotauthorFeb 02.2007 — Found the problem.

$HiScore = $Score; should be $HiScore = $Score[$i];

without [$i] key php sets the $HiScore to an array with the same values as the array $Score;

But thanks for your intrest and help, I will need it in future again.
×

Success!

Help @gogelpot spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...