Jump to content

pulling coresponding data from tables


hellonoko

Recommended Posts

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

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.