HTML Code:<html> <head> <title>News</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> page_courante=1; demarree = false; function pagePrecedente() // Previous { if (page_courante!=1) affichePage(page_courante-1); } function pageSuivante() // Next { if (page_courante!=nombrePages) affichePage(page_courante+1); } function play() { if (demarree==false) return; if (page_courante!=nombrePages) affichePage(page_courante+1); timeOut = setTimeout('play()', 2000); } function stop() { clearTimeout(timeOut); } // display the news function affichePage(page) { document.getElementById("page"+page_courante).style.display = "none"; document.getElementById("page"+page).style.display = "block"; page_courante=page; } </script> </head> <body> <button onClick="pagePrecedente()">Page précédente</button> <button onClick="pageSuivante()">Page suivante</button> <button onClick="if (!demarree) {demarree=true;play();}">Play</button> <button onClick="demarree=false;">Stop</button> <script type="text/javascript"> nombrePages =<?php echo $nbpages;?> </script> </body> </html>here is my code for the news with the text and image you can put the php code inside the body and it will workCode:<?php
//connection to database
$connection = mysql_connect("localhost","root","") or die("impossible de se connecter au serveur mysql.<p>Veuillez réessayer plus tard");
$res = mysql_select_db("upload2") or die("impossible de sélectionner la base de données <b>ecole</b>.<p>Veuillez réessayer plus tard");
//request select
$requeteStr = "SELECT path,name,texteNouvelle from upload2";
$resultat = mysql_query($requeteStr);
//calcul
$cpt = mysql_num_rows($resultat);//Number of result from request
$rpp = 1;//number of results per page
$nbpages = ceil($cpt / $rpp);//Count number of pages
$i = 1; // id of the page
//show results
while ($ligne=mysql_fetch_array($resultat))
{
if ($i == 1) //show first result
echo "<div id=\"page1\" style=\"display: block;\">";
else
echo "<div id=\"page".$i."\" style=\"display: none;\">";
echo "<table><tr><td></td></tr>";
echo "<tr><td>".$ligne["texteNouvelle"]."</td></tr>";//texteNouvelle = text news
?>
<img height="300" src="<?echo $ligne['path'].$ligne['name']?>">
<?
echo "</table></div>";
$i++;
}
?>
my path directory is './data/' when i do the upload
if you guys want to tell me some advice on how to improve the code
tell me i willl be happy to hear it
and if u want the upload file part
ask me
i will show it
Last edited by nicnicnic; 11-19-2008 at 11:12 AM.
One suggestion, if you want to go more advanced, is to store the pictures in the database instead of the filesystem. I's a little bit more tricky, but it is helpful if there are going to be many pictures.
Part I: Tutorial: Storing Images in MySQL with PHP
Part II: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images
rgr ty orjan
and ty all !
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks