Log in

View Full Version : Problem with putting image and positionning a div with an echo"div"



nicnicnic
11-14-2008, 03:45 AM
hi all, im new here and im new to php javascript also
i would need a help

what i want to do is to put a image and text from database so it can be like a news

with a button play it show the next news

i have trouble to display the image like it show below

http://img219.imageshack.us/my.php?image=testjf6.jpg

PROBLEM WITH DIV position is resolve



<html>
<head>
<title>Bibliothèque</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
var page_courante=1;
var nb_pages=1;

//Show previous page
function pagePrecedente() {
if (page_courante==1) {
alert("Vous êtes déjà sur la première page !");
} else {
affichePage(page_courante-1);
}
}

//show Next Page
function pageSuivante() {
if (page_courante==nbpages) {
alert("Vous êtes déjà sur la dernière page !");
} else {
affichePage(page_courante+1);
}
}

//show next page image text news and with a settimeout it change the news every 5 seconds
function play() {
if (page_courante==nbpages)
{
alert("Vous êtes déjà sur la dernière page !");
} else {
affichePage(page_courante+1);
}
setTimeout(play(),5000);
}

//Show Page Function
function affichePage (page){
document.getElementById("page"+page_courante).style.display = "none";
document.getElementById("lienpage"+page_courante).style.fontWeight = "normal";
document.getElementById("page"+page).style.display = "block";
document.getElementById("lienpage"+page).style.fontWeight = "bold";
page_courante=page;

}
</script>

</head>
<body>
<?php

//connect to the 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("test") or die("impossible de sélectionner la base de données <b>ecole</b>.<p>Veuillez réessayer plus tard");


//request path textNouvelle Fields with a select
$requeteStr = "SELECT path,textNouvelle from upload2";
$resultatRequete = mysql_query($requeteStr) or die("la requete de sélection a échoué.<p>Veuillez réessayer plus tard");
$resultat=mysql_query($requeteStr);
$cpt = mysql_num_rows($resultat);//number of result from the request
$rpp = 1;//Nombre de résultats à afficher par page
$nbpages = ceil($cpt / $rpp);//calculate numbers of page
$cpt2 = 0;//limit the number of results per page
$cpt3 = 0;//tell us when all data has been view
$cpt4 = 1;//send an id for every div id=\"page".$cpt4."\"


for ($i=1; $i<=$nbpages; $i++) {
echo " <a href=\"#\" id=\"lienpage".$i."\"></a>";

}



//Show divs
while($ligne=mysql_fetch_array($resultat)){
if ($cpt2 == 0) {
if ($cpt4 == 1) //Lors de la requète, on affiche les premiers enregistrements
echo "<div id=\"page1\" style=\"display: inline;\">";
else //Ensuite, les enregistements suivants sont cachés
echo "<div id=\"page".$cpt4."\" style=\"display: none; position:absolute; top:100; left:140;\">";since the div contains the table i would like to put the div in a certain position on the page, but this aint working atm with the top left...

echo "<table border=\"1\"><tr><td><b>Titre</b></td></tr>";//affichage de la légende
$cpt4++;
}
$cpt2++;
$cpt3++;
echo "<tr><td>".$ligne["textNouvelle"]."<img src=".$ligne["path"]."></td></tr>";//Affichage des enregistrements]
if ($cpt2 == $rpp || $cpt3 == $cpt) {//Lorsque l'on affiché rpp enregistrements ou que tous les enregistrements ont été affichés, on ferme le calque
echo "</table></div>";
$cpt2 = 0;
}
}
?>

<button onClick="pagePrecedente()">Page précédente</button>
<button onClick="pageSuivante()">Page suivante</button>
<button onClick="play()">Play</button>
<script type="text/javascript">
var nbpages=<?php echo $nbpages;?>
</script>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>


this is the table im working with
CREATE TABLE upload2 (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
path VARCHAR(60) NOT NULL,
textNouvelle VARCHAR(120) NOT NULL,
PRIMARY KEY(id)
);

http://img219.imageshack.us/my.php?image=imagescv5.jpg
the path in the database is all fine

so i dunno why the image aint showing right

ty for the help in advance hope someone will help me out

p.s. i know my english aint the best lol so if im not clear let me know so we can discuss about it

rangana
11-14-2008, 04:36 AM
Try to echo that line of the source:


echo $ligne["path"];


Now check if that is you're expected output.

nicnicnic
11-14-2008, 05:06 AM
ty to have reply
well i try it but this it

i show you where i put the new change dunno if its where i need to put it ? but when i do this its shows me just the results
of the path name like i show it in the screenshot

it shows D:\lol\Autumn_Leaves.jpg

http://img219.imageshack.us/my.php?image=aaaaaawalo2.jpg

p.s. i know i will have to change the button place i didnt have time to do it yet

so i really dunno how to resolve this problem, thats why im asking for help
and ty to take your time to help me i really appreciate it
hope you can help me out


while($ligne=mysql_fetch_array($resultat))
{
if ($cpt2 == 0) {
if ($cpt4 == 1) //Lors de la requète, on affiche les premiers enregistrements
echo "<div id=\"page1\" style=\"display: inline; position:absolute; top:100; left:140;\">";
else //Ensuite, les enregistements suivants sont cachés
echo "<div id=\"page".$cpt4."\" style=\"display: none; position:absolute; top:100; left:140;\">";


echo $ligne["path"];


echo "<table border=\"1\"><tr><td><b>Titre</b></td></tr>";//affichage de la légende
$cpt4++;
}
$cpt2++;
$cpt3++;
echo "<tr><td>".$ligne["textNouvelle"]."<img src=".$ligne["path"]."></td></tr>";//Affichage des enregistrements
if ($cpt2 == $rpp || $cpt3 == $cpt) {//Lorsque l'on affiché rpp enregistrements ou que tous les enregistrements ont été affichés, on ferme le calque
echo "</table></div>";
$cpt2 = 0;
}
}

rangana
11-14-2008, 05:33 AM
Does that image exist on that said folder?

The generated source is D:\lol\Autumn Leaves.jpg and not D:\lol\Autumn_Leaves.jpg

nicnicnic
11-14-2008, 05:44 AM
yeah i upload the files into this folder

http://img221.imageshack.us/my.php?image=filesautomnleavesmr9.jpg

i move the file to this folder with move_upload_file


this is my upload.php file to load the file in the mysql phpmyadmin database

<?php
$uploadDir = 'D:\\lol\\';

if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);

$fileName = addslashes($fileName);
$filePath = addslashes($filePath);


$texteNouvelle = $_POST['texteNouvelle'];


$connection = mysql_connect("localhost","root","") or die("impossible de se connecter au serveur mysql.<p>Veuillez réessayer plus tard");
$res = mysql_select_db("test") or die("impossible de sélectionner la base de données <b>ecole</b>.<p>Veuillez réessayer plus tard");
$requeteStr = "INSERT INTO upload2 (name, size, type, path,textNouvelle ) "."VALUES ('$fileName', '$fileSize', '$fileType', '$filePath','$texteNouvelle')";
$resultatRequete = mysql_query($requeteStr) or die("la requete de sélection a échoué.<p>Veuillez réessayer plus tard");
$result=mysql_query($requeteStr);

}
?>



<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246" style="height: 95px"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile">
<br>
<br>
<textarea name="texteNouvelle" style="width: 263px; height: 61px"></textarea><br>
<br>
<br>
</td>
<td style="height: 95px; width: 51px" class="style1"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>


$uploadDir = 'D:\\lol\\';

is my two \\ slashes right ?

$fileName = addslashes($fileName);
$filePath = addslashes($filePath);

and addslashes too ? im wondering if thats correct now

i wish so hard this image thing can be resolve its giving me a headeache... and ty for ur time again

i can do some research of my news with a select like query

but without showing the image its sucks ...

rangana
11-14-2008, 06:17 AM
It appears to be confusing now. Why would you move the file? Do you have a link instead?

The slashes seem right.

Are you using a cross-platform web server like XAMPP or WAMPP?