Question on Kevin Yanks Book "Build Your Own Website"

In the build your own content management system, Kevin created a Joke table that includes a column for authorid which is taken from the author table.
I got that part to work OK. My question is, how would I go about getting the actual Authors Name to display in the Joke table instead of the ID number which is the primary key of the Author Table and becomes the Foreign key in the Jokes table. I would really like to know if this is even possible. This all has to happen within the confines of a search. The user selects the author from a drop down and then that selection should be displayed in the Joke table that meets the search criteria as the name not the id number.

Much thanks for any help I might recieve

Not everyone buys books so unless you’re prepared to show us your code you might get a very limited response. It would also help to show the structure of the table too.

Tango, here is my code: My trouble is at the bottom. Take a look at the companies array variable. instead of typeid, I would like to just have type. I have a type table with two columns, id and type. I want type to display, not the id number. Thanks. I have other pages that I call using include. Let me know if you need to see them too. thanks for your reply

<?php
error_reporting(E_ALL ^ E_NOTICE);

// Step 1: Display search form. Include 1 to many & many to Many
include $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/inc_db_ciq_connection.php’;

	// Get the basic data from the type table
	$result = mysqli_query($link, 'SELECT id, type FROM type');
	if (!$result)
	{
		$error = 'Error fetching type from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}

	while ($row = mysqli_fetch_array($result))
	{
		$types[] = array('id' =&gt; $row['id'],'type' =&gt; $row['type']);
	}

	// Get the basic data from the company status table
	$result = mysqli_query($link, 'SELECT id, compstatus FROM compstatus');
	if (!$result)
	{
		$error = 'Error fetching compstatus from database!';
		include '../errorfetchingcompstats.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$compstatuss[] = array('id' =&gt; $row['id'],'compstatus' =&gt; $row['compstatus']);
	}
		
	// Get the basic data from the servicstate table
	$result = mysqli_query($link, 'SELECT id, servicestate FROM servicestate');
	if (!$result)
	{
		$error = 'Error fetching state from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$servicestates[] = array('id' =&gt; $row['id'],'servicestate' =&gt; $row['servicestate']);
	}
	
	// Get the basic data from the commodity table
	$result = mysqli_query($link, 'SELECT id, commodity FROM commodity');
	if (!$result)
	{
		$error = 'Error fetching commodity from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$commoditys[] = array('id' =&gt; $row['id'],'commodity' =&gt; $row['commodity']);
	}
	
	// Get the basic data from the LDC table
	$result = mysqli_query($link, 'SELECT id, ldc FROM ldc');
	if (!$result)
	{
		$error = 'Error fetching ldc from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$ldcs[] = array('id' =&gt; $row['id'],'ldc' =&gt; $row['ldc']);
	}
	
		
		
include 'searchform.html.php';

// Step 2: build a list of companies that satisfies the criteria specified in the search form. 1 to 1 and 1 to many

	if (isset($_GET['action']) and $_GET['action'] == 'search')
	
	{
		include $_SERVER['DOCUMENT_ROOT'] . '/includes/inc_db_ciq_connection.php';

		$SELECT = 'SELECT id, name';
		$FROM = ' FROM company';
		$WHERE = ' WHERE 1';
	
// Check each of the possible constraints selected on the search form, and adjust our SQL query. Need to do both 1 to many and many to many!

	//Checking to see if a type was specified in the search query
		$typeid = mysqli_real_escape_string($link, $_GET['type']);
		if ($typeid != '') // A type is selected
		{
			$WHERE .= " AND typeid = '$typeid'";
		}					
	// Checking to see if a status was specified in the search querry
		$compstatusid = mysqli_real_escape_string($link, $_GET['compstatus']);
		if ($compstatusid != '') // A company status is selected
		{
			$WHERE .= " AND compstatusid = '$compstatusid'";
		}
			
	// Checking to see if a service state was specified in the search querry
		$servicestateid = mysqli_real_escape_string($link, $_GET['servicestate']);
		if ($servicestateid != '') // A state is selected
		{
			$FROM .= 'INNER JOIN companystate ON id = companyid ';
			-$WHERE .= " AND servicestateid = '$servicestateid'";
		}
		
	// Checking to see if a commodity was specified in the search querry
		$commodityid = mysqli_real_escape_string($link, $_GET['commodity']);
		if ($commodityid != '') // A state is selected
		if ($commodityid != '') // A state is selected
		{
			$FROM .= 'INNER JOIN companycommodity ON id = companyid ';
			$WHERE .= " AND commodityid = '$commodityid'";
		}
		
	// Checking to see if an LDC was specified in the search querry
		$ldcid = mysqli_real_escape_string($link, $_GET['ldc']);
		if ($ldcid != '') // An LDC is selected
		{
			$FROM .= 'INNER JOIN companyldc ON id = companyid ';
			$WHERE .= " AND ldcid = '$ldcid'";
		}	
		
// Retrieve and display the results.  
	$result = mysqli_query($link, "SELECT * FROM  company $WHERE");
	echo "There are ";
	$NumResults = $result-&gt;num_rows;
	echo "&lt;b&gt;$NumResults companies meeting your search criteria"; 
	if (!$result)
	{
		$error = 'Error fetching companies.';
		include '../erronomatches.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$companies[] = array('id' =&gt; $row['id'], 'typeid' =&gt; $row['typeid'],'compstatusid' =&gt; $row['compstatusid'],  'name' =&gt; $row['name'],'address' =&gt; $row['address'], 'city' =&gt; $row['city'], 'state' =&gt; $row['state'],'zip' =&gt; $row['zip'], 'signatory' =&gt; $row['signatory'], 'designation' =&gt; $row['designation']);
	}
		include 'companies.html.php';
	exit();
	}

:)Tango, here is my code: My trouble is at the bottom. Take a look at the companies array variable. instead of typeid, I would like to just have type. I have a type table with two columns, id and type. I want type to display, not the id number. Thanks. I have other pages that I call using include. Let me know if you need to see them too. thanks for your reply

<?php
error_reporting(E_ALL ^ E_NOTICE);

// Step 1: Display search form. Include 1 to many & many to Many
include $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/inc_db_ciq_connection.php’;

	// Get the basic data from the type table
	$result = mysqli_query($link, 'SELECT id, type FROM type');
	if (!$result)
	{
		$error = 'Error fetching type from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}

	while ($row = mysqli_fetch_array($result))
	{
		$types[] = array('id' =&gt; $row['id'],'type' =&gt; $row['type']);
	}

	// Get the basic data from the company status table
	$result = mysqli_query($link, 'SELECT id, compstatus FROM compstatus');
	if (!$result)
	{
		$error = 'Error fetching compstatus from database!';
		include '../errorfetchingcompstats.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$compstatuss[] = array('id' =&gt; $row['id'],'compstatus' =&gt; $row['compstatus']);
	}
		
	// Get the basic data from the servicstate table
	$result = mysqli_query($link, 'SELECT id, servicestate FROM servicestate');
	if (!$result)
	{
		$error = 'Error fetching state from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$servicestates[] = array('id' =&gt; $row['id'],'servicestate' =&gt; $row['servicestate']);
	}
	
	// Get the basic data from the commodity table
	$result = mysqli_query($link, 'SELECT id, commodity FROM commodity');
	if (!$result)
	{
		$error = 'Error fetching commodity from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$commoditys[] = array('id' =&gt; $row['id'],'commodity' =&gt; $row['commodity']);
	}
	
	// Get the basic data from the LDC table
	$result = mysqli_query($link, 'SELECT id, ldc FROM ldc');
	if (!$result)
	{
		$error = 'Error fetching ldc from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$ldcs[] = array('id' =&gt; $row['id'],'ldc' =&gt; $row['ldc']);
	}
	
		
		
include 'searchform.html.php';

// Step 2: build a list of companies that satisfies the criteria specified in the search form. 1 to 1 and 1 to many

	if (isset($_GET['action']) and $_GET['action'] == 'search')
	
	{
		include $_SERVER['DOCUMENT_ROOT'] . '/includes/inc_db_ciq_connection.php';

		$SELECT = 'SELECT id, name';
		$FROM = ' FROM company';
		$WHERE = ' WHERE 1';
	
// Check each of the possible constraints selected on the search form, and adjust our SQL query. Need to do both 1 to many and many to many!

	//Checking to see if a type was specified in the search query
		$typeid = mysqli_real_escape_string($link, $_GET['type']);
		if ($typeid != '') // A type is selected
		{
			$WHERE .= " AND typeid = '$typeid'";
		}					
	// Checking to see if a status was specified in the search querry
		$compstatusid = mysqli_real_escape_string($link, $_GET['compstatus']);
		if ($compstatusid != '') // A company status is selected
		{
			$WHERE .= " AND compstatusid = '$compstatusid'";
		}
			
	// Checking to see if a service state was specified in the search querry
		$servicestateid = mysqli_real_escape_string($link, $_GET['servicestate']);
		if ($servicestateid != '') // A state is selected
		{
			$FROM .= 'INNER JOIN companystate ON id = companyid ';
			-$WHERE .= " AND servicestateid = '$servicestateid'";
		}
		
	// Checking to see if a commodity was specified in the search querry
		$commodityid = mysqli_real_escape_string($link, $_GET['commodity']);
		if ($commodityid != '') // A state is selected
		if ($commodityid != '') // A state is selected
		{
			$FROM .= 'INNER JOIN companycommodity ON id = companyid ';
			$WHERE .= " AND commodityid = '$commodityid'";
		}
		
	// Checking to see if an LDC was specified in the search querry
		$ldcid = mysqli_real_escape_string($link, $_GET['ldc']);
		if ($ldcid != '') // An LDC is selected
		{
			$FROM .= 'INNER JOIN companyldc ON id = companyid ';
			$WHERE .= " AND ldcid = '$ldcid'";
		}	
		
// Retrieve and display the results.  
	$result = mysqli_query($link, "SELECT * FROM  company $WHERE");
	echo "There are ";
	$NumResults = $result-&gt;num_rows;
	echo "&lt;b&gt;$NumResults companies meeting your search criteria"; 
	if (!$result)
	{
		$error = 'Error fetching companies.';
		include '../erronomatches.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$companies[] = array('id' =&gt; $row['id'], 'typeid' =&gt; $row['typeid'],'compstatusid' =&gt; $row['compstatusid'],  'name' =&gt; $row['name'],'address' =&gt; $row['address'], 'city' =&gt; $row['city'], 'state' =&gt; $row['state'],'zip' =&gt; $row['zip'], 'signatory' =&gt; $row['signatory'], 'designation' =&gt; $row['designation']);
	}
		include 'companies.html.php';
	exit();
	}

Ok, heres a couple of requirements:
First please wrap code in

 and [/ php] tags (delete the space for the tag with the / in it). It makes it easier for us to understand like this:


```php

$String = 'this is coloured differently';

Secondly please don’t double post.
Thirdly please put comments in the code in the specific area where your problem is because you have posted a lot of code. It would be nice to get straight to that particular area.
Finally please show the structure of the table you are using. Also from what you are saying it sounds as if you’re using more than one table? - Please confirm.

You can show us the table structure like this:

¦id¦name¦address
¦1¦joe¦someroad
¦2¦etc¦somewhere

You don’t need to include sample data, just names of columns.

If you don’t help us to understand we can’t help.

I wasn’t sure if you needed the square brackets around the php. Yes, I have multilple tables. This code is for a relational database. The company table gets data from the type table (and others) via selecting from drop down lists. Look below for the company variable at the bottom. I flagged it for you using ################### The companies variable contains typeid which displays integers. I want to display the cooresponding type as a string.
My type table has this structure:
¦id¦type¦
¦1 ¦ commercial ¦
¦2 ¦ residential ¦

php
error_reporting(E_ALL ^ E_NOTICE);

// Step 1: Display search form. Include 1 to many & many to Many
include $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/inc_db_ciq_connection.php’;

	// Get the basic data from the type table
	$result = mysqli_query($link, 'SELECT id, type FROM type');
	if (!$result)
	{
		$error = 'Error fetching type from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}

	while ($row = mysqli_fetch_array($result))
	{
		$types[] = array('id' =&gt; $row['id'],'type' =&gt; $row['type']);
	}

	// Get the basic data from the company status table
	$result = mysqli_query($link, 'SELECT id, compstatus FROM compstatus');
	if (!$result)
	{
		$error = 'Error fetching compstatus from database!';
		include '../errorfetchingcompstats.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$compstatuss[] = array('id' =&gt; $row['id'],'compstatus' =&gt; $row['compstatus']);
	}
		
	// Get the basic data from the servicstate table
	$result = mysqli_query($link, 'SELECT id, servicestate FROM servicestate');
	if (!$result)
	{
		$error = 'Error fetching state from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$servicestates[] = array('id' =&gt; $row['id'],'servicestate' =&gt; $row['servicestate']);
	}
	
	// Get the basic data from the commodity table
	$result = mysqli_query($link, 'SELECT id, commodity FROM commodity');
	if (!$result)
	{
		$error = 'Error fetching commodity from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$commoditys[] = array('id' =&gt; $row['id'],'commodity' =&gt; $row['commodity']);
	}
	
	// Get the basic data from the LDC table
	$result = mysqli_query($link, 'SELECT id, ldc FROM ldc');
	if (!$result)
	{
		$error = 'Error fetching ldc from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$ldcs[] = array('id' =&gt; $row['id'],'ldc' =&gt; $row['ldc']);
	}
	
		
		
include 'searchform.html.php';

// Step 2: build a list of companies that satisfies the criteria specified in the search form. 1 to 1 and 1 to many

	if (isset($_GET['action']) and $_GET['action'] == 'search')
	
	{
		include $_SERVER['DOCUMENT_ROOT'] . '/includes/inc_db_ciq_connection.php';

		$SELECT = 'SELECT id, name';
		$FROM = ' FROM company';
		$WHERE = ' WHERE 1';
	
// Check each of the possible constraints selected on the search form, and adjust our SQL query. Need to do both 1 to many and many to many!

	//Checking to see if a type was specified in the search query
		$typeid = mysqli_real_escape_string($link, $_GET['type']);
		if ($typeid != '') // A type is selected
		{
			$WHERE .= " AND typeid = '$typeid'";
		}					
	// Checking to see if a status was specified in the search querry
		$compstatusid = mysqli_real_escape_string($link, $_GET['compstatus']);
		if ($compstatusid != '') // A company status is selected
		{
			$WHERE .= " AND compstatusid = '$compstatusid'";
		}
			
	// Checking to see if a service state was specified in the search querry
		$servicestateid = mysqli_real_escape_string($link, $_GET['servicestate']);
		if ($servicestateid != '') // A state is selected
		{
			$FROM .= 'INNER JOIN companystate ON id = companyid ';
			-$WHERE .= " AND servicestateid = '$servicestateid'";
		}
		
	// Checking to see if a commodity was specified in the search querry
		$commodityid = mysqli_real_escape_string($link, $_GET['commodity']);
		if ($commodityid != '') // A state is selected
		if ($commodityid != '') // A state is selected
		{
			$FROM .= 'INNER JOIN companycommodity ON id = companyid ';
			$WHERE .= " AND commodityid = '$commodityid'";
		}
		
	// Checking to see if an LDC was specified in the search querry
		$ldcid = mysqli_real_escape_string($link, $_GET['ldc']);
		if ($ldcid != '') // An LDC is selected
		{
			$FROM .= 'INNER JOIN companyldc ON id = companyid ';
			$WHERE .= " AND ldcid = '$ldcid'";
		}	
		
// Retrieve and display the results.  
	$result = mysqli_query($link, "SELECT * FROM  company $WHERE");
	echo "There are ";
	$NumResults = $result-&gt;num_rows;
	echo "&lt;b&gt;$NumResults companies meeting your search criteria"; 
	if (!$result)
	{
		$error = 'Error fetching companies.';
		include '../erronomatches.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{

###################

		$companies[] = array('id' =&gt; $row['id'], 'typeid' =&gt; $row['typeid'],'compstatusid' =&gt; $row['compstatusid'],  'name' =&gt; $row['name'],'address' =&gt; $row['address'], 'city' =&gt; $row['city'], 'state' =&gt; $row['state'],'zip' =&gt; $row['zip'], 'signatory' =&gt; $row['signatory'], 'designation' =&gt; $row['designation']);
	}
		include 'companies.html.php';
	exit();
	}

/PHP

Sorry for double posting. It wasn’t intentional. It didn’t seem to take so I double clicked again and then it went through but twice. Sorry. Now It is doing it again. So I hope it doesn’t post twice again.

I wasn’t sure if you needed the square brackets around the php. Yes, I have multilple tables. This code is for a relational database. The company table gets data from the type table (and others) via selecting from drop down lists. Look below for the company variable at the bottom. I flagged it for you using ################### The companies variable contains id which displays integers. I want to display the cooresponding type as a string.
My type table has this structure:
¦id¦type¦
¦1 ¦ commercial ¦
¦2 ¦ residential ¦

php
error_reporting(E_ALL ^ E_NOTICE);

// Step 1: Display search form. Include 1 to many & many to Many
include $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/inc_db_ciq_connection.php’;

	// Get the basic data from the type table
	$result = mysqli_query($link, 'SELECT id, type FROM type');
	if (!$result)
	{
		$error = 'Error fetching type from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}

	while ($row = mysqli_fetch_array($result))
	{
		$types[] = array('id' =&gt; $row['id'],'type' =&gt; $row['type']);
	}

	// Get the basic data from the company status table
	$result = mysqli_query($link, 'SELECT id, compstatus FROM compstatus');
	if (!$result)
	{
		$error = 'Error fetching compstatus from database!';
		include '../errorfetchingcompstats.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$compstatuss[] = array('id' =&gt; $row['id'],'compstatus' =&gt; $row['compstatus']);
	}
		
	// Get the basic data from the servicstate table
	$result = mysqli_query($link, 'SELECT id, servicestate FROM servicestate');
	if (!$result)
	{
		$error = 'Error fetching state from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$servicestates[] = array('id' =&gt; $row['id'],'servicestate' =&gt; $row['servicestate']);
	}
	
	// Get the basic data from the commodity table
	$result = mysqli_query($link, 'SELECT id, commodity FROM commodity');
	if (!$result)
	{
		$error = 'Error fetching commodity from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$commoditys[] = array('id' =&gt; $row['id'],'commodity' =&gt; $row['commodity']);
	}
	
	// Get the basic data from the LDC table
	$result = mysqli_query($link, 'SELECT id, ldc FROM ldc');
	if (!$result)
	{
		$error = 'Error fetching ldc from database!';
		include '../errorfetchingbasics.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{
		$ldcs[] = array('id' =&gt; $row['id'],'ldc' =&gt; $row['ldc']);
	}
	
		
		
include 'searchform.html.php';

// Step 2: build a list of companies that satisfies the criteria specified in the search form. 1 to 1 and 1 to many

	if (isset($_GET['action']) and $_GET['action'] == 'search')
	
	{
		include $_SERVER['DOCUMENT_ROOT'] . '/includes/inc_db_ciq_connection.php';

		$SELECT = 'SELECT id, name';
		$FROM = ' FROM company';
		$WHERE = ' WHERE 1';
	
// Check each of the possible constraints selected on the search form, and adjust our SQL query. Need to do both 1 to many and many to many!

	//Checking to see if a type was specified in the search query
		$typeid = mysqli_real_escape_string($link, $_GET['type']);
		if ($typeid != '') // A type is selected
		{
			$WHERE .= " AND typeid = '$typeid'";
		}					
	// Checking to see if a status was specified in the search querry
		$compstatusid = mysqli_real_escape_string($link, $_GET['compstatus']);
		if ($compstatusid != '') // A company status is selected
		{
			$WHERE .= " AND compstatusid = '$compstatusid'";
		}
			
	// Checking to see if a service state was specified in the search querry
		$servicestateid = mysqli_real_escape_string($link, $_GET['servicestate']);
		if ($servicestateid != '') // A state is selected
		{
			$FROM .= 'INNER JOIN companystate ON id = companyid ';
			-$WHERE .= " AND servicestateid = '$servicestateid'";
		}
		
	// Checking to see if a commodity was specified in the search querry
		$commodityid = mysqli_real_escape_string($link, $_GET['commodity']);
		if ($commodityid != '') // A state is selected
		if ($commodityid != '') // A state is selected
		{
			$FROM .= 'INNER JOIN companycommodity ON id = companyid ';
			$WHERE .= " AND commodityid = '$commodityid'";
		}
		
	// Checking to see if an LDC was specified in the search querry
		$ldcid = mysqli_real_escape_string($link, $_GET['ldc']);
		if ($ldcid != '') // An LDC is selected
		{
			$FROM .= 'INNER JOIN companyldc ON id = companyid ';
			$WHERE .= " AND ldcid = '$ldcid'";
		}	
		
// Retrieve and display the results.  
	$result = mysqli_query($link, "SELECT * FROM  company $WHERE");
	echo "There are ";
	$NumResults = $result-&gt;num_rows;
	echo "&lt;b&gt;$NumResults companies meeting your search criteria"; 
	if (!$result)
	{
		$error = 'Error fetching companies.';
		include '../erronomatches.html.php';
		exit();
	}
	while ($row = mysqli_fetch_array($result))
	{

###################

		$companies[] = array('id' =&gt; $row['id'], 'typeid' =&gt; $row['typeid'],'compstatusid' =&gt; $row['compstatusid'],  'name' =&gt; $row['name'],'address' =&gt; $row['address'], 'city' =&gt; $row['city'], 'state' =&gt; $row['state'],'zip' =&gt; $row['zip'], 'signatory' =&gt; $row['signatory'], 'designation' =&gt; $row['designation']);
	}
		include 'companies.html.php';
	exit();
	}

/PHP

Sorry for double posting. It didn’t seem to take so I double clicked again and then it went through but twice. Sorry.

Yes, I have multilple tables. This code is for a relational database. The company table gets data from the type table (and others) via selecting from drop down lists. Look below for the company variable at the bottom. I flagged it for you using ################### The companies variable contains id which displays integers. I want to display the cooresponding type as a string within the company table.
My company table has this structure:
¦id¦typeid¦name¦address…

My type table has this structure:
¦id¦type¦

php

//Checking to see if a type was specified in the search query
$typeid = mysqli_real_escape_string($link, $_GET[‘type’]);
if ($typeid != ‘’) // A type is selected
{
$WHERE .= " AND typeid = ‘$typeid’";
}

// Retrieve and display the results.
$result = mysqli_query($link, “SELECT * FROM company $WHERE”);
echo "There are ";
$NumResults = $result->num_rows;
echo “<b>$NumResults companies meeting your search criteria”;
if (!$result)
{
$error = ‘Error fetching companies.’;
include ‘…/erronomatches.html.php’;
exit();
}
while ($row = mysqli_fetch_array($result))
{
###################
$companies = array(‘id’ => $row[‘id’], ‘typeid’ => $row[‘typeid’],‘compstatusid’ => $row[‘compstatusid’], ‘name’ => $row[‘name’],‘address’ => $row[‘address’], ‘city’ => $row[‘city’], ‘state’ => $row[‘state’],‘zip’ => $row[‘zip’], ‘signatory’ => $row[‘signatory’], ‘designation’ => $row[‘designation’]);
}
include ‘companies.html.php’;
/php

Sorry for double posting. It didn’t seem to take so I double clicked again and then it went through but twice. Sorry. I just realized I can use the preview post to make sure the code is colored. I know it seems stupid but I got hung up on that. Thanks for your patience.

Yes, I have multilple tables. This code is for a relational database. The company table gets data from the type table (and others) via selecting from drop down lists. Look below for the company variable at the bottom. I flagged it for you using ################### The companies variable contains id which displays integers. I want to display the cooresponding type as a string within the company table in the typeid field.
My company table has this structure:
¦id¦typeid¦name¦address…

My type table has this structure:
¦id¦type¦



//Checking to see if a type was specified in the search query
			$typeid = mysqli_real_escape_string($link, $_GET['type']);
			if ($typeid != '') // A type is selected
			{
				$WHERE .= " AND typeid = '$typeid'";
			}					


// Retrieve and display the results.  
		$result = mysqli_query($link, "SELECT * FROM  company $WHERE");
		echo "There are ";
		$NumResults = $result->num_rows;
		echo "<b>$NumResults companies meeting your search criteria"; 
		if (!$result)
		{
			$error = 'Error fetching companies.';
			include '../erronomatches.html.php';
			exit();
		}
		while ($row = mysqli_fetch_array($result))
		{
################### 
			$companies[] = array('id' => $row['id'], 'typeid' => $row['typeid'],'compstatusid' => $row['compstatusid'],  'name' => $row['name'],'address' => $row['address'], 'city' => $row['city'], 'state' => $row['state'],'zip' => $row['zip'], 'signatory' => $row['signatory'], 'designation' => $row['designation']);
		}
			include 'companies.html.php';

Now you’ve posted that FIVE times. You could at least modify/edit the duplicates and hit delete.

Secondly please would you use the php tags as I’ve asked. All you’ve done is written php at the top of your code without the surrounding them.

I have clearly demonstrated how to use them and I’ve asked you not to double post. Instead you do the total opposite of use the php tags and then post FIVE times.

Unless you start to comply I won’t reply any further to this topic and looking at the mess you’ve made here so far neither will anyone else. A bit of effort goes a long way but you’ve not even been bothered to delete your own duplicates.

I am really sorry that I have been so stupid. Is it possible for me to delete my posts? I don’t see a delete button except on the new ones.

No, too late. Thats what happens when you don’t review what you’ve posted. You can’t delete now, the forum only gives you 10-15minutes to edit/delete your post.

Lets start again. Please post your entire code in php tags - but in a NEW topic -not this one. That way we can avoid all the junk in between :wink: