Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help needed with converting a query result set into variables.

Posted on 2007-04-05
5
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

670 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