Problem:
I am doing a join between 2 tables then trying to display the results. The output should list the the Category name and a description next to it. On the line below that should be a list of 3 stores with pipes in between until the last where the term "more" should be listed. There should then be a blank line then the next category. The problems I am having with the code below:
1) Cateogry 1 has 5 stores, so it is showing category 1 twice then adding another section for the same category with the remaining stores.
2) If the category has less then 3 stores it doesnt add the "more" and doesnt put the blank line.
Current Output:
Category 1 - Category 1 description.
Store 1 | Store 2 | Store 3 | More
Category 1 - Category 1 description.
Store 1 | Store 2 |
Category 2 - Category 2 description.
Store 1 | Store 2 | Store 3 | More
Category 3 - Category 3 description.
Store 1 | Store 2 |
Want to look like:
Category 1 - Category 1 description.
Store 1 | Store 2 | Store 3 | More
Category 2 - Category 2 description.
Store 1 | Store 2 | Store 3 | More
Category 3 - Category 3 description.
Store 1 | Store 2
Code (this is a mess and I am a newbie... no laughing )
Code:
$result = mysql_query("SELECT scat.scatID AS Sid,
scat.scat_name AS Sname,
scat.scat_desc AS Sdesc,
pages.name AS Pname,
pages.pageID as Pid
FROM scat INNER JOIN pages
ON scat.scatID = pages.scat_id
ORDER BY scat.scat_name ASC,
pages.name ASC");
$previous_main = "";
while ($record = mysql_fetch_assoc($result)) {
if ($record["Sname"] != $previous_main) {
echo "<br><b>".$record["Sname"]."</b> - ".$record["Sdesc"].
"<br>";
$loop_count = 0;
}
if ($loop_count > 1) {
echo " <a href='discount-shopping-mall/online_shop.php?online_shop=".$record["Pid"]."'>".
$record["Pname"]."</a> | More<br>";
$previous_main = "";
} else {
echo " <a href='discount-shopping-mall/online_shop.php?online_shop=".$record["Pid"]."'>".
$record["Pname"]."</a> |";
$previous_main = $record["Sname"];
}
$loop_count++;
}
I am doing a join between 2 tables then trying to display the results. The output should list the the Category name and a description next to it. On the line below that should be a list of 3 stores with pipes in between until the last where the term "more" should be listed. There should then be a blank line then the next category. The problems I am having with the code below:
1) Cateogry 1 has 5 stores, so it is showing category 1 twice then adding another section for the same category with the remaining stores.
2) If the category has less then 3 stores it doesnt add the "more" and doesnt put the blank line.
Current Output:
Category 1 - Category 1 description.
Store 1 | Store 2 | Store 3 | More
Category 1 - Category 1 description.
Store 1 | Store 2 |
Category 2 - Category 2 description.
Store 1 | Store 2 | Store 3 | More
Category 3 - Category 3 description.
Store 1 | Store 2 |
Want to look like:
Category 1 - Category 1 description.
Store 1 | Store 2 | Store 3 | More
Category 2 - Category 2 description.
Store 1 | Store 2 | Store 3 | More
Category 3 - Category 3 description.
Store 1 | Store 2
Code (this is a mess and I am a newbie... no laughing )
Code:
$result = mysql_query("SELECT scat.scatID AS Sid,
scat.scat_name AS Sname,
scat.scat_desc AS Sdesc,
pages.name AS Pname,
pages.pageID as Pid
FROM scat INNER JOIN pages
ON scat.scatID = pages.scat_id
ORDER BY scat.scat_name ASC,
pages.name ASC");
$previous_main = "";
while ($record = mysql_fetch_assoc($result)) {
if ($record["Sname"] != $previous_main) {
echo "<br><b>".$record["Sname"]."</b> - ".$record["Sdesc"].
"<br>";
$loop_count = 0;
}
if ($loop_count > 1) {
echo " <a href='discount-shopping-mall/online_shop.php?online_shop=".$record["Pid"]."'>".
$record["Pname"]."</a> | More<br>";
$previous_main = "";
} else {
echo " <a href='discount-shopping-mall/online_shop.php?online_shop=".$record["Pid"]."'>".
$record["Pname"]."</a> |";
$previous_main = $record["Sname"];
}
$loop_count++;
}