Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/mySql problems

Status
Not open for further replies.

bubbapuck

Programmer
Mar 5, 2005
1
0
0
US
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++;
}
 
can you post the create statements for your two tables.
 
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,


error perhaps: pages.scat_id

I need to see both of the tables to get a better understanding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top