This maybe the reason why I’m having problems in other areas, but which outputting the area its giving an empty result for m_id. the filed it used multiple times and is correctly displaying data for all the other fields but the main field m_id that is used is not showing its ID number.
$res = mysql_query("SELECT *, DATE_FORMAT(sm.m_lld,'%m/%d/%y')
AS m_lld_formatted
FROM social_members sm
JOIN social_meminfo smi ON (sm.m_id = smi.m_id)
LEFT OUTER JOIN social_memtext smt ON (sm.m_id = smt.m_id)
WHERE sm.m_user = '".mysql_real_escape_string($en['user'])."'");
if (mysql_num_rows($res) == 0) call404();
$line = mysql_fetch_assoc($res);
foreach ($line as $key => $value) {
$en['m'.$key] = str_replace("\n",'<br/>',stripslashes($value));
}
echo '<pre>'; print_r($line); echo '</pre>';
echo $en['mm_id'];
Okay I think I see what’s happening. When I do a LEFT OUTER JOIN for social_memtext if that table finds no results for m_id it does not display a value for m_id even though its present in the other two tables. Is there anyway to fix that? m_id will always have a value/row in social_members and _meminfo when looked up
From: http://php.net/manual/en/function.mysql-fetch-assoc.php
If two or more columns of the result have the same field names, the last column will take precedence.
You are selecting everything out of 3 joins and in every table
m_idhas the same name.Which means there are 3
m_id‘s in your resultset, last one being from the left joined table social_memtext, which will be NULL if there is no corresponding row in that table for given m_id.To get your expected m_id add an alias in SELECT and use that alias for array index in php.