php显示mysql数据库的结果(php display results from mysql database)

编程入门 行业动态 更新时间:2024-10-19 02:16:37
php显示mysql数据库的结果(php display results from mysql database)

多年没有做任何php数据库工作,相当简单的问题我确信任何有经验的人,下面是我的代码它应该从数据库获取所有结果并将这些显示到带有链接的表:

<?php include('session.php'); ?> <html"> <head> <title>Welcome </title> </head> <body> <h1>Welcome <?php echo $login_session; ?></h1> <form method="post" action="upload.php" enctype="multipart/form-data"> <p>File:</p> <input type="file" name="Filename"> <p>Description:</p> <textarea rows="10" cols="35" name="Description"></textarea> <br/> <input TYPE="submit" name="upload" value="Submit"/> </form> <hr/> <p>Uploaded Files</p> <?php //include('config.php'); $query1=mysqli_query($db,"SELECT filepath,filename,description FROM `filedetails`"); echo "<table><tr><td>filepath</td><td>filename</td><td></td><td></td>"; while($query2=mysql_fetch_array($query1)) { echo "<tr><td>".$query2['filepath']."</td>"; echo "<td>".$query2['filename']."</td>"; echo "<td><a href='edit.php?id=".$query2['id']."'>Edit</a></td>"; echo "<td><a href='delete.php?id=".$query2['id']."'>x</a></td><tr>"; } ?> <h2><a href = "logout.php">Sign Out</a></h2> </body> </html>

所以它失败的路线是

while($query2=mysql_fetch_array($query1))

错误消息是:

警告:mysql_fetch_array()期望参数1是资源,第27行的C:\ xampp \ htdocs \ welcome.php中给出的对象

Not done any php database work for years, fairly simple question I'm sure for anyone with experience, below is my code it should take all the results from the database and display these to a table with links:

<?php include('session.php'); ?> <html"> <head> <title>Welcome </title> </head> <body> <h1>Welcome <?php echo $login_session; ?></h1> <form method="post" action="upload.php" enctype="multipart/form-data"> <p>File:</p> <input type="file" name="Filename"> <p>Description:</p> <textarea rows="10" cols="35" name="Description"></textarea> <br/> <input TYPE="submit" name="upload" value="Submit"/> </form> <hr/> <p>Uploaded Files</p> <?php //include('config.php'); $query1=mysqli_query($db,"SELECT filepath,filename,description FROM `filedetails`"); echo "<table><tr><td>filepath</td><td>filename</td><td></td><td></td>"; while($query2=mysql_fetch_array($query1)) { echo "<tr><td>".$query2['filepath']."</td>"; echo "<td>".$query2['filename']."</td>"; echo "<td><a href='edit.php?id=".$query2['id']."'>Edit</a></td>"; echo "<td><a href='delete.php?id=".$query2['id']."'>x</a></td><tr>"; } ?> <h2><a href = "logout.php">Sign Out</a></h2> </body> </html>

So the line it's failing on is

while($query2=mysql_fetch_array($query1))

The error message is:

Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\xampp\htdocs\welcome.php on line 27

最满意答案

而不是mysql_fetch_array你需要使用mysqli_fetch_array 。

<?php include('session.php'); ?> <html"> <head> <title>Welcome </title> </head> <body> <h1>Welcome <?php echo $login_session; ?></h1> <form method="post" action="upload.php" enctype="multipart/form-data"> <p>File:</p> <input type="file" name="Filename"> <p>Description:</p> <textarea rows="10" cols="35" name="Description"></textarea> <br/> <input TYPE="submit" name="upload" value="Submit"/> </form> <hr/> <p>Uploaded Files</p> <?php //include('config.php'); $query1=mysqli_query($db,"SELECT filepath,filename,description FROM `filedetails`"); echo "<table><tr><td>filepath</td><td>filename</td><td></td><td></td>"; while($row=mysqli_fetch_array($query1)) { echo "<tr><td>".$row['filepath']."</td>"; echo "<td>".$row['filename']."</td>"; echo "<td><a href='edit.php?id=".$row['id']."'>Edit</a></td>"; echo "<td><a href='delete.php?id=".$row['id']."'>x</a></td><tr>"; } ?> <h2><a href = "logout.php">Sign Out</a></h2> </body> </html>

注意:我还将您的变量名称更改为更明智的名称。

Instead of mysql_fetch_array you need to use mysqli_fetch_array.

<?php include('session.php'); ?> <html"> <head> <title>Welcome </title> </head> <body> <h1>Welcome <?php echo $login_session; ?></h1> <form method="post" action="upload.php" enctype="multipart/form-data"> <p>File:</p> <input type="file" name="Filename"> <p>Description:</p> <textarea rows="10" cols="35" name="Description"></textarea> <br/> <input TYPE="submit" name="upload" value="Submit"/> </form> <hr/> <p>Uploaded Files</p> <?php //include('config.php'); $query1=mysqli_query($db,"SELECT filepath,filename,description FROM `filedetails`"); echo "<table><tr><td>filepath</td><td>filename</td><td></td><td></td>"; while($row=mysqli_fetch_array($query1)) { echo "<tr><td>".$row['filepath']."</td>"; echo "<td>".$row['filename']."</td>"; echo "<td><a href='edit.php?id=".$row['id']."'>Edit</a></td>"; echo "<td><a href='delete.php?id=".$row['id']."'>x</a></td><tr>"; } ?> <h2><a href = "logout.php">Sign Out</a></h2> </body> </html>

Note: I also changed your variable name to a more sensible one.

更多推荐

本文发布于:2023-04-28 03:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329712.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   mysql   php   database   results

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!