
Originally Posted by
Cups
This is what var_dump() looks like, go and read about it in the database it will save your life.
Thanks for that, I'll definitely look up the var_dump 
That result set looks about right to me, try adding the code I gave you featuring a foreach() loop instead of your attempt.

Originally Posted by
r937
the query requires an ORDER BY clause for this to work successfully
OK, here is what I have for the query, including the ORDER BY that r937 recommended:
PHP Code:
mysql_select_db($database_conn_taylor, $conn_taylor);
$query_rs_status = "SELECT p.buildingID as bID, p.location as property, u.unitnum as unit, u.rent_status as status
FROM properties as p
LEFT JOIN units as u
ON p.buildingID = u.buildingID
ORDER BY bID";
$rs_status = mysql_query($query_rs_status, $conn_taylor) or die(mysql_error());
$row_rs_status = mysql_fetch_assoc($rs_status);
$totalRows_rs_status = mysql_num_rows($rs_status);
And here's the loop:
PHP Code:
$last = '';
foreach( $row_rs_status as $r ){
if( $r['property'] != $last){
echo '<h3>' . $r['property'] . '</h3>' . PHP_EOL ; }
$last = $r['property'];
echo '<p>' . $r['unit'] . ' is ' . $r['features'] .'</p>'. PHP_EOL ;}
And here's the result:
HTML Code:
1
1 is 1
3
3 is 3
1
1 is 1
1 is 1
On the other hand, with the do while loop (same query) I have
PHP Code:
do {
$last = '';
if( $row_rs_status['property'] != $last){
echo '<h4>' . $row_rs_status['property'] . '</h4>' . PHP_EOL ; }
$last = $row_rs_status['property'];
echo '<p>' . $row_rs_status['unit'] . ' is ' . $row_rs_status['status'] .'</p>' . PHP_EOL ;
} while ($row_rs_status = mysql_fetch_assoc($rs_status)); ?>
And the result is:
HTML Code:
35 Belvedere Ave
1 is 1
35 Belvedere Ave
2 is 1
35 Belvedere Ave
3 is 1
460 St. Peter's Rd
1 is 1
460 St. Peter's Rd
2 is 1
315 Norwood Rd.
2 is 1
315 Norwood Rd.
3 is 0
Etc.
I feel like something obvious is missing or out of place but I just can't see it.
Bookmarks