thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Add a Gallery #253

Open Nayden87 opened 5 years ago

Nayden87 commented 5 years ago

Hello guys, sorry to bother you but i want to ask for your help..

But first thing first its.. thank you very much for the guide and how good you can explain everuthig, you are just amazing.

Now, my problem is the following. I watched all the videos and the website its working just fine, but now i want to add a dynamic gallery. i coded everything, created a new database table and tested the code and its just perfect (at leaast for me XD), but now i want to link my gallery.php to the navigation bar and here is my problem.

i get just lost with the view folder etc. can somebody please help me or explain me how i can do this?

I tried to do it throught the database (putting the gallery.php link in navigation table in the databse) but when i go to the front end and i press the gallery button, it direct me to my gallery but i loose the dynamic view of the website. i hope this make sense.

Thank you so much for you help in advance guys

creptor commented 5 years ago

Hi,

I wouldn't have any problem helping you out but please be patient, I have some test left this week so I have to study right now, maybe on Thursday I'll have some time but until then please try to upload a picture of the current gallery and the code files pls.

creptor commented 5 years ago

The problem you have could be that you need a "page" to have the "view" "gallery.php", and not directly the "view".

I don't know if I explained myself correctly, but the idea is that...

You create pages, that are based on a file, that is located in "view". So you need to link the page (url) and not the file (inside the "view" folder).

Example:

http://example.com/gallery

Is not the same as...

http://example.com/view/gallery.php
Nayden87 commented 5 years ago

First thing first, thank you so much for your help and time, and please.. i understand how is it whn you are under a deadline with a test etc so please focus on you things first, i really appreciate your help and time.

I am sorry but the concept is not that clear to me.

This is my gallery php file..


<?php include ('../config/setup.php');?>
<?php include('../config/connection.php');?>
<?php include ('../template/navigation.php');?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $page['title'].' - '.$site_title ;?></title>

<!-- META DATA-->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<?php include ('../config/gallery.php');?>  
<?php include ('../config/css.php');?>
<?php include ('../config/js.php');?>

</head>
<body>

<?php

$gallery = "SELECT * FROM gallery";
$result = mysqli_query($dbc, $gallery) or die("Something went wrong: $gallery");

?>
<div class="container">
<?php 
    echo "<table>";
            $i = 0;

            while($row = mysqli_fetch_assoc($result)) {
                if($i%3 == 0) {
                    echo "<tr>";
                } 
                echo "<td><img src='img/{$row['img']}' alt='{$row['title']}' class='thumbnail'></td>";
                if($i%3 == 2){
                    echo"</tr>";
                }
                $i++;
        }
    echo "</table>";

?>
</div>

</body> 

I explain you my idea and what i did. i create this file gallery.php and i put it in views folder I create a link on the navigation bar named "Gallery" in the database and i give him the url localhost/example/gallery.

but now is where i get confused because i dont know what to do, when i click on "Gallery"link i just get back a blank page with a empty body and i dont know how to retrieve my image from the databse.

I tried to do something else, such as in the database in the navigation put as url "localhost/example/views/gallery.php", and when i go on the front end and click gallery, it retrieve the images from the databse but my navigation bar and footer disappear.

I am just confused about how the files work on this part as i didnt get exactly this part.

I hope i explained myself properly,

P.S all my files are exactly the same as in the github project, i just write this gallery code and tried to include it in the gallery link. Thank you vero much for your help again

Nayden87 commented 5 years ago

Sorry, i solved the problem that i was asking about before, at the end i understood how it works, but now i have another question.

In the php code posted above, the gallery was working just fine, i could retrieve and display easly the image store in my "img" folder

echo "<td><img src='img/{$row['img']}' alt='{$row['title']}' class='thumbnail'></td>";

but now i cant, i can display only the image title, and this is because the image link is not correct.

I realized if i go on navigation table on the databse and i set the url as

http://localhost/hamzadesign1/gallery

and than i open my web page and check the console i have this result as URL requested

http://localhost/hamzadesign1/gallery/images/pexels-photo-257360.jpeg

basically is looking for a folder gallery (same as i insert in the database in navigation table) that actually i dont have because al my image are in front end folder views

if can you help me to understand this i will really appreciate it.