Gallery Pagenation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Janes
Forum Newbie
Posts: 2
Joined: Sun Mar 16, 2008 3:50 am

Gallery Pagenation

Post by Janes »

Hi.

I am learning php at the moment and i am struggling with the folowing thing:

I have a database with image paths and titles.

I want to write function that displays it in 4 columns and multiple rows.

I have searched the net and I have only found complete scripts but I want to do this myself.
So can anyone just point me in the right direction please.

thanks! :banghead:
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: Gallery Pagenation

Post by highjo »

hi!
can you at leat select the data?
if yes that means you sql statement is correct.Do you know how to fetch the data? after this there is not much to do.
write your html table with the ordnary stuff.make your fetching script return table row "<tr><td> your fetched title</td><td><img src='fetchedaddress'cwith necessary attributes/></td></tr>".put it in your function and call your funcion in the html page like this:

Code: Select all

<table>
<thead>
<th>column1</th>
<th>column2</th></thead>
<?php 
 $data = yourfuntion();
echo $data;
?>
</table>
 
since you want to do it yourself i don't know much how explicit i can be.So if you are facing a problem.post your own script here and get helped. :D
Janes
Forum Newbie
Posts: 2
Joined: Sun Mar 16, 2008 3:50 am

Re: Gallery Pagenation

Post by Janes »

Code: Select all

 
<?php
function Gallery() {
        include ('config.php');
    
        $con = mysql_connect($host, $user, $pass);
            if (!con)
            {
            die ('could not connect' . mysql_error());
            }
        
        mysql_select_db($db, $con);
        
        echo "<table><tr>";
        
        $result = mysql_query("SELECT * FROM gallery");
        while($row = mysql_fetch_array($result))
        {
        
        echo "<td><img src='" . $row['path'] . "' /></td>";
        
        }
        
        echo "</tr></table>";
}
        
?>
 
<?php Gallery();?>
 
 
The Above will put print everything in the database but the problem is it prints it next to each other.
I want it to print for example 2 in a row but mutliple rows.

I am not sure how to make it put it in different rows.

Hope that explains ait a bit more.
Post Reply