Jump to content

Queries displaying wrong.


Exis

Recommended Posts

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]

 

Link to comment
Share on other sites

Forgive me for saying so, but given the output of the page, it looks like the SQL queries are working as expected, but your PHP script is not. Please confirm that all of the expected fields and values are being retrieved, and then we can deal with the PHP itself.

Link to comment
Share on other sites

[!--quoteo(post=334976:date=Jan 9 2006, 06:38 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jan 9 2006, 06:38 PM) 334976[/snapback][/div][div class=\'quotemain\'][!--quotec--]

Forgive me for saying so, but given the output of the page, it looks like the SQL queries are working as expected, but your PHP script is not. Please confirm that all of the expected fields and values are being retrieved, and then we can deal with the PHP itself.

 

Ok I thought I may have posted this in the wrong category, sorry. Thought mysql was inclusive of all php with mysql questions. I'll try to watch out for that in the future.

 

Yeah my queries themselves are working just fine. Tested them in phpmyadmin just to make sure, so it has to be my php. I am just starting to learn it, so there is probably a big red flag somewhere that I am just unable to see. All of the values that I need are being retrieved, and even formated into tables correctly...er well for the most part. I am having some trouble getting the buildings (each opposite-colored block) to go where they are supposed to. You can really tell if you look at the example link vs. the test link I put above. It seems I am having loop problems with my php script...I just dont know where.

Link to comment
Share on other sites

It's not specifically the wrong category, just maybe not the ideal one to get the most useful responses. However, it looks like you're missing a whole bunch of </TR> tags all over the place, which is why you're having issues with multiple areas only.

Link to comment
Share on other sites

Can a mod move this to the correct forum for me?

 

Fenway- What do you mean I am missing a bunch of table row anchors? I don't see any missing in my view source of [a href=\"http://www.webpropertiesinc.com/testsql.php\" target=\"_blank\"]the test page[/a]. Could you post an example of where one should be?

Link to comment
Share on other sites

I am certain that its a problem caused by something buried in my foreach loops instead of a formatting issue. Even without any formatting my information is repeated in each area. I decided to try using just one area in the $area array, and it displays fine. Then I put a second area in that array (both areas had only 1 property belonging to them in my database...so its a little easier to see what is going on now), and the second area heading has both buildings below it! Please check out my test page link that I put above with the info and at least give me a hint as to what is going on here. Thanks!

Link to comment
Share on other sites

I'm not an expert PHP script debugging -- I'm a MySQL guy. But I don't see an open TABLE tag, your initial TR doesn't close (the right one after TBODY), and your "foreach($letters as $cur_letter)" block always outputs a close TR tag, but doesn't always open one. I think these can account for most of your problems. If you need more help than that, I suggest you try a forum with more PHP-knowledgable experts. Good luck.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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

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.