Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php在个人卡片中显示MySql表中的数据?_Php_Mysql_Mysqli - Fatal编程技术网

如何使用php在个人卡片中显示MySql表中的数据?

如何使用php在个人卡片中显示MySql表中的数据?,php,mysql,mysqli,Php,Mysql,Mysqli,我一直想在我的网站上这样做,但我找不到一个合适的方法来做到这一点。任何资源都会很好。总的来说,我试图在单个引导卡中显示每个数据值。此外,是否可以使卡片的数量等于MySql表中的值的数量?我不明白的是如何将PHP集成到HTML中,使页面显示数量可变的引导卡。我正在尝试用PHP来实现这一点(我对PHP的使用还比较陌生)。谢谢你的帮助。欢迎所有回复 //the following gets values from the two tables, I am trying to get the value

我一直想在我的网站上这样做,但我找不到一个合适的方法来做到这一点。任何资源都会很好。总的来说,我试图在单个引导卡中显示每个数据值。此外,是否可以使卡片的数量等于MySql表中的值的数量?我不明白的是如何将PHP集成到HTML中,使页面显示数量可变的引导卡。我正在尝试用PHP来实现这一点(我对PHP的使用还比较陌生)。谢谢你的帮助。欢迎所有回复

//the following gets values from the two tables, I am trying to get the values from the "data" table 
if (isset($_SESSION['username'])) {
    $userLoggedIn = $_SESSION['username'];
    $user_details_query = mysqli_query($con, "SELECT * FROM users WHERE username='$userLoggedIn'" );
    $user = mysqli_fetch_array($user_details_query);


    $user_id = $user['id'];
    $data_detail_query = mysqli_query($con, "SELECT * FROM data WHERE user_id ='$user_id'");
    $data = mysqli_fetch_array($data_detail_query);

    $num_rows = mysqli_num_rows($data_detail_query);
    }

//The following shows one bootstrap card that I was able to create using one row. 
<div class="card" style="width: 18rem;float:left;margin-top:20px;margin-left:20px;border-color:white;border-width:5px;">

      <div class="card-block">
          <img style="height:250px;width:100%;" src="<?php echo $data['icon']; ?>"  alt="Card image cap">
            <div>
            <h1 class="card-title" ><?php echo $data['name']?><span style="color:#5aff28;float:right" ><?php echo $data['level']; ?></span></h1>
            <h5 class="card-subtitle mb-2 text-muted"><?php echo $data['category']; ?></h5>
            <p class="card-text"><?php echo $data['description']; ?></p>
            <a href="<?php echo $data['link']; ?>" class="card-link">Link</a>
            <a href="<?php echo $data['developer_link']; ?>" class="card-link">Developer Profile</a>

        <form method="post">

              <div style="width:200;float:left;margin-top:5px" class="form-group">
                <input  type="text" class="form-control" id="code" name="code" placeholder="Enter Code">
              </div>

        </form method="post">
         <a href="" name="code_btn" class="btn btn-success">Enter</a>
        </div>
//下面从两个表中获取值,我试图从“data”表中获取值
如果(isset($\u会话['username'])){
$userLoggedIn=$\会话['username'];
$user\u details\u query=mysqli\u query($con,“从username='$userLoggedIn'的用户中选择*);
$user=mysqli\u fetch\u数组($user\u details\u query);
$user_id=$user['id'];
$data\u detail\u query=mysqli\u query($con,“从数据中选择*,其中user\u id=“$user\u id”);
$data=mysqli\u fetch\u数组($data\u detail\u query);
$num\u rows=mysqli\u num\u rows($data\u detail\u query);
}
//下面显示了我能够使用一行创建的一个引导卡。
“alt=”卡图像上限“>


我试图获取名为“data”的表中用户名为$userLoggedIn的每一行,并将每个结果显示在其自己的引导卡中。

mysqli\u fetch\u array
只会给出下一个结果,而不是全部。您只需从数据库中获取结果,直到没有更多结果为止,例如:

while (($data = mysqli_fetch_array($data_detail_query))) {
 /// ... do the output as above, e.g.:
 ?><a href="<?php echo $data['link']; ?>" class="card-link">Link</a><?php
}
使用准备好的语句或正确引用字符串:

$userLoggedIn = $con->real_escape_string($userLoggedIn);
$user_details_query = mysqli_query($con, "SELECT * FROM users WHERE username={$userLoggedIn}" );
$userLoggedIn = $con->real_escape_string($userLoggedIn);
$user_details_query = mysqli_query($con, "SELECT * FROM users WHERE username={$userLoggedIn}" );