wispas Posted January 12, 2010 Share Posted January 12, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/188185-implode-and-display-as-a-image/ Share on other sites More sharing options...
wispas Posted January 12, 2010 Author Share Posted January 12, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188185-implode-and-display-as-a-image/#findComment-993508 Share on other sites More sharing options...
cags Posted January 12, 2010 Share Posted January 12, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188185-implode-and-display-as-a-image/#findComment-993514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.