如何使用基于 reddit 的算法在存储函数的修改下查询选择所有 mysql 行?
我花了一整天的时间进行谷歌搜索、删除和插入,试图实现这段代码。我一直在尝试使用 php 和 mysql 实现一个类似 reddit 的网站。我一直在关注另一个问题: PHP MYSQL Query Algorithm Help 和它当我查询存储的函数时,工作得很好,并且根据 myphpadmin 中上一个问题中编码的算法对行进行排名
SELECT
*,
reddit_rank(`time_added`, `up_votes`, `down_votes`) as rank
FROM
`table`
ORDER BY
rank;
,但是当我将查询粘贴到我的 php 文件中时
<?php
include("config.php");
$q= "SELECT *,reddit_rank(`time` , `votes_up` , `votes_down`) FROM `wallposts` ORDER BY rank LIMIT 0 , 30";
$r = mysql_query($q);
if(mysql_num_rows($r) > 0) {
while($row = mysql_fetch_assoc($r)){
...?>
:不起作用,我看到一个白色的 HTML 屏幕。例如,在我的 PHP 中,当我有
$q = "SELECT * FROM wallposts ORDER BY votes_up DESC";
类似 reddit/facebook 的墙时,已经预先添加了 mysql 中的每一行,并且一切正常。但是当我将其更改为
$q= "SELECT *,reddit_rank(`time` , `votes_up` , `votes_down`) FROM `wallposts` ORDER BY rank LIMIT 0 , 30";
网页时,除了白屏之外什么也没有返回,即使我知道它在 myphpadmin 中工作。
我的语法是否有问题,或者是否无法使用存储的函数查询全选以在 php 中对结果进行排序?
I've spent the whole day googling and deleting and inserting trying to implement this code. I've been trying to implement a reddit-like site using php and mysql. I have been following another question: PHP MYSQL Query Algorithm Help and it works very well and ranks rows according to the algorithm coded in the previous question within myphpadmin when I query a stored function
SELECT
*,
reddit_rank(`time_added`, `up_votes`, `down_votes`) as rank
FROM
`table`
ORDER BY
rank;
, but when I paste the query into my php file:
<?php
include("config.php");
$q= "SELECT *,reddit_rank(`time` , `votes_up` , `votes_down`) FROM `wallposts` ORDER BY rank LIMIT 0 , 30";
$r = mysql_query($q);
if(mysql_num_rows($r) > 0) {
while($row = mysql_fetch_assoc($r)){
...?>
It doesn't work and I get a white HTML screen. So for example in my PHP when I have
$q = "SELECT * FROM wallposts ORDER BY votes_up DESC";
my reddit/facebook-like wall has prepended each of my rows from mysql and everything works just fine. but when i change it to
$q= "SELECT *,reddit_rank(`time` , `votes_up` , `votes_down`) FROM `wallposts` ORDER BY rank LIMIT 0 , 30";
the webpage returns nothing but a white screen even though I know it works in myphpadmin.
Is there something wrong with my syntax or is it not possible to query a select all with a stored function to order the results in php?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我通过创建视图然后查询该视图而不是原始表找到了解决方案。在我查询 myphpadmin 中的存储函数之后:
返回这些结果后,我创建了一个视图。然后,我没有在 PHP 文件中以相同的方式查询,而是使用以下命令查询新的 mysql 视图:
瞧!
I think I found a solution by creating a view and then querying that view instead of the original table. After I queried the stored function in myphpadmin:
I then created a view after those results were returned. Then instead of querying the same way in my PHP file, I queried the new mysql view with:
Voila!