Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP- displaying 2 results on the same page

Status
Not open for further replies.

brandonbob

Technical User
Nov 16, 2000
3
US
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.
 
Have you tried to simply change the query identifier ($result in your case) name?

bye
 
Yes, I tried that too. If you think of any other ideas let me know. Thanks!
 
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 &quot;<table>&quot;;
while ($row =mysql_fetch_row($result1)) {
echo&quot;<tr>&quot;;
echo&quot;<td $row[1] </td>&quot;; /* [1] = Fieldindex */
echo&quot;<td $row[x] </td>&quot;;
....
echo&quot;</tr>&quot;;
}
echo &quot;</table>&quot;;

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

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

I haven't tested this with two querys in the same page but it works very good with one.
Regards
Dietmar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top