html - send ID to PHP script and return img src tag from DB filename -
i trying easy sure have looked , tested , not doing right. have db stores image file name, need file name based on id in html , let me explain:
<div class="slide"> <div class="image-holder"> <img src="img/asoft_table.jpg" alt="" /> </div> <div class="info"> <p>morbi tellus lorem, id scelerisque ligula. maecenas vitae turpis et.</p> </div> </div> <div class="slide"> <div class="image-holder"> <img src="img/soft_table.jpg" alt="" /> </div> <div class="info"> <p>sed semper, lorem ac lobortis bibendum, magna neque varius augue, vel accumsan.</p> </div> </div> <div class="slide"> <div class="image-holder"> <img src="img/living_room2.jpg" alt="" /> </div>
in each instance of img tag, need insert filename db. so, first image tag primary key 1, second primary key 2 , forth. here php script using retrieve filename, works, unsure how send id of image script , return properly.
<?php $hote = 'localhost'; $base = '*****'; $user = '*****'; $pass = '*****'; $cnx = mysql_connect ($hote, $user, $pass) or die(mysql_error ()); $ret = mysql_select_db ($base) or die (mysql_error ()); $image_id = mysql_real_escape_string($_get['id']); $sql = "select image image_upload id ='$image_id'"; $result = mysql_query($sql); $image = mysql_result($result, 0); header('content-type: text/html'); echo '<img src="' . $image . '"/>'; exit; ?>
any appreciated, heap
from looks trying hard separate php html.
// file: index.php <?php $hote = 'localhost'; $base = '*****'; $user = '*****'; $pass = '*****'; $cnx = mysql_connect ($hote, $user, $pass) or die(mysql_error ()); $ret = mysql_select_db ($base) or die (mysql_error ()); $image_id = mysql_real_escape_string($_get['id']); $sql = "select image image_upload id ='$image_id'"; $result = mysql_query($sql); //$image = mysql_result($result, 0); $image = array(); while ($row = mysql_fetch_assoc($result)) { $image[] = $row["image"]; } ?> <html> <head> </head> <body> <div class="slide"> <div class="image-holder"> <img src="<?php echo $image[0];?>" alt="" /> </div> <div class="info"> <p>morbi tellus lorem, id scelerisque ligula. maecenas vitae turpis et.</p> </div> </div> <div class="slide"> <div class="image-holder"> <img src="<?php echo $image[1];?>" alt="" /> </div> <div class="info"> <p>sed semper, lorem ac lobortis bibendum, magna neque varius augue, vel accumsan.</p> </div> </div> <div class="slide"> <div class="image-holder"> <img src="<?php echo $image[2];?>" alt="" /> </div> </body> </html> // magic code rows out of database :) // $row[ field_name ]; while ($row = mysql_fetch_assoc($result)) { $image[] $row["image"]; }
edit:
i'm not sure if trying accomplish, thought i'd share anyway.
$imageid1 = $_get['id1']; $imageid2 = $_get['id2']; $imageid3 = $_get['id3']; $sql = "select image image_upload "; $sql = "where id = $imageid1 or id = $imageid2 or id = $imageid3"; //the rest of code can remain same.
or if 1 id relates 3 images.
$sql = "select * image_upload id ='$image_id'"; $result = mysql_query($sql); $image = array(); $row = mysql_fetch_assoc($result); $image1 = $row["image1"]; $image2 = $row["image2"]; $image3 = $row["image3"];
i've give me more info on trying do, i'd happy give better example.
Comments
Post a Comment