DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   mysql_fetch_array for multiple tables (http://www.daniweb.com/forums/thread120808.html)

webguru07 Apr 24th, 2008 11:58 am
mysql_fetch_array for multiple tables
 
I need to get information from 2 tables in the same mysql database

$sql = mysql_query("SELECT * FROM notes, customers WHERE `to`='next' LIMIT 5");

                  while($a = mysql_fetch_array($sql)){
                   
                    $row_color = ($row_count % 2) ? "#EFEFEF" : "#FFFFFF";
                   
                          echo("<tr bgcolor=\"$row_color\">
    <td height=\"25\">" . $a['custid'] . "</td>
    <td height=\"25\">" . $a['name'] . "</td>
    <td>" . $a['ebay'] . "</td>
        <td>" . $a['title'] . "</td>
        <td>" . $a['type'] . "</td>
</tr>");
               
                        $row_count++;
                  }

The name and ebay fields are in the customer table and the rest are in the notes table. The code above doesnt produce any error just no rows are displayed

scru Apr 24th, 2008 1:21 pm
Re: mysql_fetch_array for multiple tables
 
you cant query two tables aat once. Either do them one at a time or make a stored procedure. I don't know anything about mysql so I cant help with the stored procedure.

prethum Apr 24th, 2008 4:05 pm
Re: mysql_fetch_array for multiple tables
 
is the talbes realted to each othere and the primary key of one table should be the foreign of the other tbale that u are trying to get datafrom
if soo
then you can use join
select from note, coustomers where note.id =costomer.id and to = 'next';
u can get more information on this from
http://www.tizag.com/mysqlTutorial/mysqljoins.php


All times are GMT -4. The time now is 11:52 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC