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
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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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