the problem i got is that when i get information back from the database, i only get two raws not 4 . can someone help me out as i cant find any problems
this is the code
$sql = mysql_query("SELECT INCIDENT_ID FROM appreports WHERE POSTCODE = 'CF14' ");
while($row=mysql_fetch_assoc($sql))
{
$output[] = $row;
}
print(json_encode($output));
mysql_close();
this is the screenshot of the appreports table in database
You're joining two database tables using an 'INNER' join. If there's no corresponding POSTCODE
in the joined table, this row will not be returned.
To return all appregistrations
with the specified mobile number, optionally with an appreport
, use this;
SELECT * FROM appregistration
LEFT JOIN
`appreports`
ON `appreports`.`POSTCODE` = `appregistration`.`POSTCODE`
WHERE `appregistration`.`MOBILE_NUMBER` = '$mobile'
You are inner joining on POSTCODE and from that set you are filtering on a given MOBILE_NUMBER. You have 4 of the same POSTCODES here, so i'm guessing the issue is the MOBILE_NUMBER. Remove the WHERE clause and you may be back to 4 rows.
If you want return ALL rows with mobile number is $mobile at appreports table use this:
SELECT `INCIDENT_ID`, `INVESTIGATION`, `TYPE_OF_INCIDENT`, `DESCRIPTION`
FROM `appreports`
WHERE `appregistration`.`MOBILE_NUMBER` = '$mobile'"
If you want return ALL rows with mobile number is $mobile at appreports table and the information at appregistration table if this exist use this:
SELECT `INCIDENT_ID`, `INVESTIGATION`, `TYPE_OF_INCIDENT`, `DESCRIPTION`
FROM `appreports`
FULL OUTER JOIN `appregistration`
ON `appreports`.`POSTCODE` = `appregistration`.`POSTCODE`
WHERE `appregistration`.`MOBILE_NUMBER` = '$mobile'")