hellonoko Posted February 18, 2007 Share Posted February 18, 2007 I have two tables. One is a list of URLs and information about them uniqueID/url/categoryCode/description The other is the different categories uniqueID/name I am trying to go through my list of URLS and dispay the correstponding category name For example if i have the URL www.phpfreaks.net in my urls table and its categoryID is 4 I want to the reference to my category table and if one of the fields id # is 4 which represents.. Web Design. I want to be able to display Web Design rather than 4. Below is my code wich I am sure is not the best way to do it and for some reason it only works for the first item. <?php include 'dbconnect.php'; $query = "SELECT * FROM urls"; $result = mysql_query($query); $rows = mysql_num_rows($result); $c_query = "SELECT * FROM categories"; $c_result = mysql_query($c_query); $c_rows = mysql_num_rows($c_result); for ($i=0; $i <$rows; $i++) { $row = mysql_fetch_array($result); //echo $category_result; //$id_from_url_info = 10; for ($c=0; $c <$c_rows; $c++) { $c_row = mysql_fetch_array($c_result); if ( $row[category] == $c_row[id]) { echo $c_row[category]; } } echo $row[category]; echo "<br>"; echo $row[url]; echo "<br>"; echo $row[description]; echo "<br><br>"; } ?> Here is one example someone gave me. But that would only return a blank page. <?php include 'dbconnect.php'; $sql="SELECT * FROM urls, categories WHERE categories.id = urls.category"; $result = mysql_query($sql); while($row = mysql_fetch_array($result )) { echo $row['category']; echo "<br>"; echo $row['name']; echo "<br>"; echo $row['url']; } ?> Any ideas? Thanks, Ian Quote Link to comment 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.