Page 1 of 1
Gallery Pagenation
Posted: Wed Jun 04, 2008 3:40 am
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!

Re: Gallery Pagenation
Posted: Wed Jun 04, 2008 5:51 am
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.

Re: Gallery Pagenation
Posted: Wed Jun 04, 2008 7:01 am
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.