Aesop Posted December 15, 2006 Share Posted December 15, 2006 Hi there,Not sure if this can be done, but I was wondering if one mysql query can produce 2 result sets (if thats the correct terminology). For example;[code]$q = "SELECT col1, col2, col3, col4 FROM table";$result = mysql_query($q);//throw it in a while loop to generate the sets of results while ($row=mysql_fetch_array) { $item1 = $row['col1']; $item2 = $row['col2']; $item3 = $row['col3']; $item4 = $row['col4']; //first set of results that will always show up if (($item1 != '0') && ($item2 == '1')) { echo "$item3<br />"; //second set of results that should also show up } elseif (($item1 != '0') && ($item2 != '1')) { echo "$item4<br />"; } }[/code] That snippet will only produce the first result set but I actually need both. Any suggestions? Quote Link to comment Share on other sites More sharing options...
complex05 Posted December 15, 2006 Share Posted December 15, 2006 I don't really understand what it is you're trying to do. What is the purpose of your elseif statement? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted December 15, 2006 Share Posted December 15, 2006 Either you use 2 queries for 2 result sets or you use 1 query with conditional statements in your code to display different information for each row.[nevermind - I misread something] Quote Link to comment Share on other sites More sharing options...
Aesop Posted December 15, 2006 Author Share Posted December 15, 2006 Sorry for the ambiguity on this. I just got it working but heres the point of my question;This is part of a sessions based membership system I'm doing, and this is on a page that only shows records relevant to the current user thats logged in. This member can see his leads that were generated 2 different ways; one being contacted through the site directly and the other is from an email capturing tool that records email addresses of people sending a page to a friend. Here is the snippet I'm using;[CODE]$pull = "SELECT m.uid, m.umail, l.lid, l.uid, l.lemail, l.lactive, l.lname, l.linactive, l.lfriendmail FROM tblUsers m, tblLeads l WHERE m.uid = l.uid AND m.umail = '$_SESSION[member]' ORDER BY l.lactive ASC";$pulled = mysql_query($pull);$numactive = mysql_num_rows($pulled);echo "<p class=titlebar>$numactive Active Leads</p>"; while ($dt=mysql_fetch_array($pulled)) { $leadname = $dt['lname']; $friend = $dt['lfriendmail']; $sentby = $dt['lfriendsender']; $sentto = $dt['lemail']; $id = $dt['lid']; if (($numactive != '0') && ($friend == '0')){ echo "<ul>"; echo "<li><img src=../images/search.gif width=22 height=22 border=0 alt=><a href=leadprofile.php?id=$id>Assigned Lead: $leadname</a></li>"; echo "</ul>"; } if (($numactive != '0') && ($friend != '0')) { echo "<ul>"; echo "<li><img src=../images/search.gif width=22 height=22 border=0 alt=><a href=leadprofile.php?id=$id>Friend Referral: $sentby</a></li>"; echo "</ul>"; } }}[/CODE]Thanks for the follow up though :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.