doujiu8826 2012-03-09 10:45
浏览 45
已采纳

从2个不同的MySQL表中获取数据

I'm working on a project that involved getting information from two different servers. What i plan on doing is having the user enter his or her username password and then have a php script fill in the rest of the fields below first name last name etc. I did some searching and found that some of the data i have is on two different tables within the server. Below is the coding I have so far.

 <?php
    $connect = mysql_connect("localhost","**************","**********") or die ("Couldn't Connect"); //host,username,password
    mysql_select_db("*******") or die ("Could not find database");

    $query = mysql_query("SELECT * FROM jos_users WHERE username='$username'");


    ?>
    <html>
    <form action="populate.php" method='post'>
     <table>
    <tr>
            <td>VAE&nbsp;Username:</td>

            <td><input type='text' name='username' value=''></td>
          </tr>
          <tr>
            <td>VAE&nbsp;Password:</td>

            <td><input type='password' name='password' value=''></td>
          </tr>
     </table>
      <p><input type='submit' name='submit' value='Search & Populate!'></p>
</form>
//below is the information i want filled in from the MYSQL tables
    <hr>
    $query = mysql_query("SELECT * FROM jos_users WHERE username='$username'");
    <form action="dafreg.php" method='post'>
    <table>
    <tr>
    <td>Fristname:</td>
    <td><input type='text' name='firstname' value='<?php echo $firstname; ?>'></td>
    </tr>
    <tr><td>Lastname:</td>
    <td><input type='text' name='lastname' value='<?php echo $lastname; ?>'></td>
    </tr>
    <tr>
    <td>Login:</td>
    <td><input type='text' name='login' value='<?php echo $username; ?>'></td>
    </tr>
    <tr><td>Password:</td>
    <td><input type='text' name='pass' value=''></td>
    </tr>
    <tr><td>Country:</td>
    <td><input type='text' name='country' value=''></td>
    </tr>
    <tr><td>Pilot:</td>
    <td><input type='checkbox' name='pilot' value=''></td>
    </tr>
    <tr><td>ATC:</td>
    <td><input type='checkbox' name='atc' value=''></td>
    </tr>
    <tr><td>Email:</td>
    <td><input type='text' name='email' value=''></td>
    </tr>
     </table>
     <p><input type='submit' name='submit' value='Register'></p>
     </form>





    </form>


    </html>
  • 写回答

2条回答 默认 最新

  • duanlan7903 2012-03-09 10:52
    关注

    Using 'JOIN' will be the best option for extracting the data multiple table...

    SELECT tab1.*,tab2.*
    FROM table1 tab1 JOIN table2 tab2
    ON tab1.id=tab2.id
    WHERE tab1.username=$username
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c