Forums

PHP

This topic is locked

mysql_query in a for loop

Posted 22 Sep 2003 18:48:57
1
has voted
22 Sep 2003 18:48:57 Jason Baxter posted:
I have a mysql table with a column for subscription types called Topic. The info in the column is an array divided by commas (kids, youth, couples, etc...). I'm trying to explode the array ($SubTypes), then query (select) each result in a different table, and then print both the first exploded array and it's results from the query. Below is my code.


if($Subscription) {
$SubType = $Subscription;
$SubTypes = explode("," , $SubType);
for ($x = 0; $x < count($SubTypes); $x++) {
$SubQuery = mysql_query("SELECT * FROM EmailBodyDB WHERE Topic LIKE '$SubTypes[$x]'";
$SubAnswer = mysql_fetch_assoc($SubQuery);
$Content[$x] = $SubAnswer[Content];
if($SubTypes[$x]) {
echo "<p>",$SubTypes[$x],"<br>",$Content[$x],"</p>";
}
}
}

What I get is the first exploded array ($SubType) and it's $Content, and the other arrays ($SubType) with no $Content.

Any advice?

Reply to this topic