I want to pass the value from a mysql fetch array into an sql statement, but not sure of the exact syntax.
Here is my code:
$query = "Select name FROM Category WHERE sectionName='News'"; $result = mysql_query($query); while($row2 = mysql_fetch_array($result)){ echo "Category: ".$row2['name']; $sql_stmnt = "SELECT id,title FROM Content WHERE sectionName='News'"; $results = mysql_query($sql_stmnt); while($row = mysql_fetch_row($results)) { list($id,$title) = $row; print "<br /> <a href='newslist.php?id=$id'> $title</a>"; } print "<br />"; }[/QUOTE] in the $sql_stmnt query i want to pass the value of $row2['name'] as another where clause. I tried, $sql_stmnt = "SELECT id,title FROM Content WHERE sectionName='News' AND name='$row2['name']'"; but get this error Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/cathal/public_html/cms/templates_c/%%10102102B8544%%news.tpl.php on line 25 Its probably a problem with my syntax and ive done some googling but couldnt find anything relevant to my problem. Regards, Cathal
$query = "Select name FROM Category WHERE sectionName='News'"; $result = mysql_query($query);
name
while($row2 = mysql_fetch_array($result)){ echo "Category: ".$row2['name']; $sql_stmnt = "SELECT id,title FROM Content WHERE sectionName='News'"; $results = mysql_query($sql_stmnt); while($row = mysql_fetch_row($results)) { list($id,$title) = $row; print "<br /> <a href='newslist.php?id=$id'> $title</a>"; } print "<br />"; }[/QUOTE]
in the $sql_stmnt query i want to pass the value of $row2['name'] as another where clause. I tried,
$sql_stmnt = "SELECT id,title FROM Content WHERE sectionName='News' AND name='$row2['name']'";
but get this error
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/cathal/public_html/cms/templates_c/%%10102102B8544%%news.tpl.php on line 25
Its probably a problem with my syntax and ive done some googling but couldnt find anything relevant to my problem.
Regards, Cathal
$sql_stmnt = "SELECT id,title FROM Content WHERE sectionName='News' AND name='".$row2['name']."'";
Would be the correct way of writing it.