MySQL连接在两个表中 [英] Mysql connect in two tables

查看:83
本文介绍了MySQL连接在两个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在两个表中连接...请帮助我!

I need connect in two tables... Help me please!

  <?php
    $tabela = mysql_query("SELECT * FROM rankpvp ORDER BY ratio DESC LIMIT 1");

     while($pvp = mysql_fetch_assoc($tabela)){

     $classe = mysql_query("SELECT * FROM char WHERE char_id = '".$pvp['char_id']."'");

     echo ' classe: '.$classe['class'].'<br> Nome: '.$pvp['name'].'<br> Pontos: '.$pvp['ratio'].'<br> Kills: '.$pvp['kills'].'<br>   ';   }    ?>

推荐答案

这可以通过一个查询完成

This can be done with one query

SELECT * FROM `char` WHERE char_id = (SELECT char_id FROM rankpvp ORDER BY ratio DESC LIMIT 1)

请注意,char是保留字,因此必须将其包装在中间.也许这是您遇到的实际问题(语法错误),而不是while循环问题.不过,一个查询是正确的方法

Note that char is a reserved word so it will have to be wrapped in back ticks. Maybe this is the actual problem you ran into (syntax error) rather than a problem with your while loop. Nevertheless, one query is the right way

这篇关于MySQL连接在两个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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