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
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 :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.