Klein_Kipje Posted December 17, 2014 Share Posted December 17, 2014 I googled myself lame to find out, but no luck. Is it possible to allign every row in a sql result table different. And i mean, not the text but the whole row. 01 | ** | ** | left 02 | ** | ** | center 03 | ** | ** | right 04 | ** | ** | center05 | ** | ** | left depending of the value of one of the cell in that row. I'm able to assign a different class to <TD> to change color of the cell (or whatever) depending on that value. Is it possible at all to allign rows different from each other ? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted December 17, 2014 Share Posted December 17, 2014 "an sql result table"? Do you perhaps mean an html table? Assuming that is what you meant to say, I would say 'No'. An html table doesn't have that facility (afaik). So - how to do this? Well - how important are 'column alignments once you decide where a specific row should being (on the x axis)? If no so important you could simply display each row in different divs which have specific left margins set to do what you want. If important, then you might do it with the same divs scheme but with individual divs defined for each 'column' that are then output inside of each 'row' div. Psuedo-like-this: <div id='left-row'> data </div> <div id='right_row'> data </div> Or: <div id='left_row'> <div id='col1'> col1 data </div> <div id='col2'> col2 data </div> <div id='col3'> col3 data </div> </div> and so on. Quote Link to comment Share on other sites More sharing options...
Klein_Kipje Posted December 17, 2014 Author Share Posted December 17, 2014 (edited) I mean a sql result table its to create a timetable now i have every event on the same left allign like a normal sql table its has 3 locations and my idea was to allign every location different to make it more easy viewable This is the code so far, the <td class = "'.$NewClass.'"> makes the table cell a different color depending on the location $result = mysql_query($sql) or die(mysql_error()); $begin = strtotime('13:00'); echo'<table>'; while($row = mysql_fetch_array($result)) { $PODIUM = $row['PODIUM']; if ($row['PODIUM'] == 1) { $NewClass = "JA" ; } elseif ($row['PODIUM'] == 2) { $NewClass = "NEE"; } elseif ($row['PODIUM'] == 3) { $NewClass = "MISSCHIEN"; } $duur = $row['DUUR']; $end = strtotime("+ $duur minutes", $begin); echo'<tr> <td class = "'.$NewClass.'">'.$row['POSITIE'].'</td> <td class = "'.$NewClass.'">'.$row['NAAMBAND'].'</td> <td class = "'.$NewClass.'">'; if($PODIUM == 1){ echo "<div class='item'><label>Hoofdpodium</label></div>"; }; if($PODIUM == 2){ echo "<div class='item'><label>DJ Toren</label></div>"; }; if($PODIUM == 3){ echo "<div class='item'><label>Talentstage</label></div>"; }; echo'<td class = "'.$NewClass.'">'.$row['DUUR'].'</td> <td class = "'.$NewClass.'">'.date('H:i', $begin).'</td> <td class = "'.$NewClass.'">'.date('H:i', $end).'</td> '; echo'</tr>'; $begin = $end; } echo'</table>'; ?> Edited December 17, 2014 by Klein_Kipje Quote Link to comment Share on other sites More sharing options...
ginerjm Posted December 17, 2014 Share Posted December 17, 2014 Ok - that is an html table. Sql results are not in a table (they are in a 'resource') until you output them as part the data in an html table. (Semantics are VERY important in the IT realm.) So - now you can consider my previous suggestions - or not. BTW - isn't this display idea going to make viewing a little troubling? Personally if I'm viewing a set of data that is homogeneous I want to see it in a clear format, not have to make my eyes wander from column to column to find like items which this format will cause. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 17, 2014 Share Posted December 17, 2014 If you allocate 3x as many columns to your HTML table then you can arrange them by outputting empty cells. In this example there are 3 rooms, and the room number sets the left, centre or right position mysql> SELECT * FROM timetable; +--------------+-----------+------+----------+----------+ | timetable_id | subject | room | timefrom | timeto | +--------------+-----------+------+----------+----------+ | 1 | English | 1 | 09:00:00 | 10:00:00 | | 2 | Maths | 2 | 10:00:00 | 11:00:00 | | 3 | Biology | 3 | 11:00:00 | 12:00:00 | | 4 | Geography | 2 | 13:00:00 | 14:00:00 | | 5 | History | 3 | 14:00:00 | 15:00:00 | +--------------+-----------+------+----------+----------+ the sample code $mysqli = new mysqli(HOST,USERNAME,PASSWORD,'test'); $sql = "SELECT subject , room , timefrom , timeto FROM timetable ORDER BY timefrom"; $res = $mysqli->query($sql); $ttdata = ''; while (list($sub,$room,$from,$to) = $res->fetch_row()) { $from = date('g:i', strtotime($from)); $to = date('g:i', strtotime($to)); $ttdata .= '<tr>'; switch ($room) { case 1: $ttdata .= "<td>$sub</td><td>$from</td><td>$to</td><td colspan='6' class='empty'></td></tr>"; break; case 2: $ttdata .= "<td colspan='3' class='empty'></td><td>$sub</td><td>$from</td><td>$to</td><td colspan='3' class='empty'></td></tr>"; break; case 3: $ttdata .= "<td colspan='6' class='empty'></td><td>$sub</td><td>$from</td><td>$to</td></tr>"; break; } } ?> <html> <head> <title>Sample</title> <style type="text/css"> table {border-collapse: collapse;} th {background-color: blue; color: white;} td {padding: 2px 4px;} td.empty {background-color: #eee;} </style> </head> <body> <table border="1" cellspacing="3"> <tr><th colspan='3'>Room 1</th><th colspan='3'>Room 2</th><th colspan='3'>Room 3</th></tr> <?=$ttdata?> </table> </body> </html> Output Quote Link to comment Share on other sites More sharing options...
Klein_Kipje Posted December 17, 2014 Author Share Posted December 17, 2014 Would it be possible that you put your solution in my code, because it goes i little above my head. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 17, 2014 Share Posted December 17, 2014 (edited) The relevant bit is switch ($room) {case 1: //LEFT$ttdata .= "<td>$sub</td><td>$from</td><td>$to</td><td colspan='6' class='empty'></td></tr>";break;case 2: //CENTRE$ttdata .= "<td colspan='3' class='empty'></td><td>$sub</td><td>$from</td><td>$to</td><td colspan='3' class='empty'></td></tr>";break;case 3: //RIGHT$ttdata .= "<td colspan='6' class='empty'></td><td>$sub</td><td>$from</td><td>$to</td></tr>";break;} Edited December 17, 2014 by Barand Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.