I have a script I have been making in PHP to call information from a mysql database, and then auto-seperate that data by locations. This thing has been driving me nuts and I hope someone here could at least point me in the right direction.
[a href=\"http://www.webpropertiesinc.com/testsql.php\" target=\"_blank\"]The test page[/a]
[a href=\"http://www.webpropertiesinc.com/testsqlworks.php\" target=\"_blank\"]How its supposed to look[/a]
So just looking at the test page, you can see the same data is repeated over and over again for each location, with an extra property at the bottom of the list outside of the </table>. So let me start with posting my code at least:
$resultcbd = mysql_query("SELECT * FROM `Building Information` WHERE (Location = 'CBD & Periphery') ORDER BY `Building Name` ASC") or die(mysql_error());
$resultnorth = mysql_query("SELECT * FROM `Building Information` WHERE (Location = 'North Side') ORDER BY `Building Name` ASC") or die(mysql_error());
...etc, etc for each location is at the top of the page.
$color_switch = 'first';
$letters=array('A','B','C','D','E','F','G','H','I','J','K');
$bits=array('Type','Unit','Sq Ft','Annual Rate');
$areas=array('cbd' => 'CBD & Periphery', 'north' => 'North Side', 'valley' => 'Spokane Valley', 'shill' => 'South Hill', 'west' => 'West Plains', 'outside' => 'Outside Spokane'); //etc.
These are my variables...
foreach($areas as $key => $cur_area) {
$string='result' . $key;
while ($row = mysql_fetch_assoc($$string)) {
$heading='<h5><a name="' .$cur_area.'">' .$cur_area.'</a></h5>';
$table_row .= '<tbody class="' . $color_switch . '">' . "\n";
$table_row .= '<tr>' . "\n";
$table_row .= '<td rowspan="15" width="155"><a href="' . $ROOT . '/' . $row['HREF'] . '"><img src="' . $ROOT . '/images/' . $row['Picture'] . '" class="listingpic"/></a></td>' . "\n";
$table_row .= '<td rowspan="15"><dl><dt><a href="' . $ROOT . '/' . $row['HREF'] . '" title="View complete information">' . $row['Building Name'] . '</a></dt><dd><address>' . $row['Building Address 1'] . '<br>' . $row['Building Address 2'] . '</address></dd></dl></td>' . "\n";
foreach($letters as $cur_letter) {
$table_row .= $var_row . "\n";
if ( $cur_letter == 'A' ) {
$var_row = "";
} else {
$var_row = '<tr>' . "\n";
}
foreach($bits as $cur_type) {
$table_row.='<td>'.$row[$cur_type.' '.$cur_letter].' </td>';
}
$table_row .= '</tr>' . "\n";
}
$table_row .= '</tbody>' . "\n";
if ($color_switch == 'first') {
$color_switch = 'second';
} else {
$color_switch = 'first';
}
}
echo $heading . "\n";
echo $preamble . "\n";
$table_row .= '</table>' . "\n";
echo $table_row . "\n";
}
And that is what is in the body. So it seems like everything should pull correctly, but its all messed up and I don't know why! If I do only 1 area for my $areas=array, then that single area will display 100% correctly, with the correct properties under it and everything. However, more than 1 area and everything starts messing up. Where is my loop going wrong?
EDIT: This looks really jumbled, so I made a text file with all the data somewhat organized so you can actually tell what is going on.
[a href=\"http://www.webpropertiesinc.com/brokenscript.txt\" target=\"_blank\"]Text File that is somewhat organized[/a]