Hi, i'm creating a image gallery, using .htaccess. And this is my first time i work with .htaccess

So i have this code, and it's allright but there's just one thing...the images don't appear. What i want is if:

if $clean_url[2]=='all'
//ALL IMAGES

if $clean_url[2]!='all'
//IMAGES w/ title='$clear_url[2]'

I have strong feelings that is because of the SQL Queries. So here's my code:

<?php

if($clean_url[2] == "all"){
     $page_number = 1;
    // how many records per page
    $size = 8;

    // we get the current page from $_GET
    if (isset($_GET['page'])){
        $page_number = (int) $_GET['page'];
    }

    $result_images=mysql_query("SELECT * FROM  album_lang WHERE lang='".$current_lang."'");
    $row_images=mysql_fetch_assoc($result_images);

    $result_content=mysql_query("SELECT * FROM album_images WHERE visivel=1 ");
    $total_records = mysql_num_rows($result_content);

    $result_imagens=mysql_query("SELECT * FROM album_images_lang WHERE id_image='".$total_records['id']."' AND lang='".$current_lang."' AND visivel=1");
    $total_imagens=mysql_fetch_assoc($result_imagens);

    // create the pagination class
    $pagination = new Pagination();
    $pagination->setLink($current_lang."/product/all?page=%s");
    $pagination->setPage($page_number);
    $pagination->setSize($size);
    $pagination->setTotalRecords($total_records);

    $result_content=mysql_query("SELECT * FROM album_lang WHERE titulo='' AND lang='$current_lang' AND visivel=1 " . $pagination->getLimitSql());

    $navigation = $pagination->create_links();

}else{
    if(isset($clean_url[2])!= "all"){
        $result_content=mysql_query("SELECT * FROM album_lang WHERE titulo='".$clean_url[2]."' AND lang='$current_lang' AND visivel=1");
    }else{

        $page_number = 1;

        // how many records per page
        $size = 8;

        // we get the current page from $_GET
        if (isset($_GET['page'])){
            $page_number = (int) $_GET['page'];
        }

        list($tax_name, $tax_id) = explode("-", $page);

        $result_content=mysql_query("SELECT * FROM album_images WHERE id_projecto='".$tax_id."' AND visivel=1");
        $total_records = mysql_num_rows($result_content);

        // create the pagination class
        $pagination = new Pagination();
        $pagination->setLink($current_lang."/product/all?page=%s");
        $pagination->setPage($page_number);
        $pagination->setSize($size);
        $pagination->setTotalRecords($total_records);

        $result_content=mysql_query("SELECT * FROM album WHERE id='".$tax_id."' AND lang='$current_lang' AND visivel=1 " . $pagination->getLimitSql());

        $navigation = $pagination->create_links();

    }
}

$num_rows_content = mysql_num_rows($result_content);
$conta_rows_content = 1;
$content = "";

if($num_rows_content > 0 || $page == "all"){
    echo '<div class="content" id="page">
                    <div class="container">
                        <div class="interior_page" style="border-bottom:0px;">';
                            if($page == "all"){
                                $pageTitle="GALERIA";
                            }else{
                                if(isset($clean_url[3]) && $clean_url != ""){
                                    $pageTitle = $row_content->titulo;
                                }else{
                                    $result_tax_titulo = mysql_query("SELECT * FROM `taxonomia_page` WHERE id='". $tax_id."' LIMIT 0,1");
                                    $row_tax_titulo = mysql_fetch_object($result_tax_titulo);

                                    $pageTitle = $row_tax_titulo->title;
                                }
                            }

                            echo '<div id="menu_produtos">';

                            echo '</div>';


                            if($num_rows_content > 1 || $page == "all" || !isset($clean_url[3])){

                                //Se existir mais que um produto apresenta a listagem de todos os existentes

                                echo '<div id="products">';
                                    echo "<h1 class='title'>".$pageTitle."</h1>";

                                    echo '<div class="produts_list">';

                                    $count_products = 1;

                                    while($row_products = mysql_fetch_object($result_content)){
                                        $extra = unserialize(base64_decode($row_products->extra));

                                        $clean_descricao = strip_tags($row_products->descricao);

                                        $result_tax = mysql_query("SELECT * FROM `taxonomia_page` WHERE id='".$row_products->taxonomy_id."' LIMIT 0,1");
                                        $row_tax = mysql_fetch_object($result_tax);

                                        if($count_products == 2)
                                            echo '<div class="product last">';
                                        else
                                            echo '<div class="product">';
                                            if($extra['capa'] != "")
                                                echo '<a href="'.$current_lang.'/product/'.$row_tax->link."-".$row_tax->id.'/'.$row_products->url.'">'.image_preset($extra['capa'], 'thumb_products', 'align="left"')."</a>";
                                            echo '<label class="titulo"><a href="'.$current_lang.'/product/'.$row_tax->link."-".$row_tax->id.'/'.$row_products->url.'">'.$row_products->titulo.'</a></label>';
                                            echo '<label class="tax"><a href="'.$current_lang.'/product/'.$row_tax->link."-".$row_tax->id.'">'.$row_tax->title.'</a></label>';

                                            echo '<label class="descricao">'.substr($clean_descricao, 0 ,120);
                                                if(strlen($clean_descricao) > 120)
                                                    echo "(...)";
                                            echo '</label>';
                                        echo '</div>';

                                        if($count_products == 2)
                                            $count_products = 1;
                                        else
                                            $count_products++;
                                    }

                                    echo '<div class="clearfloat"></div>'; 
                                    echo $navigation; // will draw our page navigation
                                    echo '<div class="clearfloat"></div>'; 
                                    echo '</div>';

                                echo '</div>';

                            }else{
                                //Se apenas existir um produto mostra logo a página do mesmo e não a listagem

                                $row_products = mysql_fetch_object($result_content);
                                $extra = unserialize(base64_decode($row_products->extra));

                                $pageTitle = $row_products->titulo;

                                echo '<div id="products">';


                                    echo '<div class="product_details">';
                                        echo '<div class="extras">';
                                            echo '<div class="images">';
                                                if($extra['capa'] != "")
                                                echo '<a href="'.$extra['capa'].'" rel="group" title="'.$pageTitle.'">'.image_preset($extra['capa'], 'thumb_image', 'align="left" alt="'.$pageTitle.'"').'</a>';
                                            echo '</div>';

                                            $result_moresimages = mysql_query("SELECT ni.id, ni.imagem, ni.visivel, nil.titulo FROM `node_images` as ni, `node_images_lang` as nil 
                                            WHERE ni.id = nil.id_image AND nil.lang='$current_lang' AND ni.visivel=1 AND nil.visivel=1
                                            AND ni.nid = ".$row_products->id." ORDER BY ni.posicao ASC");
                                            if(mysql_num_rows($result_moresimages) > 0){
                                                echo '<div class="more_images">';
                                                    echo '<ul>';
                                                    while($row_moreimages = mysql_fetch_object($result_moresimages)){
                                                        echo '<li><a href="'.$row_moreimages->imagem.'" rel="group" title="'.$row_moreimages->titulo.'">'.image_preset($row_moreimages->imagem, 'thumb_miniimage', 'align="left" alt="'.$row_moreimages->titulo.'"').'</a></li>';
                                                    }
                                                    echo '</ul>';
                                                    echo '<div class="clearfloat"></div>'; 
                                                echo '</div>';
                                            }

                                            if($extra['anexo'] != "")
                                                echo '<a href="'.$extra['anexo'].'" class="bt_maisinformacoes" target="_blank">DESCARREGUE O CATÁLOGO EM PDF</a>';


                                        echo '</div>';

                                        echo '<div class="descricao">';
                                            echo "<h1 class='title'>".$pageTitle."</h1>";
                                            echo $row_products->descricao;
                                        echo '</div>';
                                        echo '<div class="clearfloat"></div>'; 
                                    echo '</div>';

                                echo '</div>';

                            }

                            echo '<div class="clearfloat"></div>'; 
                        echo  '</div>
                <div class="clearfloat"></div>';
    echo  '</div>
        </div>';

}else{
    header("Status: 404 Not Found");
    header( "Location: ".$url."/".$current_lang."/pages/error/404" );
    die();
}

?>

Help me please,
thank you,
PF2G

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

I have strong feelings that is because of the SQL Queries. So here's my code:

I don't see anything wrong with the query.

But I do see this $clean_url[2] as an issue.

I don't see this often using a htaccess file to store a code so query can SELECT the value from it.

There are 2 things that might not be working:

1) is your database is connected to the htaccess file
2) is your htaccess file is in the same folder with this query file.

This is by far the most iffy/weird post I seen and read, the reason is using the htaccess file to store a value and used a query to fetch the data from htaccess?

This is my point of view and answer to your image gallery issue.

Hi, i'm creating a image gallery, using .htaccess. And this is my first time i work with .htaccess

Simple, you cannot use .htaccess for this. You cannot execute code in that manner.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.