PDA

View Full Version : below html/mysql syntax is correct: building links from php vars ?


lse123
11-25-2007, 06:09 PM
Can you tell me how to get values [eg. $photo=image3, $details=link3] from database table to build an image and a link ? below html/mysql syntax is correct ?
<? ... db connection & query from result I get...
$photo = mysql_result($result,$i,"photo");
$details = mysql_result($result,$i,"details");
...?>
[$photo=image1]
<img src="/images/search/.htmlentities($photo)..jpg" alt="h" width="200" height="132" />
or
[$photo="/images/search/image1.jpg"]
<img src="<?= $photo ?>" alt="h" width="200" height="132" />

is it correct to save urls in mysql tables or php vars ?
same implies to below ?
<a href="/apartments/akamasvillageargaka.php<?= $details ?>">

Inigoesdr
11-25-2007, 07:11 PM
You would have to show your query for more specifics, but this is one way:

<?php
// connect
$result = mysql_query('SELECT `photo` FROM `table` WHERE 1') or die('MySQL Query Failed. Error: ' . mysql_error());
while($row = mysql_fetch_assoc($result))
{
?>
<img src="/images/<?php echo $row['photo']; ?>.jpg" alt="h" width="200" height="132" />
<?php
}
?>
You could add some logic to make sure rows were returned before doing the loop.

lse123
11-25-2007, 07:53 PM
[This should work with $photo="/images/search/image1.jpg"]

<img src="<?= $photo ?>" alt="h" width="200" height="132" />

is it correct to save urls in mysql tables or php vars ?