Hello,
On my way down a long road to develop a web form for a local sports league.
Upon form submission, on my process.php page, I am trying to tally up each of the player's highlights throughout the match form.

http://radmedia.org/EWMSa.jpg

Right now I have code which works, but I am only comparing the first HOME id field to the 31 other fields (32 fields of player/id and highlightsplayerH1, highlightsplayerH2, highlightsplayerH3 etc..)

I still have VISITORS to do also with a similar naming convention highlightsplayerV1, highlightsplayerV2 etc..

Here is my code so far: I know there is an easier way to step through these...

$ph1 = '';
if (isset($highlightsplayerH1)) {
	$ph1 = $playerH1." - ".$highlightsplayerH1;
} else {}

if ($playerH1 == $playerH11 && isset($highlightsplayerH11)) {
	$ph1 = $ph1.", ".$highlightsplayerH11;
} else {}

if ($playerH1 == $playerH12 && isset($highlightsplayerH12)) {
	$ph1 = $ph1.", ".$highlightsplayerH12;
} else {}

if ($playerH1 == $playerH13 && isset($highlightsplayerH13)) {
	$ph1 = $ph1.", ".$highlightsplayerH13;
} else {}

if ($playerH1 == $playerH14 && isset($highlightsplayerH14)) {
	$ph1 = $ph1.", ".$highlightsplayerH14;
} else {}

if ($playerH1 == $playerH15 && isset($highlightsplayerH15)) {
	$ph1 = $ph1.", ".$highlightsplayerH15;
} else {}

if ($playerH1 == $playerH16 && isset($highlightsplayerH16)) {
	$ph1 = $ph1.", ".$highlightsplayerH16;
} else {}

if ($playerH1 == $playerH17 && isset($highlightsplayerH17)) {
	$ph1 = $ph1.", ".$highlightsplayerH17;
} else {}

if ($playerH1 == $playerH18 && isset($highlightsplayerH18)) {
	$ph1 = $ph1.", ".$highlightsplayerH18;
} else {}

if ($playerH1 == $playerH19 && isset($highlightsplayerH19)) {
	$ph1 = $ph1.", ".$highlightsplayerH19;
} else {}

if ($playerH1 == $playerH20 && isset($highlightsplayerH20)) {
	$ph1 = $ph1.", ".$highlightsplayerH20;
} else {}

if ($playerH1 == $playerH21 && isset($highlightsplayerH21)) {
	$ph1 = $ph1.", ".$highlightsplayerH21;
} else {}

if ($playerH1 == $playerH22 && isset($highlightsplayerH22)) {
	$ph1 = $ph1.", ".$highlightsplayerH22;
} else {}

if ($playerH1 == $playerH23 && isset($highlightsplayerH23)) {
	$ph1 = $ph1.", ".$highlightsplayerH23;
} else {}

if ($playerH1 == $playerH24 && isset($highlightsplayerH24)) {
	$ph1 = $ph1.", ".$highlightsplayerH24;
} else {}

if ($playerH1 == $playerH25 && isset($highlightsplayerH25)) {
	$ph1 = $ph1.", ".$highlightsplayerH25;
} else {}

if ($playerH1 == $playerH26 && isset($highlightsplayerH26)) {
	$ph1 = $ph1.", ".$highlightsplayerH26;
} else {}

if ($playerH1 == $playerH27 && isset($highlightsplayerH27)) {
	$ph1 = $ph1.", ".$highlightsplayerH27;
} else {}

if ($playerH1 == $playerH28 && isset($highlightsplayerH28)) {
	$ph1 = $ph1.", ".$highlightsplayerH28;
} else {}

if ($playerH1 == $playerH29 && isset($highlightsplayerH29)) {
	$ph1 = $ph1.", ".$highlightsplayerH29;
} else {}

if ($playerH1 == $playerH30 && isset($highlightsplayerH30)) {
	$ph1 = $ph1.", ".$highlightsplayerH30;
} else {}

if ($playerH1 == $playerH31 && isset($highlightsplayerH31)) {
	$ph1 = $ph1.", ".$highlightsplayerH31;
} else {}

if ($playerH1 == $playerH32 && isset($highlightsplayerH32)) {
	$ph1 = $ph1.", ".$highlightsplayerH32;
} else {}

$ph1Array = explode(",",$ph1);
$ph1Count = count($ph1Array);
echo "Itemized Highlights<br />";
echo $ph1." Wow, you shot ".$ph1Count." highlights!<br />";

Here the output in Firefox...

http://radmedia.org/EWMSb.jpg

The variable $playerH1 or V1 (up to 32) all contain the players ID.
So I would like to compare and list (once) the ID and all the highlights associated with that ID.

I was working on some sort of loop code to handle this but I must admit I am not an expert.

$i = 0;
	/* phht = Player Home Highlight Total */
	$phht = '';
	while ($i<=32){
	  $i++;
		if ($playerH1 == ($playerH.$i)) {
			$phht = $playerhighlightsH.$i;
			echo $phht;
			echo "<br />";
		} else {
		echo $phht." "."There were no highlights for the Home team this week.<br>";
	}
}

Ok, I spotted a large error.. misspelling argh..

$i = 0;
	/* phht = Player Home Highlight Total */
	$phht = '';
	while ($i<=32){
	  $i++;
		if ($playerH1 == ($playerH.$i)) {
			$phht = $highlightsplayerH.$i;
			echo $phht."<br />";
		} else {
		//echo $phht." "."There were no highlights for the Home team this week.<br>";
	}
}

Anyone, what am I doing wrong? I am not getting an error, but it does not even compare/write playerH1 highlights. I am stumped.

I see why its not working now, but clueless as to a solution..
I think when I try and echo $playerH.$i it does not show as one variable.. but 2.
so it echos:
[nothing]1
[nothing]2
[nothing]3 etc..
because $PlayerH is not defined and $playerH + 1 is not coming back as playerH1.

Why?? Clues?

Member Avatar for diafol

THat looks really complicated - you probably could get better results with an array variable for players add loops.

Also you build a string and then break it up again ($ph1) - I can't see the point of that as you build with a ',' and explode on it as well.

Could you please show me a brief example of building a var for players add loops?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.