Coldman Posted May 23, 2008 Share Posted May 23, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/106936-split-one-mysql-table-in-more-tables/ Share on other sites More sharing options...
fenway Posted May 23, 2008 Share Posted May 23, 2008 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. What? Quote Link to comment https://forums.phpfreaks.com/topic/106936-split-one-mysql-table-in-more-tables/#findComment-548172 Share on other sites More sharing options...
Coldman Posted May 24, 2008 Author Share Posted May 24, 2008 this is the problem: Quote Link to comment https://forums.phpfreaks.com/topic/106936-split-one-mysql-table-in-more-tables/#findComment-548751 Share on other sites More sharing options...
beboo002 Posted May 24, 2008 Share Posted May 24, 2008 u make splited table in database or found output like this Structure ? if u want split table and save in database(i think there is no need ) want output like below you mantion then use paging this is right way Quote Link to comment https://forums.phpfreaks.com/topic/106936-split-one-mysql-table-in-more-tables/#findComment-548831 Share on other sites More sharing options...
Coldman Posted May 26, 2008 Author Share Posted May 26, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/106936-split-one-mysql-table-in-more-tables/#findComment-550091 Share on other sites More sharing options...
Barand Posted May 26, 2008 Share Posted May 26, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/106936-split-one-mysql-table-in-more-tables/#findComment-550455 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.