Since my last post I have been going round in circles trying to include data from another table in this query.
I now have (following your advice) the query to show the stores that haven't sent data this week. However I am now trying to include in this query the user information to show in the csv file the user related to that store.
code that works - show the 'missing' stores
$sql = "SELECT tblStore.StoreId, tblStore.CommonName, tblStore.SerialNumber,
tblStore.ContractRef, tblStore.UserRef, tblUser.CoName FROM tblStore
WHERE StoreId NOT IN(SELECT StoreRef FROM tblResults WHERE DateLogRef = '$DateLogId' AND ConcesRef = '$ConcesRef')
";
$getinfo = mysql_query($sql)
or die (mysql_error());
while($row = mysql_fetch_array($getinfo, MYSQL_ASSOC))
{
while (list($key, $value) = each($row))
{
echo ("$value" . "," );
} // close 2nd while
echo ("\n");
} // close 1st while
mysql_close();
} // close 2nd if
else
{
listErrors();
} // close 1st else
} //close 1st if
else
{
echo "please try again";
} // close 2nd else
I have tried to extend this code to try to include data from tblUser as follows
$sql = "SELECT tblStore.StoreId, tblStore.CommonName, tblStore.SerialNumber,
tblStore.ContractRef, tblStore.UserRef, tblUser.CoName FROM tblStore, tblUser
WHERE StoreId NOT IN(SELECT StoreRef FROM tblResults WHERE DateLogRef = '$DateLogId' AND ConcesRef = '$ConcesRef')
AND tblUser.UserId = tblStore.UserRef
";
$getinfo = mysql_query($sql)
or die (mysql_error());
while($row = mysql_fetch_array($getinfo, MYSQL_ASSOC))
{
while (list($key, $value) = each($row))
{
echo ("$value" . "," );
} // close 2nd while
echo ("\n");
} // close 1st while
mysql_close();
} // close 2nd if
else
{
listErrors();
} // close 1st else
} //close 1st if
else
{
echo "please try again";
} // close 2nd else
This gives the correct output and shows the User information as I would expect, however, it stops after the first 2 records. In my test I know there are 8 records - the first, shorter code outputs all 8 records, but this extended code only does 2.
I have tried so many different permutations of the code and cannot get it to work at all - any help will be gratefully received - thanks.