Jump to content

Split one MySql table in more tables


Coldman

Recommended Posts

Hello ther i am trying to fix an MySql query problem but i can not fix this for some days, any help will be welcome.

The problem is this way.

I have an query that selects data from three tables and when i display them they are shown all in one table. All i want to do is to split this table in more tables based on the rows that have similar data.

this is my query:

$query1=mysql_query("SELECT tbltasks.taskid, tbltasks.campid, tbltasks.taskname, tbltasks.taskdate, tblemployee.Name, tblemployee.Surename, tblemployee.profession, tblemployee.foto, tblemployee.drivinglicense, tblemployee.bexh, tblemployee.medicalscreening, tblcamps.campname

FROM tbltasks, tblemployee, tblcamps

WHERE tbltasks.taskid = tblemployee.taskid

AND tbltasks.campid = tblcamps.campid ");

 

so i want to have different tables based on the tbltasks.taskid, every rows that have similar tbltasks.taskid to be shown in one table and sow on.

 

Please help?

Link to comment
https://forums.phpfreaks.com/topic/106936-split-one-mysql-table-in-more-tables/
Share on other sites

i use this code

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("ecologevents") or die(mysql_error());

$query1=mysql_query("SELECT count(tbltasks.taskid) as count,  tbltasks.taskid, tbltasks.campid, tbltasks.taskname, tbltasks.taskdate, tblemployee.Name, tblemployee.Surename, tblemployee.profession, tblemployee.foto, tblemployee.drivinglicense, tblemployee.bexh, tblemployee.medicalscreening, tblcamps.campname
FROM tbltasks, tblemployee, tblcamps
WHERE tbltasks.taskid = tblemployee.taskid
AND tbltasks.campid = tblcamps.campid GROUP BY tbltasks.taskid having count >0 order by tbltasks.taskid ");
while($row_list=mysql_fetch_array($query1)){
$taskid = $row_list['taskid'];
$taskname = $row_list['taskname'];
$campname = $row_list['campname'];
$taskdate = $row_list['taskdate'];
$employeename = $row_list['Name'];
$employeesurname = $row_list['Surename'];
$profession = $row_list['profession'];
$foto = $row_list['foto'];
$leja = $row_list['drivinglicense'];
$bexhi = $row_list['bexh'];
$kontrollat = $row_list['medicalscreening'];
$count = $row_list['count'];
if($foto == 'Posedon'){

$foto = "images/ka.gif";
}
else 
{
$foto =  "images/nukka.gif";}

if($leja == 'Posedon'){

$leja = "images/ka.gif";
}
else 
{
$leja =  "images/nukka.gif";}

if($bexhi == 'Posedon'){

$bexhi = "images/ka.gif";
}
else 
{
$bexhi =  "images/nukka.gif";}

if($kontrollat == 'Posedon'){

$kontrollat = "images/ka.gif";
}
else 
{
$kontrollat =  "images/nukka.gif";}

if ($count > 1){
?>

<table style="border:1px solid #B5DAE7;" cellpadding="0" cellspacing="0">
<tr>
<td width="80" align="center" valign="middle" bgcolor="#E7EFF2"><?php echo $employeename;  ?></td>
<td width="80" align="center" valign="middle" bgcolor="#E7EFF2"><?php echo $employeesurname; ?></td>
<td width="80" align="center" valign="middle" bgcolor="#E7EFF2"><b><?php echo $profession; ?></b></td>
<td width="150" align="center" valign="middle" bgcolor="#E7EFF2"><?php echo $campname; ?></td>
<td width="50" align="center" valign="middle" bgcolor="#E7EFF2"><img src="<?php echo $foto; ?>"/></td>
<td width="50" align="center" valign="middle" bgcolor="#E7EFF2"><img src="<?php echo $leja; ?>"/></td>
<td width="50" align="center" valign="middle" bgcolor="#E7EFF2"><img src="<?php echo $bexhi; ?>"/></td>
<td width="50" align="center" valign="middle" bgcolor="#E7EFF2"><img src="<?php echo $kontrollat; ?>"/></td>
<td width="150" align="center" valign="middle" bgcolor="#E7EFF2"><?php echo $taskdate; ?><br></td>
</tr>
</table>

</font>

<?php

}
}
?>

This way i get just one employee from all tasks

please help

First you need "ORDER BY taskid" added to the query. The pseudocode for the output is

 

lastID = '';

while fetch next row

        if taskid not equal to lastID
               if lastID not ''
                      output </table>
               end if
               output <table> and headings
               set lastID = taskid
        end if

        echo data row

end while
output </table>

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.