Page 1 of 1

Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 3:50 am
by simonmlewis
Hi

Code: Select all

$result = mysql_query ("SELECT * FROM diary WHERE raceid = '$id' ORDER BY cartype ASC");
while ($row = mysql_fetch_object($result))
      {
      $resultuser = mysql_query ("SELECT * FROM admin WHERE id = '$row->userid'");
      while ($rowuser = mysql_fetch_object($resultuser))
      {
echo "<tr valign='top'>
      <td>$rowuser->firstname $rowuser->lastname</td>
      <td>$row->carmake, $row->carmodel</td>
      <td>$row->cartype</td>
      <td>$row->transponder</td>
      <td>$row->frequency</td>
      <td>";
      if ($cookietype == "admin") { echo "<a href='index.php?page=attendees&id=$id&diaryid$row->id&event=$event&=&d=yes' style='text-decoration: none; color: #444444'>Admin Delete</a><br/>";}
      if ($cookieid == "$row->userid") { echo "<a href='index.php?page=attendees&id=$id&diaryid$row->id&event=$event&=&d=yes' style='text-decoration: none; color: #444444'>Delete</a>";}
      echo "</td></tr>";
      }
mysql_free_result($resultuser);
} 	mysql_free_result($result);
This products all car attendees of a race, ordered by Car Type.

Is it possible to put a blank spaced row when one car type ends, and another begins.

Ie. you have three '2WD' and then you have two'4WD'.

Can it show like this?

Fred 2WD
Bob 2WD
Ginger 2WD

Arthur 4WD
Alf 4WD

???
I would assume it checks the word being rendered and if the next one in the query is different from the one before, then put in a space, but I cannot work it out.
I tried this:

Code: Select all

$cartype=$row->cartype
if ($cartype != $cartype) { echo "stick in a space";}
But obviously as each row shows, that $cartype WILL be correct.

Help!!

Re: Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 12:19 pm
by mikosiko

Code: Select all

....

$cartype = "";
while ($row = mysql_fetch_object($result))
{
  if ($cartype != $row->cartype) {
     echo "<br />";  // or whatever you want
     $cartype = $row->cartype;
  }
 ....

}

Re: Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 12:47 pm
by simonmlewis
mmmm well this puts a space after every row of the rendered table.

Code: Select all

$cartype = "";
$result = mysql_query ("SELECT * FROM diary WHERE raceid = '$id' ORDER BY cartype ASC");
while ($row = mysql_fetch_object($result))
      {
      $resultuser = mysql_query ("SELECT * FROM admin WHERE id = '$row->userid'");
      while ($rowuser = mysql_fetch_object($resultuser))
      {
echo "<tr valign='top'>
      <td>$rowuser->firstname $rowuser->lastname</td>
      <td>$row->carmake, $row->carmodel</td>
      <td>$row->cartype</td>
      <td>$row->transponder</td>
      <td>$row->frequency</td>
      <td>";
      if ($cookietype == "admin") { echo "<a href='index.php?page=attendees&id=$id&diaryid$row->id&event=$event&=&d=yes' style='text-decoration: none; color: #444444'>Admin Delete</a><br/>";}
      if ($cookieid == "$row->userid") { echo "<a href='index.php?page=attendees&id=$id&diaryid$row->id&event=$event&=&d=yes' style='text-decoration: none; color: #444444'>Delete</a>";}
      echo "</td></tr>";
      if ($cartype != $row->cartype) { echo "<tr><td colspan='6'>&nbsp;</td></tr>";}
      }
mysql_free_result($resultuser);
} 	mysql_free_result($result);

Re: Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 12:58 pm
by shawngoldw
take another look at mikosiko's post. You missed something.

Shawn

Re: Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 1:04 pm
by simonmlewis

Code: Select all

      if ($cartype != $row->cartype) { echo "<tr><td colspan='6'>&nbsp;</td></tr>";
      $cartype = $row->cartype;}
Found it. But it producing a slightly peculiar result with no pattern to it, as far as I can tell. See attached.

Re: Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 1:28 pm
by shawngoldw
It looks like you are doing the check after you print the row, you need to check first then print the row.

Shawn

Re: Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 1:38 pm
by simonmlewis
I'm not exactly sure what this achieves.
Can you please post it showing where I'd put a blank row in?

Re: Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 1:38 pm
by mikosiko
simonmlewis wrote:

Code: Select all

      if ($cartype != $row->cartype) { echo "<tr><td colspan='6'>&nbsp;</td></tr>";
      $cartype = $row->cartype;}
Found it. But it producing a slightly peculiar result with no pattern to it, as far as I can tell.....
write the code that I gave to you in the exact same position that I wrote it.... is very clear.

Code: Select all

....

$cartype = "";
while ($row = mysql_fetch_object($result))
{
  if ($cartype != $row->cartype) {
     echo " .... ";  // or whatever you want
     $cartype = $row->cartype;
  }
 ....

}

Re: Space between Groupby rendered rows???

Posted: Thu Aug 19, 2010 3:04 pm
by simonmlewis

Code: Select all

$cartype = "";
$result = mysql_query ("SELECT * FROM diary WHERE raceid = '$id' ORDER BY cartype ASC");
while ($row = mysql_fetch_object($result))
      {
      $resultuser = mysql_query ("SELECT * FROM admin WHERE id = '$row->userid'");
      while ($rowuser = mysql_fetch_object($resultuser))
      {
echo "<tr valign='top'>
      <td>$rowuser->firstname $rowuser->lastname</td>
      <td>$row->carmake, $row->carmodel</td>
      <td>$row->cartype</td>
      <td>$row->transponder</td>
      <td>$row->frequency</td>
      <td>";
      if ($cookietype == "admin") { echo "<a href='index.php?page=attendees&id=$id&diaryid$row->id&event=$event&=&d=yes' style='text-decoration: none; color: #444444'>Admin Delete</a><br/>";}
      if ($cookieid == "$row->userid") { echo "<a href='index.php?page=attendees&id=$id&diaryid$row->id&event=$event&=&d=yes' style='text-decoration: none; color: #444444'>Delete</a>";}
      echo "</td></tr>";
      }
mysql_free_result($resultuser);
} 	mysql_free_result($result);
This produces only a few of the records expected.