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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.