View Single Post
Old 10-31-2004   #1 (permalink)
MrProtoman
Registered User
 
MrProtoman's Avatar
 
Join Date: Aug 2004
Location: Evansville, IN
Posts: 70

Send a message via ICQ to MrProtoman Send a message via AIM to MrProtoman Send a message via MSN to MrProtoman Send a message via Yahoo to MrProtoman
PHP/mySQL tables

Okay, I'm working on a links page for my site, and I'm trying to divide the links into catagories. I'm trying two tables here. One is the links themselves, and the other is the catagories, set up like this.
links:
ID | Cat | Title | URL | Date | Hits
links_cat:
ID | Title

What I'm wanting to do is read the links table, match links.cat to links_cat.id, and return links_cat.title. Here's the PHP so far (no referencing)
Code:
<?php 
$db = mysql_connect("localhost","username","password"); 
mysql_select_db ("database"); 
$result = mysql_query("SELECT * FROM links"); 
echo "<table border='1' align='center'>"; 
echo "<th>ID#</th><th>Catagory</th><th>Link</th><th>Date</th><th>Hits</th>";
while ($rows = mysql_fetch_array($result)) 
{ 
echo "<tr><td>$rows[id]</td><td>$rows[cat]</td><td><a href=out.php?id=$rows[id]>$rows[title]</a></td><td>$rows[date]</td><td>$rows[hits]</td></tr>"; 
}  
echo "</table>"; 
?>
I've found some listings for JOIN and CROSS, though the documentation doesn't make a lot of sense to me for some reason. It just seams to be looking for listings that exist in both tables, not using two id's to get other info.
You'll have to forgive the links display formatting. Working code first, then pretty output.
__________________
MrProtoman is offline