简体   繁体   English

joomla 2.5数据库未收到查询?

[英]joomla 2.5 database not receiving queries?

I have php function that sends emails to users using templates from db. 我有php函数,该函数使用db中的模板向用户发送电子邮件。 The problem is that the last 3 queries are not working (I tried from phpmyadmin and it works fine). 问题是最后3个查询无法正常工作(我从phpmyadmin尝试过,并且工作正常)。 The code executes, no errors, but instead of getting amount of views and replies there is just empty space (db->loadobjectlist returns null?) and the last update query not doing anything either. 该代码可以执行,没有错误,但是没有获取足够的视图和答复,而是只有空白(db-> loadobjectlist返回null?),并且最后一个更新查询也不执行任何操作。

This is what it is sending at the end 这是它最后发送的

Please help me to understand what's wrong with this code 请帮助我了解这段代码有什么问题

$config = JFactory::getConfig();
$mailfrom = $config->get('mailfrom');
$fromname = $config->get('sitename');
$dbprefix = $config->getValue('config.dbprefix');
$database = JFactory::getDBO();

$query = "select u.id, u.email
from ".$dbprefix."users as u
left join ".$dbprefix."djcf_items as i on u.id=i.user_id and i.published=1
where u.sendEmail=1 and TIMESTAMPDIFF(hour,NOW(), u.WeeklyAD)=0
having count(i.id)>0";
$database->setQuery($query);
$users = $database->loadObjectList();

$template_name = 'Weekly ad';
$template_table = 'Weekly table';
$subject = 'Ads Peformance Update';
$template_main = getTemplate($template_name);
$template_table = getTemplate($template_table);

foreach($users as $user){
    $query = "select id, name, image_url, alias, timestampdiff(day, date_start, now()) as days_live
    from ".$dbprefix."djcf_items
    where user_id = ".$user->id." and published=1";
    $database->setQuery($query);
    $items = $database->loadObjectList();
    $template = $template_main;
    foreach($items as $item){
        $query = "select count(distinct v.user) as overall, count(distinct vw.user) as week
        from  ".$dbprefix."visitors as v
        left join ".$dbprefix."visitors as vw on vw.name=v.name and timestampdiff(hour, vw.date, now())<=7*24
        where v.name='".$item->alias.$item->id."'";
        $database->setQuery($query);
        $views = $database->loadObjectList();

        $query = "select count(distinct ia.id) as overall, count(distinct iaw.id) as week
        from  ".$dbprefix."djcf_itemsask as ia
        left join ".$dbprefix."djcf_itemsask as iaw on iaw.id=ia.item_id and timestampdiff(hour, iaw.date, now())<=7*24
        where ia.item_id=".$item->id;
        $database->setQuery($query);
        $replies = $database->loadObjectList();

        $table .= $template_table;
        $imagelink = explode(';',$item->image_url);
        $imagelink = 'http://'.$_SERVER['HTTP_HOST'].'/components/com_djclassifieds/images/'.$imagelink[0];

        $table = str_replace("##ITEM_NAME##", $item->name, $table);
        $table = str_replace("##DAYS##", $item->days_live, $table);
        $table = str_replace("##VIEWS##", $views->overall, $table);
        $table = str_replace("##VIEWS_WEEK##", $views->week, $table);
        $table = str_replace("##REPLIES##", $replies->overall, $table);
        $table = str_replace("##REPLIES_WEEK##", $replies->week, $table);
        $table = str_replace("##ITEM_IMG##", $imagelink, $table);
    }
    $template = str_replace("##WEEKLY_TABLE##", $table, $template);
    SendEmail($mailfrom, $fromname, $user->email, $subject, $template);
    $query = "update ".$dbprefix."users set WeeklyAD=ADDDATE(WeeklyAD, interval 7 day) where id='".$user->id."'";
    $database->setQuery($query);
}

It appears you may be using the wrong function in the select queries since loadObjectList() returns an indexed array of PHP objects from the table records returned by the query. 由于loadObjectList()从查询返回的表记录中返回PHP对象的索引数组,因此您似乎在选择查询中使用了错误的函数。 To use this function you would access the individual values by using: 要使用此功能,您可以使用以下方法访问各个值:

$row['index']->name // e.g. $row['2']->email

For single row results use loadObject() which returns a PHP object from a single record in the table. 对于单行结果,请使用loadObject() ,该对象从表中的单个记录返回一个PHP对象。 This matches your code since you would access the individual values by using: 这与您的代码匹配,因为您可以使用以下方法访问各个值:

$result->index // e.g. $result->email

The final update query is not executing because you are missing the execute() . 最终更新查询未执行,因为您缺少execute()

$query = "update ".$dbprefix."users set WeeklyAD=ADDDATE(WeeklyAD, interval 7 day) where id='".$user->id."'";
$database->setQuery($query);
$result = $database->execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM