Jump to content

Archived

This topic is now archived and is closed to further replies.

CHZilm

Array Trouble

Recommended Posts

Still fairly new to PHP but in all honesty I have no clue what is casing my problems. Heres the code.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php
$getjob = $_POST["job"];
$getzone = $_POST["zone"];
$getglass = $_POST["glass"];
$getslot = $_POST["slot"];

if($getjob == "" || $getslot == "" || $getglass == "" || $getslot == "")
break;

$zone[0] = "San dOria";
$zone[1] = "Bastok";
$zone[2] = "Windurst";
$zone[3] = "Jeuno";
$zone[4] = "Beucerdine";
$zone[5] = "Xarcabard";
$zone[6] = "Valkurm";
$zone[7] = "Buburimu";
$zone[8] = "Qufim";
$zone[9] = "Tavnazia";

$num_Zones = 10;

$glass[0] = "Davoi";
$glass[1] = "Beadeaux";
$glass[2] = "Oztraja";

$num_Glasses = 3;

$job[0] = "WAR";
$job[1] = "MNK";
$job[2] = "WHM";
$job[3] = "BLM";
$job[4] = "RDM";
$job[5] = "THF";
$job[6] = "PLD";
$job[7] = "DRK";
$job[8] = "BST";
$job[9] = "BRD";
$job[10] = "RNG";
$job[11] = "SAM";
$job[12] = "NIN";
$job[13] = "DRG";
$job[14] = "SMN";
$job[15] = "BLU";
$job[16] = "COR";
$job[17] = "PUP";

$num_Jobs = 18;

$slot[0] = "Head";
$slot[1] = "Body";
$slot[2] = "Hand";
$slot[3] = "Legs";
$slot[4] = "Feet";
$slot[5] = "Accs";

$num_Slots = "6";

$zone_start = 0;
$glass_start = 0;
$job_start = 0;
$slot_start = 0;

//Setup Variables If not "Any"
if($getzone != "Any")
{
$x = $num_Zones - 1;

while($zone[$x] != $getzone)
{
$x = $x - 1;
}
$num_Zones = 1;
$zone_start = $x;
}

if($getglass != "Any")
{
$x = $num_Glasses - 1;

while($glass[$x] != $getglass)
{
$x = $x - 1;
}
$num_Glasses = 1;
$glass_start = $x;
}

if($getjob != "Any")
{
$x = $num_Jobs - 1;

while($job[$x] != $getjob)
{
$x = $x - 1;
}
$num_Jobs = 1;
$job_start = $x;
}

if($getslot != "Any")
{
$x = $num_Slots - 1;

while($slot[$x] != $getslot)
{
$x = $x - 1;
}
$num_Slots = 1;
$slot_start = $x;
}
$conn = mysql_connect("localhost", "thelogin", "thepass");

mysql_select_db("thedb", $conn);

//Start Looping to make the tables.

for($g = 0; $g < $num_Glasses; $g++)
{
$gindex = $glass_start + $g;
$gwant = $glass[$gindex];

echo "<table border=0 cellpadding=4 width = 25%>";
echo "<tr><td><h1>";
echo "$gwant";
echo "</h1></td></tr></table>";
//setup Rows for zones leaving first cell blank
$width = 9 + ( 9 * $num_Zones);
echo "<table border=1 cellpadding=4 width = $width%><tr><td width = 9%></td>";
for($z = 0; $z < $num_Zones; $z++)
{
$zindex = $zone_start + $z;
$zwant = $zone[$zindex];
echo "<td width = 9%>$zwant</td>";
}
echo "</tr>";

/**
* Print the job in the first box. Then in each next box print how many occurences in that zone/job/glass combo
*/
for($j = 0; $j < $num_Jobs; $j++)
{
$jindex = $job_start + $j;
$jwant = $job[$jindex];
echo "<tr><td width = 9%>$jwant</td>";

for($zo = 0; $zo < $num_Zones; $zo++)
{
$zoindex = $zone_start + $zo;
$total = 0;
if($getslot != "Any")
{
for($s = 0; $s < $num_Slots; $s++)
{
$sindex = $slot_start + $s;
$sql = "SELECT COUNT(id) FROM dynamisarmor WHERE zone = '$zone[$zoindex]' && glass = '$glass[$gindex]' && job = '$job[$jindex]' && slot = '$slot[$sindex]'";

$result = mysql_query($sql, $conn);
$newarray = mysql_fetch_array($result);
$drops = $newarray["COUNT(id)"];
$total += $drops;
}
}
else
{
$sql = "SELECT COUNT(id) FROM dynamisarmor WHERE zone = '$zone[$zoindex]' && glass = '$glass[$gindex]' && job = '$job[$jindex]'";

$result = mysql_query($sql, $conn);
$newarray = mysql_fetch_array($result);
$drops = $newarray["COUNT(id)"];
$total += $drops;
}
echo "<td>$total</td>";
}
echo "</tr>";
}
echo "</table>";
}
mysql_close($conn);
?>
[/quote]



What it should look like is a table with the elements of $job[] as the first item in a row and with an element from $zone[] at the top of a cloumn.

Waht I am getting is the elements of $job[] and $zone[] being truncated to the first character of them. IE THF becomes T Oztraja becomes O and Jeuno becomes J.

This becomes a major problem running through the first few loops as well as making it imposible to cycle through the items for the myql queries.


The code works perfectly on my test machine which runs php 5.2 it doesn not work properly on my yahoo webhosting account wich is running php 4.3

Any help in how to fix the code to make it work with 4.3 will be most appreciated.

Share this post


Link to post
Share on other sites
Solved the problem myself.


Solution: Drop boxes in the html form shared name with the data arrays. Didnt cause confusion on the development machine but did on the host machine.

Share this post


Link to post
Share on other sites
It's probably register_globals related ... disabled on your test machine (correctly), enabled on the production machine (incorrect).

Ken

Share this post


Link to post
Share on other sites

×

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.