Solved

Help needed with converting a query result set into variables.

Posted on 2007-04-05
5
165 Views
Last Modified: 2008-03-06
I think what I want to do is possible.  I have the following result set from a query and want to be able to create a comma separated list for each field's result set.

Field1   Field2   Field3
--------------------------
Data1   Name1  Fr
Data2   Name2  Fr

And the desired result is a variable that contains each field's data is a comma separated list

$Field1Var = Data1, Data2
$Field2Var = Name1, Name2
$Field3Var = Fr

Can anyone help me with this?  Thanks!
0
Comment
Question by:Quetysis
  • 3
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 18859840
     $Field1Var = "";
      $Field2Var = "";
      $Field3Var = "";
      
      $query = mysql_query("SELECT * FROM tablename");
      
      $i = $k = $j = 0;
      
      while($row = mysql_fetch_object($query)) {
      
            if(!strstr($Field1Var,$row->Field1)) {
            
                  $Field1Var .= ($i==0?$row->Field1:", ".$row->Field1);
            
                  $i++;
            }
            
            if(!strstr($Field2Var,$row->Field2)) {
            
                  $Field2Var .= ($k==0?$row->Field2:", ".$row->Field2);
            
                  $k++;
            }
            
            if(!strstr($Field3Var,$row->Field3)) {
            
                  $Field3Var .= ($i==0?$row->Field3:", ".$row->Field3);
            
                  $j++;
            }
      
      
      
      
      }
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 18859846
change $Field3Var .= ($i==0?$row->Field3:", ".$row->Field3);

to

$Field3Var .= ($ξ==0?$row->Field3:", ".$row->Field3);
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 18859851
emm lol ..... sorry keyboard switch to greek :)

$Field3Var .= ($j==0?$row->Field3:", ".$row->Field3);
0
 

Author Comment

by:Quetysis
ID: 18859957
Ah!  Thanks steelseth12!  I'm going to try this out and report back to you.
0
 

Author Comment

by:Quetysis
ID: 18860392
That worked beautifully.  Thanks again!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now