Solved

Help needed with converting a query result set into variables.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

920 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

11 Experts available now in Live!

Get 1:1 Help Now