Okay, I'm trying to output data from one table, with only certain instances pulling up data from another table.

On a value of 0 in PriceID, it uses values in the first table; on a value of anything else, it should pull a set of values from the second table.

<?php
$dbcon = mysql_connect("sqlserv","user","pass");
if (!$dbcon)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("exqp_db", $dbcon);

$result = mysql_query("SELECT * FROM itemlist");

while($row = mysql_fetch_array($result))
  {
if ($row['Active'] == "1")
{
$ps = $row['PriceID'];
  echo 
$row['ID'] . " " . 
$row['Name'] . " " . 
$row['Catalog'] . "<br />" . 
$row['SDesc'] . "<br />" . 
$row['LDesc'] . "<br /> ";

	if ($row['PriceID'] == "0"){
	echo
	"$" . $row['Price'] . " Per " . $row['PerA'] . "<br /> $" . 
	$row['PriceB'] . " Per " . $row['PerB'] . "<br />";}
	
	else {

$result = mysql_query("SELECT * FROM pricesets WHERE ID=$ps");

echo "$" . $row['25'] . 
"<br /> $" . echo $row['50'] . 
"<br /> $" . echo $row['75'] . 
"<br /> $" . echo $row['100'] . 
"<br /> $" . echo $row['125'] . 
"<br /> $" . echo $row['150'] . 
"<br /> $" . echo $row['175'] . 
"<br /> $" . echo $row['200'];}

echo
"<br /><a href=" . $row['ImgSrc'] . "><img src=" . $row['ThumbSrc'] . " border=0></a><br />" . 
$row['ModTime'];
  echo "<br />&nbsp;<img src=ddiv.gif>&nbsp;<br />";
}
else echo "";}

mysql_close($dbcon);
?>

Okay, I cleaned out the extra echos, removed the second $result reference, and used Right Join on table1.id=table2.id, but this simply merges the two tables. I want to be able to reference a singular row in the second table from multiple items in the first table, to be referenced by the $ps variable.

<?php
$dbcon = mysql_connect("dbserv","user","pass");
if (!$dbcon)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("exqp_db", $dbcon);

$result = mysql_query("SELECT * FROM itemlist RIGHT JOIN (pricesets) ON (itemlist.ID=pricesets.ID)");

while($row = mysql_fetch_array($result))
  {
if ($row['Active'] == "1")
{
$ps = $row['PriceID'];
  echo 
$row['ID'] . " " . 
$row['Name'] . " " . 
$row['Catalog'] . "<br />" . 
$row['SDesc'] . "<br />" . 
$row['LDesc'] . "<br /> ";

	if ($ps == "0"){
	echo
	"$" . $row['Price'] . " Per " . $row['PerA'] . "<br /> $" . 
	$row['PriceB'] . " Per " . $row['PerB'] . "<br />";}
	
	else {

echo "25 for $" . $row['25'] . 
"<br />50 for $" . $row['50'] . 
"<br />75 for $" . $row['75'] . 
"<br />100 for $" . $row['100'] . 
"<br />125 for $" . $row['125'] . 
"<br />150 for $" . $row['150'] . 
"<br />175 for $" . $row['175'] . 
"<br />200 for $" . $row['200'];}

echo
"<br /><a href=" . $row['ImgSrc'] . "><img src=" . $row['ThumbSrc'] . " border=0></a><br />" . 
$row['ModTime'];
  echo "<br />&nbsp;<img src=ddiv.gif>&nbsp;<br />";
}
else echo "";

}
mysql_close($dbcon);
?>

///rEI

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.