I’m having some issues declaring a value in my php statement. The 2 values outside of the sub query declare fine but the one inside the sub query does not work and gives me Undefined index: deviceName.
$sql4 = "SELECT endPort, startPort,
(
SELECT deviceName
FROM devices
WHERE devices.deviceID = patching.endDeviceID
)
FROM patching
WHERE deviceID = '$deviceID'
LIMIT 0 , 10";
$query4 = mysql_query($sql4);
while ($row = mysql_fetch_array($query4))
{
$startp = $row['startPort'];
$endp = $row['endPort'];
$endname= $row['deviceName'];
echo '<tr class="logm"><td>'.$startp.'</td><td></td><td>'.$endname.'</td><td></td><td>'.$endp.'</td><td></td></tr>';
}
Is it possible to declare this value and am i doing it wrong or is there another way round this issue.
You didn’t give the subquery result a name:
Though you should be using joins, not subqueries: