doushang7209 2014-04-23 13:53
浏览 17
已采纳

数据库帮助/查询[关闭]

I was just wondering if I could do a php code with a database that goes like this: (ID, username, full name, channel, link, email, skype). I want the database to have everyones data but in the php code I would like it to only echo the data of the username. Im not sure if it makes to much sense but for example if my username is x and there are 3 different recruiters x,y, and z with a total of 10 data for the database, I only want the data created by x to show because the username = x.

Sorry if this doesn't make sense, I don't try to confuse anyone. So if you can't understand feel free to post below and I will happily answer your questions as best as I can. If you can't be bothered no problem. Thanks for the time guys.

  • 写回答

1条回答 默认 最新

  • doucheng9634 2014-04-23 13:59
    关注

    Yes, it's simple SELECT statement:

    $db = new PDO(
        $config['connectionString'],
        $config['username'],
        $config['password']
    );
    
    $query = $db->prepare('SELECT * FROM `users_table` WHERE `username` = :user');
    $query->execute([':user' => "Slayer5000"]);
    $user = $query->fetch(PDO::FETCH_OBJ);
    

    UPDATE WITH YOUR CODE

    <?php
    $db = new PDO(
        "mysql:host=127.0.0.1;port=3306;dbname=goaerox_lkdb1",
        "goaerox_lkdb1",
        "njimkolp"
    );
    
    $query = $db->prepare('SELECT `id`, `channel`, `email`, `paypal`, `network`, `name` FROM `partners` WHERE `name` = :user');
    $query->execute([':user' => $your_user_name_to_search_for]);
    $user = $query->fetch(PDO::FETCH_OBJ);
    
    echo "<table>";
    echo "<tr><td>ID</td><td>Username</td><td>Full Name</td><td>Channel</td><td>Link</td><td>Email</td><td>Skype</td></tr>";
    
        echo "<tr>";
        echo "<td>{$user->id}</td>";
        echo "<td>{$user->name}</td>";
        echo "<td>{$user->name} &lt;{$user->}&gt;</td>"; // Have no idea how you generate fullName here
        echo "<td>{$user->channel}</td>";
        echo "<td>{$user->paypal}</td>";
        echo "<td>{$user->email}</td>";
        echo "</tr>";
    
    echo "</table>";
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch