Jump to content

Database Querying


Schlo_50

Recommended Posts

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  ???

Link to comment
https://forums.phpfreaks.com/topic/72422-database-querying/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.