Jump to content

Recommended Posts

Hi,

 

I'm not sure if this is possible but hoping someone in here will say it is and show me how.

 

I have a list of suplliers returned from my database, fields include:

 

account name

address 1

address 2

post code and region.

 

I would like to split the data into multiple tables by region and have a header on each table with the region name.

 

This is what i currently have, but that just shows each supplier in one long table.

 

$query  = "SELECT * FROM product_stockist WHERE $cat='Y' ORDER BY Region";

$result = mysql_query($query);

 

$no_of_rows = mysql_num_rows($result);

 

if($no_of_rows > 0){

    echo "<table width=100% align=center callpadding=2 cellspacing=0>";

    echo "</tr>";

}

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

    echo "<tr>";

    echo "<td>{$row['Account_Name']} </td>".

        "<td>{$row['Address_Line_1']} </td>".

        "<td>{$row['Address_Line_2']} </td>".

        "<td>{$row['Address_Line_4']} </td>".

        "<td>{$row['Post_Code']} </td>".

        "<td>{$row['Region']} </td>";

    echo "</tr>";

}

 

echo "</table";

you could do something like this

 

$query  = "SELECT * FROM product_stockist WHERE $cat='Y' ORDER BY Region";

$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

$results[$region]=$row;

}

 

echo "<table>";

foreach($results as $regionname=>$region)

{

    echo "<tr><td>";

    echo "<table width=100% align=center callpadding=2 cellspacing=0>";

    echo "<tr><td colspan='5' align='center'>$regionname</td></tr>";

    foreach($region as $row)

    {

          echo "<tr>";

    echo "<td>{$row['Account_Name']} </td>".

        "<td>{$row['Address_Line_1']} </td>".

        "<td>{$row['Address_Line_2']} </td>".

        "<td>{$row['Address_Line_4']} </td>".

        "<td>{$row['Post_Code']} </td>".

        "<td>{$row['Region']} </td>";

    echo "</tr>"; 

 

    }

    echo "</td></tr></table>";

}

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.