Jump to content

Recommended Posts

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>
";


}
}

Link to comment
https://forums.phpfreaks.com/topic/270912-help-separating-by-groups/
Share on other sites

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>";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.