Jump to content


Photo

categorizing the results of an sql statement


  • Please log in to reply
2 replies to this topic

#1 darga333

darga333
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 09 May 2006 - 05:43 AM

I am having a problem displaying the result of my sql statement in groups.

It needs to spit out the first category, then the first business name in that category, then all of the Headlines for that business... then it needs to just loop and do it again for each business in that same category.. and then it needs to move to the next category and repeat the process.

I am only using 1 SQL statement that is relatively simple

$sql_1  = "SELECT t1.sHeadlines,t2.sName,t3.sBusinessname FROM ucfdiscount t1,ucfdiscountcategory t2,ucfmembers t3 WHERE t3.user_id = t1.iMemberId AND t1.iDisCategoryId = t2.idiscategoryid ORDER BY t2.sName, t3.sBusinessname, t1.sHeadlines ASC";

$result_1 = mysql_query($sql_1);
$row_1 = mysql_fetch_array($result_1);
$num33 = mysql_num_rows($result_1);

if ($num33 > 0)  {  
  
          $message =  $row_1['sName']; 
          $message.=  $row_1['sBusinessname']; 
          $message.=  $row_1['sHeadlines']; 

 }

I know I am missing the if statements inside the bracket that will allow me to do this.
Will someone please help me figure this out.
The logic is:

For each Category display category
For each Business Name display business name
For each Headline Display headline

Do i just need 3 different for each statements? Thank you so much for helping me figure this out!

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,167 posts

Posted 09 May 2006 - 07:19 AM

I gave you a solution to this one in your previous post of this question.

[a href=\"http://www.phpfreaks.com/forums/index.php?s=&showtopic=92932&view=findpost&p=371976\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=371976[/a]

Don't double post, you've already had one warning, and if you choose to ignore the solutions offered why bother to post at all?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 darga333

darga333
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 09 May 2006 - 06:08 PM

I apologize for that but I am looking for a solution without Inner Joins and List variables. But thanks for your earlier response, it was much appreciated. Just a bit too confusing for me




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users