ulteriormotif
Technical User
I have a series of queries that, according to a number of conditions submitted on a form, only ONE of the queries will execute. That's working fine.
I then put the result of that query into an array. It's only one field that I want, but there will be a variable number of records returned. I THINK that's working, but the output isn't as clean as I expected it to be.
That array I then need to use as criteria in the next query. THAT I am having trouble with.
Can you help please? Firstly, am I putting the data into the array correctly? Secondly, how do I then refer to that array in the following query.
Example follows:
The blkyrs echo out in this case as:
1293
1325
1705
3812
3824
4649
4655
... which is exactly the data I expect to see.
When I check out the array with print_r($gotblkyrs);
I get:
Array ( [0] => Array ( [0] => 1293 [blkyr] => 1293 ) [1] => Array ( [0] => 1325 [blkyr] => 1325 ) [2] => Array ( [0] => 1705 [blkyr] => 1705 ) [3] => Array ( [0] => 3812 [blkyr] => 3812 ) [4] => Array ( [0] => 3824 [blkyr] => 3824 ) [5] => Array ( [0] => 4649 [blkyr] => 4649 ) [6] => Array ( [0] => 4655 [blkyr] => 4655 ) )
I don't know - is that how it should look? Why the duplication of the blkyr values?
The array then needs to be used as criteria in the next query - I need to find the records that match any of the blkyrs in the array:
Which produces the following error:
Error: 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 '''' at line 1
I hope I've explained it clearly enough. Would really appreciate any help.
I then put the result of that query into an array. It's only one field that I want, but there will be a variable number of records returned. I THINK that's working, but the output isn't as clean as I expected it to be.
That array I then need to use as criteria in the next query. THAT I am having trouble with.
Can you help please? Firstly, am I putting the data into the array correctly? Secondly, how do I then refer to that array in the following query.
Example follows:
Code:
<?
$gotblkyrs=array();
//INITIAL QUERY
$getblkyrsquery="SELECT bid AS blkyr FROM blockyear WHERE (various criteria here)";
$getblkyrsquery = mysql_query($getblkyrsquery) or die("Error: " . mysql_error());
if(mysql_num_rows($getblkyrsquery) == 0){
echo("can't identify any appropriate blocks");
} ELSE {
while ($row = mysql_fetch_array($getblkyrsquery)) {
//LOOP THROUGH RESULTS AND PUT INTO ARRAY - HAVE I GOT THIS RIGHT?
array_push($gotblkyrs, $row);
echo $row['blkyr']."<br>";
}
}
?>
The blkyrs echo out in this case as:
1293
1325
1705
3812
3824
4649
4655
... which is exactly the data I expect to see.
When I check out the array with print_r($gotblkyrs);
I get:
Array ( [0] => Array ( [0] => 1293 [blkyr] => 1293 ) [1] => Array ( [0] => 1325 [blkyr] => 1325 ) [2] => Array ( [0] => 1705 [blkyr] => 1705 ) [3] => Array ( [0] => 3812 [blkyr] => 3812 ) [4] => Array ( [0] => 3824 [blkyr] => 3824 ) [5] => Array ( [0] => 4649 [blkyr] => 4649 ) [6] => Array ( [0] => 4655 [blkyr] => 4655 ) )
I don't know - is that how it should look? Why the duplication of the blkyr values?
The array then needs to be used as criteria in the next query - I need to find the records that match any of the blkyrs in the array:
Code:
<?
$getblkyrsquery2="SELECT blockyearid AS blkyr FROM blockyear WHERE blockyear.blockyearid '" . $gotblkyrs[blkyr] . "'";
$getblkyrsquery2 = mysql_query($getblkyrsquery2) or die("Error: " . mysql_error());
if(mysql_num_rows($getblkyrsquery2) == 0){
echo("IMPLODE TEST FAILED");
} ELSE {
while ($row = mysql_fetch_array($getblkyrsquery2)) {
echo $row['blkyr']." - <br>";
}
}
?>
Which produces the following error:
Error: 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 '''' at line 1
I hope I've explained it clearly enough. Would really appreciate any help.