problem with variables from php to html and echo

Hello,
i am connecting to a database and then bring the ten most popular images to show them to the client,
but there are problems with echoing the results to the client. It returns errors similar to this one “Parse error: parse error, expecting `T_STRING”.
I suspect there might be problems in the way i use echo, using “” or ‘’,the use of integer variables as strings
and the paths in the code bellow, any help is appreciated.Also please be a bit extensive i would like to understand the solution except of solving the problem.

[php]<?php
$con=mysql_connect(“localhost”,“root”,"");
if(!$con)
die(‘Could not connect’.mysql_error());
mysql_select_db(“user_details”,$con);
$result=mysql_query(“SELECT * FROM image WHERE type=‘public’ ORDER BY views DESC “)
or die(mysql_error());
$i=0;
while(($row = mysql_fetch_array($result))&&(i<10)){
$width=(i%5)*150;
$height=(i/5)*150;
$imgName=”\archive”.$row[‘title’];
echo"<div
style=" top: “$height”; left: “$width”; position: absolute; z-index: 1; visibility: show; ">




";
$i++;
}

[/php]

Have you echoed out the result of $imgName

or try
[php]<img src=’".$imgName."’[/php]

<img src=\"$imgName\"

i is a var so should be $i

[php]while(($row = mysql_fetch_array($result))&&(i<10)){
$height=(i/5)*150;
$height=(i/5)*150;[/php]
[php]while(($row = mysql_fetch_array($result))&&($i<10)){
$height=($i/5)*150;
$height=($i/5)*150;[/php]

Thank you for the reply, actually i tried different things and found i had many mistakes including the things you wrote, here is the corrected code:

[php]<?php
$con=mysql_connect(“localhost”,“root”,"");
if(!$con)
die(‘Could not connect’.mysql_error());
mysql_select_db(“i-mage”,$con);
$result=mysql_query("SELECT * FROM image WHERE type=‘public’ ORDER BY views DESC “)
or die(mysql_error());
$i=0;
while(($row = mysql_fetch_array($result))&&($i<10)){
$width=($i%5)*150;
$height=(integer)($i/5)*150;
$imgName=‘archive/’.$row[‘title’];
echo “<div
style=” top: $height; left: $width; position: absolute; z-index: 1; visibility: show; “>
<a href=“imageview.php” >
<img src=”$imgName” height=“150” width=“150” border=“1” >


";
$i++;
}
?>[/php]

So it works now ?

Yes its done. Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service