derekshull Posted November 19, 2012 Share Posted November 19, 2012 I've got the following code below and it works great. It's list all the entrys in the database that meet those specifications and it's sorted by the title of need and the ID. My question is is there a way to put a space between the different titled groups. Right now it looks like this: Title1 Title1 Title1 Title2 Title3 Title3 But I'd like for it to look like this: Title1 Title1 Title1 Title2 Title3 Title3 I'm not sure how to go about it. Thanks for the help! $query = mysql_query("SELECT * FROM needs WHERE status !='hidden' AND status !='denied' AND status !='deleted' AND status !='expired' AND (workerfoldername IS NULL OR workerfoldername='') AND (needsusername='$username' OR workerusername='$username') ORDER BY titleofneed, ID"); echo "<table border='1'><tr><th><center>Title of Need</center></th><th><center> Organization </center></th><th><center>Needs Username</center></th><th><center>Worker Username</center></th><th><center>City, State</center></th></tr>"; while ($rows = mysql_fetch_array($query)) { $id = $rows['ID']; $status = $rows['status']; $firstname = $rows['firstname']; $city = $rows['city']; $state = $rows['state']; $phone = $rows['phone']; $email = $rows['email']; $typeofneed = $rows['typeofneed']; $description = $rows['description']; $workername = $rows['workername']; $workeremail = $rows['workeremail']; $workerphone = $rows['workerphone']; $completiondate = $rows['completiondate']; $needsusername = $rows['needsusername']; $workerusername = $rows['workerusername']; $howmanypeopleneeded = $rows['howmanypeopleneeded']; $howmanypeoplesignedup = $rows['howmanypeoplesignedup']; $titleofneed = $rows['titleofneed']; $theneedsfoldername = $rows['needsfoldername']; $theworkerfoldername = $rows['workerfoldername']; if (($needsusername == $username && $theneedsfoldername == '') || ($workerusername == $username && $theworkerfoldername == '')) { $orgname = $rows['orgname']; $expiredate = $rows['expiredate']; echo " <tr><td>$titleofneed</td><td>$orgname</td><td>$needsusername</td><td>$workerusername</td><td>$city, $state</td><td>view more</td></tr> "; } } Quote Link to comment https://forums.phpfreaks.com/topic/270912-help-separating-by-groups/ Share on other sites More sharing options...
Barand Posted November 19, 2012 Share Posted November 19, 2012 (edited) $prev = ''; while (whatever) { if ($prev && $currentValue != $prev) { // output blank line here $prev = $currentValue; } // output normal line here } Edited November 19, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/270912-help-separating-by-groups/#findComment-1393621 Share on other sites More sharing options...
derekshull Posted November 19, 2012 Author Share Posted November 19, 2012 Tried putting it in the code but didn't work...this is what I had: $query = mysql_query("SELECT * FROM needs WHERE status !='denied' AND (needsusername='$username' OR workerusername='$username') AND (workerfoldername='$foldertoview' OR needsfoldername='$foldertoview') ORDER BY ID"); echo "<table border='1'><tr><th><center> Title of Need </center></th><th><center> Organization </center></th><th><center> Needs Username </center></th><th><center> Worker Username </center></th><th><center> City, State </center></th><th><center> Move To </center></th></tr>"; $i=1; $prev = ''; while ($rows = mysql_fetch_array($query)) { $titleofneed = $rows['titleofneed']; if ($titleofneed != $prev) { echo "<tr></tr><tr></tr>"; $prev = $currentValue; } $id = $rows['ID']; $status = $rows['status']; $firstname = $rows['firstname']; $city = $rows['city']; $state = $rows['state']; $phone = $rows['phone']; $email = $rows['email']; $typeofneed = $rows['typeofneed']; $description = $rows['description']; $workername = $rows['workername']; $workeremail = $rows['workeremail']; $workerphone = $rows['workerphone']; $completiondate = $rows['completiondate']; $needsusername = $rows['needsusername']; $workerusername = $rows['workerusername']; $howmanypeopleneeded = $rows['howmanypeopleneeded']; $howmanypeoplesignedup = $rows['howmanypeoplesignedup']; $theneedsfoldername = $rows['needsfoldername']; $theworkerfoldername = $rows['workerfoldername']; if (($needsusername == $username && $theneedsfoldername == $foldertoview) || ($workerusername == $username && $theworkerfoldername == $foldertoview)) { $orgname = $rows['orgname']; $expiredate = $rows['expiredate']; $j=$i++; echo " <tr><td> <script type='text/javascript'> function submitaform".$j."() { document.theaform".$j.".submit(); } </script> <form name='theaform".$j."' action='viewfullneed' method='post'> <input type='hidden' name='idtoview' value='$id'> <a href='javascript: submitaform".$j."()'>$titleofneed</a> </form> </td> <td>$orgname</td><td>$needsusername</td><td>$workerusername</td><td>$city, $state</td><td>"; $userquery = mysql_query("SELECT * FROM folders WHERE username='$username'"); echo"<form action='moveneed' method='post'><input type='hidden' name='idtomove' value=$id><select name='foldertomove' size='1'><option value=''></option><option value=''>Home Folder</option>"; while ($userrows = mysql_fetch_array($userquery)) { $foldername = $userrows['foldername']; echo "<option value='$foldername'>$foldername</option>"; } echo "</select> <input type='submit' value='Move'></form> </td> "; } } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/270912-help-separating-by-groups/#findComment-1393636 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.