Page 1 of 1

display information from a database column

Posted: Fri Jan 31, 2014 3:25 pm
by pratick
Hello I made a request to display information from a base against I do not get it to appear in column

For information in the database I have dates with several slots

before(data from the base=
22/10/2013 HD:10h30 HF:11h30
22/10/2013 HD:18h30 HF:20h30
22/10/2013 HD:21h30 HF:22h00

23/10/2013 HD:10h30 HF:11h30
23/10/2013 HD:18h30 HF:20h30

25/10/2013 HD:10h30 HF:11h30
25/10/2013 HD:18h30 HF:20h30

application to display the information in column
22/10/2013---|-23/10/2013--|-23/10/2013--|
D10h30-F11h30|D18h30-F20h30|D18h30-F20h30|
D18h30-F20h30|D10h30-F11h30|
D21h30-F22h00|
Thank you

Code: Select all

$date_entre = new DateTime($_POST['date_debut_input']);
  $date_entre->modify('-1 day');
  echo "<table><tr>";  
for ($i = 1; $i <= 4; $i++) {
    $date_entre2=$date_entre->modify('+1 day');
    echo  "<td>".($date_entre2->format('Y-m-j'))."</td>";
    $date_heure2[]=$date_entre2->format('Y-m-j');
 
 
    $deta_heure_unique = array_unique($date_heure2);        
 
};
 
 foreach ($deta_heure_unique as $key ) {
//     echo "<td>".$key."</td><td>";
  echo "<tr>";      
	 $select1= "SELECT SQL_CALC_FOUND_ROWS t1.*, t3.* FROM agents t1
		 LEFT join heures t3 on(t1.GAIA = t3.GAIA) where ".$compreq." and date_heures='".$key."'  order by date_heures DESC"; //where $compreq $date_entre order by heure_fin
			$reponse1 = mysql_query($select1)or die (mysql_error());
				while($donne1=mysql_fetch_array($reponse1)){
 
					echo "<td> HD:".$donne1['heure_debut']." HF:".$donne1['heure_fin']."</br>";
				}
				echo "</td></tr>";
 }
 
  echo "</tr></table>";
  ?>
 
</div>

Re: display information from a database column

Posted: Thu Feb 06, 2014 1:36 pm
by requinix
It's not the most efficient solution, but it is the easiest to describe and understand:
1. Get a list of all the possible columns (ie, dates)
2. Get a list of all the things and their dates
3. Turn that second list into a 2D array, with the things at the first level and the dates at the second level
Then the table:
4. Loop over all the things in the array
5. Loop over all the possible dates (from the first list)
6. If the thing has a corresponding entry for that date, show it, otherwise show an empty cell