PHP MySQL While 循环从两个表中选择? [英] PHP MySQL While loop for SELECT from two tables?

查看:63
本文介绍了PHP MySQL While 循环从两个表中选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在编写从两个表中选择列的 PHP 代码.

Hi there i am working on PHP code that is selecting columns from two tables.

这是我的代码:

$result2  = mysql_query("SELECT  * 
                         FROM   `videos`, `m_subedvids` 
                         WHERE  `videos.approved`='yes' AND 
                                `videos.user_id`='$subedFOR' 
                         ORDER BY `videos.indexer`
                         DESC LIMIT $newVID");

while($row2 = mysql_fetch_array($result2))
{
    $indexer   = addslashes($row2['videos.indexer']);
    $title_seo = addslashes($row2['videos.title_seo']);
    $video_id  = addslashes($row2['videos.video_id']);
    $title     = addslashes($row2['videos.title']);
    $number_of_views = addslashes($row2['videos.number_of_views']);
    $video_length    = addslashes($row2['videos.video_length']);
}

当我尝试使用 echo $indexer; 打印 $indexer 时,它没有给我任何结果.我在这段代码中的错误在哪里?

When i try to print $indexer with echo $indexer; it's not giving me any results. Where is my mistake in this code?

推荐答案

在我看来,'indexer' 键似乎不在您的结果中.很难说,因为您没有列出表的定义,而且您使用的是 SELECT * 所以我们看不到名称.

It seems to me like the key 'indexer' isn't in your results. It's hard to tell, since you haven't listed a definition for your table and you're using SELECT * so we can't see the names.

如果您使用 SELECT col1, col2, ... 而不是 SELECT *...,它会使程序更易于以后阅读.是的,SELECT * 现在可以为您节省一些输入时间,但是当您或其他任何处理您代码的人每次使用该行时都必须检查表定义时,您将失去这段时间代码.

It makes the program easier to read later, if instead of SELECT *..., you use SELECT col1, col2, .... Yes, SELECT * will save you some typing right now, but you'll lose that time later when you or anyone else who works on your code has to check the table definition every time they work with that line of code.

因此,尝试更改您的查询以明确选择您使用的列.如果它是一个无效的列,您会立即收到错误消息,而不是您现在遇到的这种无声的失败,稍后您也会感谢自己.

So, try changing your query to explicitly select the columns you use. If it's an invalid column you'll get an error right away rather than this silent failure you're getting now, and you'll thank yourself later as well.

这篇关于PHP MySQL While 循环从两个表中选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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