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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动