Solved

Help needed with converting a query result set into variables.

Posted on 2007-04-05
5
171 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

679 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