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

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.