Thanks for the reply. I'm just beginning in PHP. I still have a problem and hope someone can help. In the code below, if the SELECT query does not contain && assn ='$value', then everything works. I am trying to run the query for every $value in the array and each time determine the number of $rows for each query result. $rows is added to $total each time to keep a running count of number of rows.
When I run the code below, the ECHO runs for as many times as the FOREACH runs, and $total always is zero. I suspect I have an error in the SELECT statement.
I've checked to make sure the array is valid by echoing $key and $value, and the database has records that meet the query criteria so the query should produce results.
Thanks in advance.
Code:
<?php
$dbc = mysql_connect('xxxx', 'yyyy','xxxx')
or die('Error connecting to MySQL server.');
mysql_select_db('mydb');
// Number of closed condo sales for 7-12 months prior to effective date
$total = 0;
foreach ($_POST['condo'] as $key => $value){
$results = mysql_query("select * from compsin where cldate > '$effdate365' && cldate < '$effdate182' && assn ='$value' ");
$rows = mysql_num_rows($results);
if ($rows < 1)
{
echo "No Matching records.<br>";
}
else
{
$total = ($rows + $total);
}
}
?>
Last edited by gdaniels; 04-11-2009 at 11:15 AM..
Reason: Correct code
|