If it matters, my server is running php v 5.
This snippet of code is part of a larger page which works fine on its on. Here's what I can successfully display when I insert this snippet of code:
<?
$wkrpcodesearch= mysql_query("SELECT catwkrps FROM category WHERE lcat_id='$cat'") or die(mysql_error()); // fetches numerical data example '100,101'
while($row = mysql_fetch_array($wkrpcodesearch))
{extract($row);
$catwkrpsnew = $catwkrps;}
$cat_rev_codes = array($catwkrpsnew); //displaying as an array the list of wkrps associated with a category number
foreach($cat_rev_codes as $code)
{
print " $code, ";
}
?>
The result will print '100, 101, ' which is successful.
What I want to do is to be able to perform a query within the loop to get additional info related to '100' and '101'. For example, I want to search table 'wkrp' where '100' equals 'wkrpcode' and display two pieces of related info, 'wkrp_name' and 'wkrp_url' and then display them in a html text link.
So here's what I came up with:
<?
$search1= mysql_query("SELECT catwkrps FROM category WHERE lcat_id='$cat'") or die(mysql_error());
while($row = mysql_fetch_array($search1))
{extract($row);
$catwkrps = $row["catwkrps"];
$cat_rev_codes = array($catwkrps); //displaying as an array, the list of wkrps associated with a category number
foreach($cat_rev_codes as $code)
{
$search2 = mysql_query("SELECT wkrp_name, wkrp_url FROM wkrp WHERE wkrpcode = '$code'") or die(mysql_error());
while($row = mysql_fetch_array ($search2))
{extract($row);
$wkrp_name = $row["wkrp_name"];
$wkrp_url = $row["wkrp_url"];
print "<a href='$wkrp_url' alt='Visit this link for more info.'>$wkrp_name</a>";
}
}
}
?>
But I get the following error message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '101' at line 1
I've been scratching my head over this one since yesterday. Can anybody help out? Thanks in advance.