Hi!
I am fairly new to PHP, having thrown myself in at the deep end by agreeing to help a friend with his site! I am learning as I go, but keep meeting obstacles. I have one that I can't solve. I have asked this on another forum, but I thought I'd come and ask here as I would ideally like to get this done today. Oh, and apologies if I use any incorrect terms!
The site has a 'report' to display the results of a query (the basic premise is to list orders to be delivered on a set day of the week). This is working fine, but I can only get it to display in columns, e.g.:
Joe Bloggs 1 0 2
Fred Smith 0 1 0
The above numbers are items, so Joe Bloggs wants 1 of Item1, 0 of Item2 and 2 of Item3.
What I would like is to display the results like a delivery sheet, so each person displays in a separate table, with each item on a new line, e.g.:
Name: Joe Bloggs
Item 1: 1
Item 2: 0
Item 3: 2
Name: Fred Smith
Item1: 0
Item2: 1
Item3: 0
I know that I can rearrange the way the table displays in the HTML, but I don't know how to sort the looping side of things!
Here is my current code:
// print table header
echo("<table cellspacing=\"0\" cellpadding=\"0\" width=\"500\" class=\"edittable\">
<tr><th>Name</th><th>Item 1</th><th>Item 2</th><th>Item 3</th></tr>");
// fetch the current row into the array $row
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo("<tr>");
echo("<td>" . $row["FirstName"] . " " . $row["Lastname"] . "</td>");
echo("<td>" . $row["Item1"] . "</td>");
echo("<td>" . $row["Item2"] . "</td>");
echo("<td>" . $row["Item3"] . "</td>");
echo "</tr>";
}
echo("</table>");
How can I achieve the layout I want?
I would be happy if someone could get me that far. However, I'm wanting to go a step further, so if it makes a difference to how I should approach this, here's what I want to do...
Each table should filter out the unwanted items. So, taking the above example, it would display as:
Name: Joe Bloggs
Item 1: 1
Item 3: 2
Name: Fred Smith
Item2: 1
Can anyone suggest how I could go about this? Any help would be greatly appreciated.
Thanks in advance!