News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

MySQL results into columns

Started by James Bone, May 26, 2005, 07:16:02 AM

Previous topic - Next topic

James Bone

I am trying to get my mysql results put into a calender. I have the dates of the staff leave which i want to put in columns under Jan..feb..mar.. etc etc.

How would i go about doing it?

[Unknown]

I'm not sure I understand what you mean.  Do you just mean that you have a SELECT query you want to put into a table?

-[Unknown]

James Bone

Yes, i would like to sort the results which are dates into the relevent cells in the table.

[Unknown]

CREATE TABLE table_name
SELECT ...;

-[Unknown]

James Bone

Sorry, i mean an HTML table on output

So in the January cell it will list all the results with January in etc

[Unknown]

Oh, lol.  Okay.  Then something like this:

$request = mysql_query("
   SELECT ...");
$data = array();
while ($row = mysql_fetch_assoc($request))
   $data[] = $row;
mysql_free_result($request);

echo '<table>
   <tr><th>', implode('</th><th>', array_keys($data[0])), '</th></tr>';
foreach ($data as $row)
   echo '
   <tr><td>', implode('</th><th>', $row), '</td></tr>';
echo '
</table>';


-[Unknown]

James Bone

How about getting it to do this;

JanFebMar
Data hereData hereData here
AprMayJun
Data hereData hereData here
JulAugSept
Data hereData hereData here
OctNovDec
Data hereData hereData here

[Unknown]

Sorry, but it's hard to understand your meaning without a query or visual example.

For that, use something like this:

$request = mysql_query("
   SELECT ...");
$data = array();
while ($row = mysql_fetch_assoc($request))
   $data[] = $row;
mysql_free_result($request);

echo '<table>
   <tr><th>', implode('</th><th>', array_keys($data[0])), '</th></tr>
   <tr>';

$i = 0;
foreach ($data as $row)
{
   if ($i == 3)
   {
      echo '
   </tr>';
      $i = 0;
   }

   echo '
   <td>', $row['month'], '<br />', $row['data'], '</td>';

   $i++;
}

echo '
   </tr>
</table>';


-[Unknown]

Advertisement: