doudou0111 2015-11-07 02:35 采纳率: 0%
浏览 8
已采纳

从同一数据库中的不同表中获取数据PHP [关闭]

So here's my problem, I'm trying to fetch data from different tables, I already wrote the code for fetching from one table, but I couldn't fetch another data from the other table, here is my code:

 <?php
}
else
{
    $q = mssql_query("SELECT fdExp, fdGameMoney, fdUserNum FROM UserInfoGame WHERE fdUserNum = '".$_SESSION['fdUserNum']."'");
?>
    <div class="login2" style="color:#a1a1a1;">
    <font size="3"><div style="font-size:16px; margin-left:10px;">Welcome, <?php echo $_SESSION['username']; ?></div></font>
    <div style="font-size:14px; margin-left:15px; margin-top:5px;">
        <font size="2">TR: <?php echo mssql_result($q, 0, 'fdGameMoney'); ?>
        <div style="margin-top:-5px;">Exp: <?php echo mssql_result($q, 0, 'fdExp'); ?></div>
        <div style="margin-top:-5px;">UserNum: <?php echo mssql_result($q, 0, 'fdUserNum'); ?></div>
        <div style="margin-left:5px;">

the other table called "tbl.cash" and the rows are "MC" and "usernum" the code should check the usernum if it's the same it gonna fetch the data of how much mc he got..

  • 写回答

1条回答 默认 最新

  • doupao1530 2015-11-07 03:30
    关注

    What exactly is the problem? Do you get any errors?
    The following should work:

    <?php
    
    $q = mssql_query($conn, "SELECT mc FROM tbl.cash WHERE usernum = '".$_SESSION['fdUserNum']."'");
       if(!is_null($MC = mssql_result($q, 0, 'mc'))) {
          // do output here
          echo $MC;
       }
    


    Perhaps a JOIN would do the same.

    SELECT * FROM userinfogame
    LEFT JOIN tbl.cash ON userinfogame.fdUserNum = tbl.cash.usernum;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样