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!
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.
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:
<?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.