grimm1 Posted October 6, 2013 Share Posted October 6, 2013 I have a mysql database and from it I wish to populate a web page with the results. The results are sorted by manufacturer and there are 3 results per manufacturer. A Manufacturer's logo heads each section of the page. My image is 200 x 200 and is stored in the database as a blob. (I can place the image if I source it from a folder on my machine using a file path no problem). Can anyone spot what I am doing wrong? I have been on this on and off for 24 hours. I have posted this on another forum and have incorporated it into my query. Unfortunately, it is not working. The query works fine in myPHPadmin. Thanking you in advance. <!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><title>Car Results List | My Cars INC</title><link rel="stylesheet" href="css/websitereset.css" /><link rel="stylesheet" href="css/websitetext.css" /><link rel="stylesheet" href="css/960_24_col.css" /><link rel="stylesheet" href="css/websitestyles.css" /></head><body><h1><a href="default.html">My Cars INC</a></h1><div class="container_24"><div class="grid_10" style="float:right;" id="block"><ul id="usernav"><li onClick="window.location.href='contact.html'"><a href="contact.html">Contact</a></li></ul></div><div class="clear"></div><div class="container_24" id="header"><div class="grid_24" id="banner"><p> </p></div><div class="grid_20" id="addbanner"><p><br><br><br></p></div></div><div class="clear"></div> <div class="grid_4" id="nav"><h5>Model Types</h5><!--<p>Sorted by Manufacturer --></p><p><img src="img/logo_th/audi.gif"/></p><?php$db = mysql_connect("localhost", "root", "")or die ("Couldn't connect to Server!");$result = mysql_select_db("mycarsinc_inventory", $db)or die ("Couldn't select Database!");$query = "select img, make, price(no vat), from tbl_automatic WHERE MakeID = '27'";$result = mysql_query($query,$db)or die ("Couldn't execute query!");while($row = mysql_fetch_array($result)){}?><div class="cardetails"> <a href="car.html"><img src="img/audicarpic1.jpg"/></a><p class="make"><a href="car.html"><?$['audi']?><a></p><p class="price"><?=$q['Price(No VAT)']?></p><div class="clear"></div> </div> <div class="cardetails"> <a href="car.html"><img src="img/audicarpic2.jpg"/></a><p class="make"><a href="car.html"><?$['audi']?><a></p><p class="price"><?=$q['Price(No VAT)']?></p><div class="clear"></div> </div> <div class="cardetails"><a href="car.html"><img src="img/audicarpic3.jpg"/></a><p class="make"><a href="car.html"><?$['audi']?><a></p><p class="price"><?=$q['Price(No VAT)']?></p><div class="clear"></div> </div> <p><img src="img/logo_th/ford.gif"/></p><div class="cardetails"> <a href="car.html"><img src="img/fordcarpic1.jpg"/></a><p class="make"><a href="car.html"><?$['ford']?><a></p><p class="price"><?=$q['Price(No VAT)']?></p><div class="clear"></div> </div> <div class="cardetails"> <a href="car.html"><img src="img/fordcarpic2.jpg"/></a><p class="make"><a href="car.html"><?$['ford']?><a></p><p class="price"><?=$q['Price(No VAT)']?></p><div class="clear"></div> </div> <div class="cardetails"><a href="car.html"><img src="img/fordcarpic3.jpg"/></a><p class="make"><a href="car.html"><?$['ford']?><a></p><p class="price"><?=$q['Price(No VAT)']?></p><div class="clear"></div></div> Quote Link to comment https://forums.phpfreaks.com/topic/282761-php-query-to-return-html-links/ Share on other sites More sharing options...
Barand Posted October 6, 2013 Share Posted October 6, 2013 For the sake of those of us who aren't looking over your shoulder to see the results, or who are sadly lacking in the clairvoyance department, please define "not working" Quote Link to comment https://forums.phpfreaks.com/topic/282761-php-query-to-return-html-links/#findComment-1452828 Share on other sites More sharing options...
vinny42 Posted October 6, 2013 Share Posted October 6, 2013 Images in HTML must either be called using an SRC element and cause a seprate hit on the webserver which would then fetch the blob from the database (which is bad idea because it loads up your database with filesystem work) or you must encode the blob data as base64 into the HTML source, another not so good idea. The best solution is to cache the images on disk and link them the usual way in the IMG tag. That way you can instruct the clients not to refresh it for a fe weeks, which saves lots of bandwidth. Quote Link to comment https://forums.phpfreaks.com/topic/282761-php-query-to-return-html-links/#findComment-1452830 Share on other sites More sharing options...
grimm1 Posted October 6, 2013 Author Share Posted October 6, 2013 Vinny42, thanks for your advice. I will cache the images. Barand, Sorry for not making my problem clear. I am new to php and MySQL. My expertise is in networking and I am trying something new. What I mean by "not working" is that when I click on the link to the page, I would like to see an image, a hyperlink with the make of the car and the price for each car. Unfortunately nothing appears on the page. Quote Link to comment https://forums.phpfreaks.com/topic/282761-php-query-to-return-html-links/#findComment-1452835 Share on other sites More sharing options...
Solution Barand Posted October 6, 2013 Solution Share Posted October 6, 2013 When this has executed $row will contain "false", not the returned data while($row = mysql_fetch_array($result)){ } If you only search for one row, don't use while(). But then, having put the returned row into $row, it doesn't appear again in the code Quote Link to comment https://forums.phpfreaks.com/topic/282761-php-query-to-return-html-links/#findComment-1452845 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.