joomla sql查询 [英] joomla sql query

查看:134
本文介绍了joomla sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我对sql不太了解,但是我试图为我的网站进行动态重定向,这个想法是将每个用户重定向到与该用户相同的文章,所以这里有一些代码,但是我不知道知道如何完成它:(

ok so i dont know much about sql but im trying to make a dinamic redirect for my website, the idea is to redirect each user to an article called the same as the user is called, so here's a little code but i dont know how to finish it :(

$database->setQuery("SELECT id "." FROM #__content "." WHERE state='1' "." ");
$rows = $database->loadObjectList();
foreach($rows as $user_name){   
$article_id = $row->id; 
break;
}
$redirect_url = 'index.php?option=com_content&view=article&id='.$article_id;

$ user_name和$ redirect_url是预制"选项,因此不必担心,我只需要知道如何实际执行查询,谢谢您的帮助:D

$user_name and $redirect_url are "premade" options so dont worry about it, i just need to know how to actually do the query hehe, thanks for the help :D

推荐答案

您似乎打算返回单个article_id,因此SQL查询应始终返回单个行(值),在这种情况下,foreach必须消失.问题是您需要重写SQL查询,并向WHERE子句添加另一个条件.也许是这样的:

It looks like you intend to return a single article_id, so that SQL query should always return a single row (value), in which case, that foreach must disappear. The thing is that you need to rewrite your SQL query and add another condition to the WHERE clause. Perhaps something like this:

$user =& JFactory::getUser();
$database->setQuery("SELECT id FROM #__content WHERE state='1' AND title = '".$user->name."'");
$row = $database->loadAssoc();
$redirect_url = 'index.php?option=com_content&view=article&id='.$row['id'];

请注意,我尚未测试以上代码.

Please note that I have not tested the above code.

这篇关于joomla sql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆