Problems with SQL query to show 3 records

Hello guys,

I have an website where I have 5 category blocks in my index page to show last 3 posts in each category.
But I having problems showing the content in my “last added” block.
Sometimes works, and sometimes not. Dont know what is happening… This happens with all of the 5 blocks, the code is almost the same as above, maybe is the same problem…

For each category that I want to show their posts, I have a file called newhome_x.php

In my templates/dirvideo/main.tpl file, I have this code:

[CODE]


{info} {newhome_final} {content}
[/CODE]

In my templates/dirvideo/newhome.tpl file, I have this code:

[CODE]


  • {home_title}

    {home_title}

  • [/CODE]

    in my index.php I have this code:
    [php]require_once ENGINE_DIR . ‘/modules/newhome.php’;
    require_once ENGINE_DIR . ‘/modules/newhome_b.php’;
    require_once ENGINE_DIR . ‘/modules/newhome_c.php’;
    require_once ENGINE_DIR . ‘/modules/newhome_d.php’;
    require_once ENGINE_DIR . ‘/modules/newhome_e.php’;

    if (clean_url ( $_SERVER[‘HTTP_HOST’] ) != clean_url ( $config[‘http_home_url’] )) {

    $replace_url = array ();
    $replace_url[0] = clean_url ( $config['http_home_url'] );
    $replace_url[1] = clean_url ( $_SERVER['HTTP_HOST'] );
    

    } else
    $replace_url = false;

    if (!$is_logged && !in_array($_GET[‘do’], array(‘register’, ‘lostpassword’))) { include ‘index.html’; die; }
    $tpl->load_template ( ‘main.tpl’ );
    $tpl->set ( ‘{lastusers}’, $lastusers);
    $tpl->set(’{forumStyle}’, require_once ROOT_DIR . ‘/engine/bullet_energy/modules/load_style.php’);
    require_once ENGINE_DIR . ‘/modules/3news.php’;$source = ’



      {newhome}
      {newhome_b}
      {newhome_c}
      {newhome_e}
      {newhome_d}
    '; if (!isset($_REQUEST["catalog"]) && !isset($_REQUEST["newsid"]) && !isset($_REQUEST["do"]) && !isset($_REQUEST["page"]) && !isset($_REQUEST["category"]) && !isset($_REQUEST["cat"]) && !isset($_REQUEST["action"]) && !isset($_REQUEST["id"]) && !isset($_REQUEST["name"]) && !isset($_REQUEST["news_name"]) && !isset($_REQUEST["seourl"]) && !isset($_REQUEST["findpost"]) && !isset($_REQUEST["subaction"])) { $tpl->set ( '{newhome_final}', $source);} else { $tpl->set ( '{newhome_final}', "");}

    $tpl->set ( ‘{referer}’, $referer_block );
    $tpl->set ( ‘{calendar}’, $tpl->result[‘calendar’] );
    $tpl->set ( ‘{top_news}’, $top_news );
    $tpl->set ( ‘{last_news}’, $last_news );
    $tpl->set ( ‘{rand_news}’, $rand_news );
    $tpl->set ( ‘{archives}’, $tpl->result[‘archive’] );
    $tpl->set ( ‘{tags}’, $tpl->result[‘tags_cloud’] );
    $tpl->set ( ‘{vote}’, $tpl->result[‘vote’] );
    $tpl->set ( ‘{topnews}’, $topnews );
    $tpl->set ( ‘{login}’, $tpl->result[‘login_panel’] );
    $tpl->set ( ‘{info}’, $tpl->result[‘info’] );
    $tpl->set ( ‘{speedbar}’, $tpl->result[‘speedbar’] );
    $tpl->set ( ‘{catlist}’, $catlist );
    $tpl->set ( ‘{moviepopular}’, $tpl->result[‘moviepopular’] );$tpl->set ( ‘{newhome}’, $tpl->result[‘newhome’] );$tpl->set ( ‘{newhome_b}’, $tpl->result[‘newhome_b’] );$tpl->set ( ‘{newhome_c}’, $tpl->result[‘newhome_c’] );$tpl->set ( ‘{newhome_d}’, $tpl->result[‘newhome_d’] );$tpl->set ( ‘{newhome_e}’, $tpl->result[‘newhome_e’] );[/php]

    In my engine/modules folder I have the files:
    newhome.php
    newhome_b.php
    newhome_c.php
    newhome_d.php
    newhome_e.php

    This is the code of engine/modules/newhome_c.php file (Series block):
    [php]<?php
    if (!isset($_REQUEST[“catalog”]) && !isset($_REQUEST[“newsid”]) && !isset($_REQUEST[“do”]) && !isset($_REQUEST[“page”]) && !isset($_REQUEST[“category”]) && !isset($_REQUEST[“cat”]) && !isset($_REQUEST[“action”]) && !isset($_REQUEST[“id”]) && !isset($_REQUEST[“name”]) && !isset($_REQUEST[“news_name”]) && !isset($_REQUEST[“seourl”]) && !isset($_REQUEST[“findpost”]) && !isset($_REQUEST[“subaction”])) {

    if( ! defined( ‘DATALIFEENGINE’ ) ) {

        die( "Hacking Attempt!" );
    

    }

    $is_change = false;

    if ($config[‘allow_cache’] != “yes”) { $config[‘allow_cache’] = “yes”; $is_change = true;}

    $tpl->result[‘newhome_c’] = dle_cache(“newhome_c”, $config[‘skin’]);

    $tpl->load_template( ‘newhome.tpl’ );

    if( strpos( $tpl->copy_template, “[xfvalue_” ) !== false ) { $xfound = true; $xfields = xfieldsload();}

        else $xfound = false;
    
    
    
        if ($tpl->result['newhome_c'] === false) {
    

    $sql = $db->query( "SELECT id, title, date, alt_name, category,xfields,autor FROM " . PREFIX . “_post WHERE category like ‘%7%’ ORDER BY date DESC LIMIT 3” );

    while ($row = $db->get_row($sql))

    {

    $catchecks = explode(",",$row[“category”]);

    $catpass = false;
    foreach ($catchecks as $catcheck) {
    if ($catcheck == “7”)
    $catpass = true;
    }

    if ($catpass) {

    $sql2 = $db->query( "SELECT alt_name FROM " . PREFIX . “_category WHERE id=’$row[category]’” );

    $row2 = $db->get_row($sql2);

    if( $xfound ) {

                        $xfieldsdata = xfieldsdataload( $row['xfields'] );
    
    
    
                        foreach ( $xfields as $value ) {
    
                                $preg_safe_name = preg_quote( $value[0], "'" );
    
    
    
                                if( empty( $xfieldsdata[$value[0]] ) ) {
    
                                        $tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template );
    
                                } else {
    
                                        $tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template );
    
                                }
    
    
    
                                $tpl->copy_template = str_replace( "[xfvalue_{$preg_safe_name}]", stripslashes( $xfieldsdata[$value[0]] ), $tpl->copy_template );
    
                        }
    
                }
    

    if($config[‘seo_type’]==‘1’)

    {

    $link= “$row[id]”.’-’."$row[alt_name]".’.html’;

    }

    else

    {

    $link="$row2[alt_name]".’/’."$row[id]".’-’."$row[alt_name]".’.html’;

    }

    $tpl->set( ‘{home_title}’,stripslashes($row[‘title’]));

    $tpl->set( ‘{home_author}’, stripslashes($row[‘autor’]));

    $tpl->set( ‘{home_date}’, $row[‘date’]);

    $tpl->set( ‘{link}’,$link);

    $tpl->compile(‘newhome_c’);

    }
    }

    create_cache (“newhome_c”, $tpl->result[‘newhome_c’], $config[‘skin’]);

    $tpl->clear();

    $db->free();

    }

    if ($is_change) $config[‘allow_cache’] = false;

    }

    ?>[/php]

    I think that is everything here :slight_smile:
    Can please someone help me?

    When it doesn’t work, what has happened? Have new items been added?

    Also, what error(s) are displayed when it does not work?

    Is fixed, thank you anyway mate :slight_smile:

    Sponsor our Newsletter | Privacy Policy | Terms of Service