abs0lut Posted May 7, 2008 Share Posted May 7, 2008 database structure it should display this userid1 userid2 userid3 iqid1 cost cost cost iqid2 cost cost cost iqid3 cost cost cost please help me.. Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/ Share on other sites More sharing options...
trq Posted May 7, 2008 Share Posted May 7, 2008 Post your code and your question. Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-534986 Share on other sites More sharing options...
moselkady Posted May 7, 2008 Share Posted May 7, 2008 You can read your costs into a 2D array then print that array as a table. For example <?php $result = mysql_query("SELECT iqid, cost, userid FROM my_table"); while ($row = mysql_fetch_array($result)) { $arr[$row['iqid']][$row['userid']] = $row['cost']; $uid[] = $row['userid']; } $uid = array_unique($uid); $qid = array_keys($arr); foreach($uid as $userid) echo "\t$userid"; echo "\n";foreach($qid as $iqid) { echo "$iqid\t"; foreach($uid as $userid) { if (isset($arr[$iqid][$userid])) echo $arr[$iqid][$userid]; else echo " "; echo "\t"; } echo "\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-534998 Share on other sites More sharing options...
abs0lut Posted May 8, 2008 Author Share Posted May 8, 2008 file.php <?php $post=$_GET['post']; $result = mysql_query("SELECT iqid, cost, userid FROM ctable WHERE postid=$post"); while ($row = mysql_fetch_array($result)) { $arr[$row['iqid']][$row['userid']] = $row['cost']; $uid[] = $row['userid']; } $uid = array_unique($uid); $qid = array_keys($arr); foreach($uid as $userid) echo "\t$userid"; echo "\n";foreach($qid as $iqid) { echo "$iqid\t"; foreach($uid as $userid) { if (isset($arr[$iqid][$userid])) echo $arr[$iqid][$userid]; else echo " "; echo "\t"; } echo "\n"; } ?> when I enter file.php?post=2 all iqids are selected please help me.. Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-535659 Share on other sites More sharing options...
abs0lut Posted May 10, 2008 Author Share Posted May 10, 2008 why I couldn't edit my previous posts? I already solved the above posts but I have problem with alignment of cost.. \n and \t is not functioning, userids are not aligned with the cost.. please change it with tables?? Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-537212 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 echo "<br />"; Instead of echo "\n"; Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-537217 Share on other sites More sharing options...
Barand Posted May 10, 2008 Share Posted May 10, 2008 . please change it with tables?? http://www.w3schools.com/html/html_tables.asp Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-537221 Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 echo "<br />"; Instead of echo "\n"; I meant: echo "<br />"; =P Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-537223 Share on other sites More sharing options...
moselkady Posted May 10, 2008 Share Posted May 10, 2008 Replace this part in your code: echo '<table><tr><td></td>'; foreach($uid as $userid) echo "<td>$userid</td>"; echo '</tr>'; foreach($qid as $iqid) { echo "<tr><td>$iqid</td>"; foreach($uid as $userid) { echo '<td>'; if (isset($arr[$iqid][$userid])) echo $arr[$iqid][$userid]; echo '</td>'; } echo "</tr>"; } echo '</table>'; Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-537233 Share on other sites More sharing options...
abs0lut Posted May 10, 2008 Author Share Posted May 10, 2008 echo '<table cellpadding=5><tr><td></td>'; foreach($uid as $userid) echo "<td>$userid</td>"; echo '</tr>'; foreach($qid as $iqid) { echo "<tr><td>$iqid</td>"; foreach($uid as $userid) { echo '<td>'; if (isset($arr[$iqid][$userid])) echo $arr[$iqid][$userid]."<input type='checkbox' name='sa[]'>"; echo '</td>'; } echo "</tr>"; } echo '</table>'; thank you very much.. I've added checkbox in every cost, I have problem with alignment again.. the checkbox is not aligned with each other vertically Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-537274 Share on other sites More sharing options...
abs0lut Posted May 11, 2008 Author Share Posted May 11, 2008 <?php echo'<form method="post" name="myform" action="file.php">'; $result = mysql_query("SELECT iqid, cost, userid FROM ctable where postid=$post"); while ($row = mysql_fetch_array($result)) { $arr[$row['iqid']][$row['userid']] = $row['cost']; $uid[] = $row['userid']; } $uid = array_unique($uid); $qid = array_keys($arr); echo '<table cellpadding=5><tr><td></td>'; foreach($uid as $userid) echo "<td>$userid</td>"; echo '</tr>'; foreach($qid as $iqid) { echo "<tr><td>$iqid</td>"; foreach($uid as $userid) { echo '<td>'; if (isset($arr[$iqid][$userid])) echo $arr[$iqid][$userid]; echo '</td>'; } } $result = mysql_query("SELECT cid FROM ctable WHERE postid=$post"); while ($row = mysql_fetch_array($result)) { echo "<input type='checkbox' name='sa[]' value='$row[cid]'>"; } echo "</tr>"; echo '</table>'; echo '<input type="submit" name="listing" />'; echo'</form>'; ?> I've added checkbox and I need to get the cid.. I have problem in positioning, the checkbox appeared in the top of the userid(above userid) I want the checkbox to appear beside with the cost.. please help me... Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-538005 Share on other sites More sharing options...
moselkady Posted May 13, 2008 Share Posted May 13, 2008 I am not sure what you are trying to display. If you can post an image of the table that you want to produce, that would help Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-539670 Share on other sites More sharing options...
abs0lut Posted May 13, 2008 Author Share Posted May 13, 2008 Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-539708 Share on other sites More sharing options...
moselkady Posted May 13, 2008 Share Posted May 13, 2008 In this code, I added cid to the query as well as in a second array $arr2 then print 2 cells for each user that will have cost and checkbox. I hope this helps <?php $result = mysql_query("SELECT iqid, cost, userid, cid FROM ctable"); while ($row = mysql_fetch_array($result)) { $arr[$row['iqid']][$row['userid']] = $row['cost']; $arr2[$row['iqid']][$row['userid']] = $row['cid']; $uid[] = $row['userid']; } $uid = array_unique($uid); $qid = array_keys($arr); echo '<table cellpadding=5><tr><td></td>'; foreach($uid as $userid) echo "<td colspan='2'>$userid</td>"; echo '</tr>'; foreach($qid as $iqid) { echo "<tr><td>$iqid</td>"; foreach($uid as $userid) { if (isset($arr[$iqid][$userid])) { echo "<td>".$arr[$iqid][$userid]."</td><td><input type='checkbox' name='sa[]' value='{$arr2[$iqid][$userid]}'></td>"; } else echo '<td colspan='2'></td>'; } echo "</tr>"; } echo '</table>'; ?> Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-540206 Share on other sites More sharing options...
abs0lut Posted May 13, 2008 Author Share Posted May 13, 2008 thank you very much.. Link to comment https://forums.phpfreaks.com/topic/104504-solved-display-by-group/#findComment-540416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.