doudou0111
2015-11-07 02:35
浏览 7
已采纳

从同一数据库中的不同表中获取数据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;
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题