Jump to content

Can one db query produce 2 result sets?


Aesop

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/30779-can-one-db-query-produce-2-result-sets/
Share on other sites

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.