Jump to content

Recommended Posts

Currently all of my implodes displays as text strings properly... i have a field called 'hotel_img' which contains a URL to an image in my MySQL database... but im not sure if i am doing it properly here as the image does not load:

 

<?php
// Connect database
include("includes/connectdb.php");

$sql="SELECT hotel_id, hotel_name, hotel_location, hotel_desc, hotel_img FROM hotel ORDER BY hotel_name ASC";
$result=mysql_query($sql);

$options="";

$id_array = array();
$hotel_name = array();
$hotel_location = array();
$hotel_desc = array();
$hotel_img = array();

while ($row=mysql_fetch_array($result)) {

    $id_array[]=$row["hotel_id"];
    $hotel_name[]=mysql_real_escape_string($row["hotel_name"]);
    $hotel_location[]=mysql_real_escape_string($row["hotel_location"]);
    $hotel_desc[]=mysql_real_escape_string($row["hotel_desc"]);
$hotel_img[]=mysql_real_escape_string($row["hotel_img"]);
    $options.="<option VALUE='".$row["hotel_id"]."'>".$row["hotel_name"]."</option>";
}

?>

 

I am using implode and it works with the strings:

 

<?php echo "var thetext1 = new Array('".implode('\',\'',$hotel_name)."');"; ?>
<?php echo "var thetext2 = new Array('".implode('\',\'',$hotel_location)."');"; ?>
<?php echo "var thetext3 = new Array('".implode('\',\'',$hotel_desc)."');"; ?>
<?php echo "var thetext4 = new Array('".implode('\',\'','<img src="'.$row["hotel_img"].'" >')."');"; ?>

 

Not sure what have done wrong... any ideas?

Link to comment
https://forums.phpfreaks.com/topic/188185-implode-and-display-as-a-image/
Share on other sites

Im doing this bit wrong:

 

<?php echo "var thetext4 = new Array('".implode('\',\'','<img src="'.$row["hotel_img"].'" >')."');"; ?>

 

Initially it was

<?php echo "var thetext4 = new Array('".implode('\',\'',$hotel_img)."');"; ?>

 

But this only displays a URL but i want it to display the image instead of a URL.

Couple of things. Firstly, why are you calling mysql_real_escape_string() on information that you have pulled out of the database? This function is designed to escape data that you are placing in the database. Secondly, if you are only going to use the associative keys to access the data fetched by mysql_fetch_array, then you would be better off using mysql_fetch_assoc. Thirdly, your <img tag isn't closed so it's not valid HTML. You need a / before the >, not sure this would cause your problem though. Finally, have you checked the output to see if there are any obviously mistakes in what your PHP is outputting? Ie view source in your browser. If you can't see anything there perhaps if you post some of the output somebody else will see something.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.