Jump to content

Problems with SQL query to show 3 records


Divvy

Recommended Posts

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...

 

Look:

http://screensnapr.com/e/Zm4ssA.jpg

 

Only "Filmes" is showing, but not "Series"...

 

the movies block sometimes have this issue too... 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:

<div id="page_content" class="clearfix">
{info} {newhome_final} {content}
</div>

 

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

<li style="margin-right: 45px;" onclick="window.location='{link}'">
<a title='{home_title}' href="{link}"><img src="[xfvalue_poster]" alt='{home_title}' /></a>
<h3 style="overflow:hidden"><a title='{home_title}' href="{link}">{home_title}</a></h3>
</li>

 

in my index.php I have this code:

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 = '<div class="index_top1" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " >						
<span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/movies.gif">
</span>
<ul class="clearfix">
{newhome}
</ul>
</div>
<div class="index_top2" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " >
<span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/serie.gif">
</span>
<ul class="clearfix">
{newhome_b}
</ul>
</div>
<div class="index_top3" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " >
<span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/music.gif">
</span>
<ul class="clearfix">
{newhome_c}
</ul>
</div>
<div class="index_top6" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " >
<span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/jogo.gif">
</span>
<ul class="clearfix">
{newhome_e}
</ul>
</div>
<div class="index_top4" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " >
<span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/programas.gif">
</span>
<ul class="clearfix">
{newhome_d}
</ul>
</div>';
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'] );

 

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
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;

}

?>

 

I think that is everything here :-)

Can please someone help me?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.