Jump to content

border between different warranty


abs0lut
 Share

Recommended Posts

<?php include 'conn.php';$post = $_GET['post'];?>   <form method="post" name="formk" action="<?= $_SERVER['PHP_SELF']. '?' . $_SERVER['QUERY_STRING'] ?>"><?php$result = mysql_query("SELECT cid, iqid, cost, usersid, warranty, othmsg FROM ctable WHERE postid=$post ORDER BY warranty");while ($row = mysql_fetch_array($result)){  $arr[$row['iqid']][$row['usersid']] = $row['cost'];  $arr2[$row['iqid']][$row['usersid']] = $row['cid'];  $arr3[$row['iqid']][$row['usersid']] = $row['warranty'];  $uid[] = $row['usersid'];}$uid = array_unique($uid);$qid = array_keys($arr);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)  {	if (isset($arr[$iqid][$userid]))	{	   		echo "<td width='10%'>".$arr[$iqid][$userid]."<input type='radio'  name='iqid[$iqid]' value='{$arr2[$iqid][$userid]}'></td>";	}	else echo "<td></td>";	  }  echo "</tr>";}echo '<tr><td>Warranty:</td>'; foreach($uid as $userid)  { echo '<td width=10%>';  echo $arr3[$iqid][$userid];  echo '</td>';  }echo '</tr>';echo '</table>';echo '<input type="submit" name="checkb" />'; echo'</form>';	}?>

I used order by to sort warranty, so that same warranty will be grouped togetherI need to put a border between different warranty, could you please help me?15490478gu4.jpg

Link to comment
Share on other sites

I see two ways to do this; the second is more elegant but requires a complete reworking of your foreach-loops.

  1. Every time you make a new cell that might need the left border, check to see whether the current warranty is different from the last; if it is, add a CSS handle to the cell.
  2. Use only one foreach($uid as $userid) loop. Before it, assemble an array of the rows, with each value being of the form <tr><td>[row name]</td>. Each iteration of the loop, check the warranty as above and add to each row (in an inner foreach-loop) as appropriate. After the outer loop exits, echo implode('', $rows);.

EDIT: This would be much easier if you put the user ID in the left column and organized each user's data in a row rather than a column - because that's how HTML "thinks" about it.

Link to comment
Share on other sites

Maintain a variable whose scope spans all the loops. Just before the current user is changed, assign the warranty to this variable; compare the variable's value to the current warranty as necessary. For your current program structure, you would need to initialize the variable at least three times, one for each outer loop. The second structure I detailed is much simpler and easier to maintain - it would only require one initialization. (By "initialization," I mean setting the variable to null or whatever value you use to indicate you're only on the first column.)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...