Schlo_50 Posted October 9, 2007 Share Posted October 9, 2007 Hi guys, Heres my problem: Im currently working on a project whereby i am using 'open database connectivity' to display items on my webage from my MS Access database. The tutorial displayed on PHPFreaks has been a tremendous help however as a php beginner (still) im having problems querying my access database in the way that i want. What im trying to do: I have two tables (category.tbl and product.tbl) which both contain 'CategoryId' as the foriegn key. What i need is some PHP code to query the database in a way which displays a category and then a list of associated products, followed by another category and then that ones associated products. E.g. Category Product Product Category Product Product Product Product So far i am using this technique to display my database information on a page, although it's not suitable for the organisation that i require. Could somone help me please! I've been trying to google this for ages and am now on my knees begging! lol <?php require_once('odbc/odbc.php'); $query = odbc_exec($odbc, "SELECT * FROM category1") or die (odbc_errormsg()); while($row = odbc_fetch_array($query)) { echo 'Category Number: '.$row['CategoryId'].'<br />'; echo 'Category Name: '.$row['CategoryName'].'<br />'; echo '<hr />'; } odbc_close($odbc); ?> <br /> <br /> <?php require_once('odbc/odbc.php'); $query = odbc_exec($odbc, "SELECT * FROM Product1") or die (odbc_errormsg()); while($row = odbc_fetch_array($query)) { echo 'Product Number: '.$row['ProductId'].'<br />'; echo 'Price: '.$row['Price'].'<br />'; echo '<hr />'; } odbc_close($odbc); ?> Thanks very much for anyones help in this matter ??? Quote Link to comment https://forums.phpfreaks.com/topic/72422-database-querying/ Share on other sites More sharing options...
Barand Posted October 9, 2007 Share Posted October 9, 2007 see http://www.phpfreaks.com/forums/index.php/topic,100662.0.html Quote Link to comment https://forums.phpfreaks.com/topic/72422-database-querying/#findComment-365218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.