How to select data from 2 tables by id

kitty_go_bark

New Member
I have a script to get data from a table and export to xml, but i need to get the data from 2 different tables.\[code\]Table 1: Productsi have inside:id codeTable 2: Stocki have insideid qty\[/code\]my script is:\[code\]<?php $db_host = "localhost"; $db_name = "test"; $db_username = "root"; $db_password = ""; $dbh = mysql_connect($db_host, $db_username, $db_password) or die("Unable to connect to MySQL"); mysql_query('SET NAMES "utf8"'); mysql_select_db($db_name, $dbh) or die("Could not select $db_name"); $sql = "select * from products "; $q = mysql_query($sql); $custom = '"'; $xml = "\n"; $xml .= "<XML>\n"; while($r = mysql_fetch_assoc($q)) { $xml .= " <PRODUCT code=$custom " . $r["code"] . "$cusmot qty=$custom " . $r["qty"] . "$custom />\n"; } $xml .= "</XML>"; header("Content-type: text/xml"); echo $xml;?>\[/code\]Need help to get the qty from Stock result according the id on Products table.Any help is welcome.
 
Back
Top