Jump to content

How to identify location and room changes, an elegant solution


cjohnsonuk

Recommended Posts

I found the tutorial on the joins. I can read my location, room and help desk call information into one array but is there an elegant way to display  the resulting parsed array nicely into 1 div per location and 1 table per room with each call going in on its own table row?

Without much to go on its a bit difficult to know what you want to achieve.

 

I'm going to take a stab anyway

 

<?php
$sql = "SELECT * FROM sometable";
$query = mysql_query($sql);

$loc = ''; //set temp variable to hold location
$room = ''; //set temp variable to hold room

while($result = mysql_fetch_array($query)) {
//check if location has changed
if($loc != $result['location']) {
	if($loc == '') {
		//first time through the loop - open a new div tag
		echo '<div>';
	} else {
		//close the existing div tag and open a new one
		echo '</div><div>';
	}
}	

if($room != $result['room']) {
	if($room == '') {
		//first time through the loop - open a new table tag
		echo '<table>';
	} else {
		//close the existing table tag and open a new one
		echo '</table><table>';
	}
}

//display the calls
echo '<tr><td>'.$result['call'].'</td></tr>';	

//update temp variables
$loc = $result['location'];
$room = $reslt['room'];
}
?>

 

i haven't fully tested this yet, but it should give you what i think you want  :-\

 

 

Can you post the query that you have and some html on how you expect it to look, in case the above is not what you want.

 

 

Archived

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

×
×
  • 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.