从 MySQL 数据库错误中选择最新条目
<?php
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("jmvarela_jacket") or die(mysql_error());
$query = 'SELECT * FROM `quote` ORDER BY `id` DESC LIMIT 1';
$row = mysql_fetch_array( $query );
echo $row['frase'];
?>
我无法让它发挥作用。
我收到此错误:
警告:mysql_fetch_array():已提供 参数不是有效的 MySQL 结果 资源在 /home/jmvarela/public_html/ihateyourjacket.com/latest/index.php 第 7 行
我尝试选择 mysql 数据库的最新条目。
该表名为“quote”,
共有三个字段:id、frase 和 name。
只是为了澄清(因为这可能是非常糟糕的编码)我试图获取“最大”id 并显示它对应的“frase”。
<?php
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("jmvarela_jacket") or die(mysql_error());
$query = 'SELECT * FROM `quote` ORDER BY `id` DESC LIMIT 1';
$row = mysql_fetch_array( $query );
echo $row['frase'];
?>
I cant get this to work.
I get this error:
Warning: mysql_fetch_array(): supplied
argument is not a valid MySQL result
resource in
/home/jmvarela/public_html/ihateyourjacket.com/latest/index.php
on line 7
I am trying to select the latest entry to the mysql database.
The table is called "quote"
There are three fields: id, frase and name.
Just to clarify (because this could be VERY bad coding) I am trying to get the "biggest" id and to display it's correspondant "frase".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还没有执行您的查询
试试这个
you have not perform your query
try this
您似乎没有运行查询。
另外,最好将
SELECT *
更改为SELECT frase
,因为您只对frase
列感兴趣。这不会将所有不需要的列从 MySql 带到 PHP,从而使您的程序性能更好。Looks like you are not running the query.
Also it's better to change
SELECT *
toSELECT frase
, since you're interested only in thefrase
column. This will not bring all the unwanted columns from MySql to PHP, making your program perform better.我不确定是否应该这样做,但我会留下完整的运行代码以供将来参考。
谢谢大家!
I´m not sure if this should be done but ill leave the complete running code for future refence.
Thanks to everyone!