Hello, I'm new here, but am really impressed with the positive attitude! I was wondering if someone could give me some help or point me in the right direction. I have a query that returns the following fields:
city
state
name
serial
category
using this code
[PHP]
$p = '';
$result = mysql_query("SE LECT city, state, title, serial, category FROM serials ORDER BY serial, category");
while($row = mysql_fetch_ass oc($result))
{
if($row['serial'] == $p)
{
echo "<br />";
$p = $row['serial'];
}else{
echo "<br />";
echo "<br />";
$p = $row['serial'];
}
echo $row["city"];
echo $row["state"];
echo $row["title"];
echo $row["serial"];
echo $row["category"];
}
?>
[/PHP]
This generates the following:
I'm not too concerned about the formatting of the results right now.
What I would like to do is to group like results together. Naturally the <serialnum> values are grouped together and broken up by the double line break. What I would like to also group like 'categories' together with the <serialnum> groupings.
Ideally the data above would be represented like this:
So because the <category> field on line 3 matches the <category> field of line 1, it is grouped with the first grouping. Likewise, although the <serial> field of line 4 doesn't match either of lines 1,2,3 the <category> field of line 4 matches that of line 2. Lastly, since the <serial> field of line 5 matches the <serial> field of line 4, it is grouped in the first grouping.
Does this make sense? Sorry, reading it back it doesn't read that well. Let me know if I can make any further clarification.
Most importantly, thanks in advance for any direction that you can provide!
Jake
city
state
name
serial
category
using this code
[PHP]
$p = '';
$result = mysql_query("SE LECT city, state, title, serial, category FROM serials ORDER BY serial, category");
while($row = mysql_fetch_ass oc($result))
{
if($row['serial'] == $p)
{
echo "<br />";
$p = $row['serial'];
}else{
echo "<br />";
echo "<br />";
$p = $row['serial'];
}
echo $row["city"];
echo $row["state"];
echo $row["title"];
echo $row["serial"];
echo $row["category"];
}
?>
[/PHP]
This generates the following:
Code:
Toronto Ontario Chef 12345 ABC Detroit Michigan Cook 12345 DBF Toronto Ontario Cook 12353 ABC Los Angeles California Waiter 12355 DGG NYC New York Janitor 12382 DGG Miami Florida Cook 12777 FGH Fort Worth Texas Usher 12777 QWE Dallas Texas Cook 22222 FGH NYC New York Chef 33333 JKL Detroit Michigan Janitor 33333 DBF
What I would like to do is to group like results together. Naturally the <serialnum> values are grouped together and broken up by the double line break. What I would like to also group like 'categories' together with the <serialnum> groupings.
Ideally the data above would be represented like this:
Code:
Toronto Ontario Chef 12345 ABC Detroit Michigan Cook 12345 DBF Toronto Ontario Cook 12353 ABC Detroit Michigan Janitor 33333 DBF NYC New York Chef 33333 JKL Los Angeles California Waiter 12355 DGG NYC New York Janitor 12382 DGG Miami Florida Cook 12777 FGH Fort Worth Texas Usher 12777 QWE Dallas Texas Cook 22222 FGH
Does this make sense? Sorry, reading it back it doesn't read that well. Let me know if I can make any further clarification.
Most importantly, thanks in advance for any direction that you can provide!
Jake
Comment