Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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
从SQL中提取PHP循环(初学者)_Php_Html_Sql_Database - Fatal编程技术网

从SQL中提取PHP循环(初学者)

从SQL中提取PHP循环(初学者),php,html,sql,database,Php,Html,Sql,Database,不熟悉php和sql,正在为资源而挣扎 基本上,我所需要做的就是从表中选择数据并将其格式化为适当的html 我已经有了大致的想法,只是没有设置循环。 我设置了到数据库的SQL连接,然后是到表的SQL连接 这是代码。 还有桌子的布局。 谢谢,伙计们,如果有什么不对劲的地方,请告诉我,因为我宁愿现在就纠正,也不愿以后再纠正 代码: $query=mysqli_query($con,“从TableName中选择*); 而(??){ $game=$temp['game']; $stance=$temp

不熟悉php和sql,正在为资源而挣扎

基本上,我所需要做的就是从表中选择数据并将其格式化为适当的html

我已经有了大致的想法,只是没有设置循环。 我设置了到数据库的SQL连接,然后是到表的SQL连接

这是代码。 还有桌子的布局。

谢谢,伙计们,如果有什么不对劲的地方,请告诉我,因为我宁愿现在就纠正,也不愿以后再纠正

代码:

$query=mysqli_query($con,“从TableName中选择*);
而(??){
$game=$temp['game'];
$stance=$temp['stance'];
$start=$temp['start'];
}
回声'
echo$游戏$姿态$开始
';

我建议看一下PHP手册


一旦你掌握了它的窍门并理解了它应该做什么,这就非常简单了。

我们都建议在MySQL连接中使用PDO

以下是一种快速而肮脏的入门方式(未经测试):

$pdo=newpdo('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8','user','pass');
$pdo->setAttribute(pdo::ATTR_ERRMODE,pdo::ERRMODE_EXCEPTION);//所有pdo错误都将引发异常
试一试{
$result=$pdo->query(“从myTable中选择*);
而($row=$result->fetch(PDO::fetch_ASSOC)){
回声“;
回显“$row['column_name']”;
回显“$row['column_name2']”;
回显“$row['column_name3']”;
回声“;
}
}捕获(PDO$e){
echo“查询出现问题。{$e->getMessage()}”;
}
试试这个

$query = mysqli_query($con,"SELECT * FROM tablenamehere");
while($query){
$game = $query['game'];
$stance = $query['stance'];
$start = $query['start'];

echo "<div  id='accordion'>
       <h3><tr><td>".$game."</td><td>".$stance."</td><td>".$start."</td></tr></h3>  
       </div>";

}
$query=mysqli_query($con,“从TableName中选择*);
while($query){
$game=$query['game'];
$stance=$query['stance'];
$start=$query['start'];
回声“
“$game.”“$stance.”“$start.”
";
}

将代码粘贴到此处,而不是粘贴到pastebin中。更正:将代码同时粘贴到这两个位置;你想要答案,那些愿意帮助你的人有优先权。php手册中有一些例子涵盖了你的确切问题。你看过了吗?
$pdo = new PDO('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8', 'user', 'pass');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // all pdo errors will throw an exception

try {
  $result = $pdo->query("SELECT * FROM myTable");
  while($row = $result->fetch(PDO::FETCH_ASSOC)) {
    echo "<tr>";
    echo "  <td>" . $row['column_name'] . "</td>";
    echo "  <td>" . $row['column_name2'] . "</td>";
    echo "  <td>" . $row['column_name3'] . "</td>";
    echo "</tr>";
  }
} catch(PDOException $e) {
  echo "Something went wrong with the query. {$e->getMessage()}";
}
$query = mysqli_query($con,"SELECT * FROM tablenamehere");
while($query){
$game = $query['game'];
$stance = $query['stance'];
$start = $query['start'];

echo "<div  id='accordion'>
       <h3><tr><td>".$game."</td><td>".$stance."</td><td>".$start."</td></tr></h3>  
       </div>";

}