数组未显示所有结果 [英] Array not displaying all results

查看:79
本文介绍了数组未显示所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这也许就是为什么我在其他区域遇到问题的原因,但是输出该区域会给 m_id 一个空结果.该文件多次使用,并正确显示了所有其他字段的数据,但使用的主字段 m_id 未显示其ID号.

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'];

好的,我想我知道发生了什么事.当我为social_memtext做一个LEFT OUTER JOIN时,如果该表没有找到m_id的结果,即使它存在于其他两个表中,它也不会显示m_id的值.反正有解决办法吗?查找时,m_id在social_members和_meminfo中始终具有一个值/行

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

推荐答案

来自:如果结果的两个或更多列具有相同的字段名称,则最后一列优先.

If two or more columns of the result have the same field names, the last column will take precedence.

您要从3个联接中选择所有内容,并且在每个表中m_id具有相同的名称. 这意味着结果集中有3个m_id,最后一个来自左联接表social_memtext,如果该表中没有给定m_id的对应行,则为NULL.

You are selecting everything out of 3 joins and in every table m_id has 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.

要获得所需的m_id,请在SELECT中添加一个别名,并将该别名用于php中的数组索引.

To get your expected m_id add an alias in SELECT and use that alias for array index in php.

SELECT *, DATE_FORMAT(sm.m_lld,'%m/%d/%y') 
                AS m_lld_formatted,
          sm.m_id as mem_id
...

这篇关于数组未显示所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆