Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

PHP- displaying 2 results on the same page

PHP- displaying 2 results on the same page

PHP- displaying 2 results on the same page

I apologize for asking what is probably a simple question, but I have been unable to find relief for my headache!

I am attempting to display the results of 2 'select' queries in 2 separate tables on the same page.  I am using

For both queries I use:

1) $result= mysql_query(SELECT...)
2) while ($myrow = mysql_fetch_array($result)
3) table definition with $myrow('fieldname')
4) mysql_free_result

I can run both of the 2 independently without any problems.  However, when I try to get them both to work at the same time, the first table vanishes and all the results are stored in the second table.  I have tried each of the following so far:

1) changing the varaible on the 2nd query to $myrow2
2) separating the 2nd query into its own function
3) separating the 2nd query into its own script

Can someone help me out?  Thanks in advance for any assistance.

RE: PHP- displaying 2 results on the same page

Have you tried to simply change the query identifier ($result in your case) name?


RE: PHP- displaying 2 results on the same page

Yes, I tried that too.  If you think of any other ideas  let me know.  Thanks!

RE: PHP- displaying 2 results on the same page

probably you have to define where each table starts and ends.
like this

/* start first query */
$result=mysql_query($sqlquery1, $conn);   

/* table for 1st query */
       echo "<table>";
    while ($row =mysql_fetch_row($result1)) {
                  echo"<td $row[1] </td>"; /* [1] = Fieldindex */
                  echo"<td $row[x] </td>";
       echo "</table>";

/* start second query */
$result=mysql_query($sqlquery2, $conn);   

/* table for 2nd query */
       echo "<table>";
    while ($row =mysql_fetch_row($result)) {
                  echo"<td $row[1] </td>"; /* [1] = Fieldindex */
                  echo"<td $row[x] </td>";
       echo "</table>";

I haven't tested this with two querys in the same page but it works very good with one.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close