Steviep Posted July 26, 2010 Share Posted July 26, 2010 Hi all, Firstly apologies if this has been covered before I had a search through and could not find what I was after so I am hoping you can guide me. I'm doing a website which will contain a product catalogue. I decided to use PHP MySQL for this. At the moment I have in the database the categoryID, Title and the cat_thumb (for the thumbnail). What I want to do is to echo this out on a page for then each category to link to the relative products. My code at the moment is: <?php require 'database.php'; $q = "SELECT categoryID, title, cat_thumb FROM category"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if ($result) { echo "<ul id='photos'> \n"; while ($row = $result->fetch_object()) { $title = $row->title; $cat_thumb = $row->cat_thumb; $categoryID = $row->categoryID; echo "<li><a href='../images/products/categorythumbs/$cat_thumb'><img src='../images/products/categorythumbs/$cat_thumb' id='$CategoryID' alt='$title' /></a> \n"; echo "<h4>$title</h4></li> \n"; } echo "</ul>"; } ?> The code above works really well however the issue is that it echos everything out in one go, I would like to do it seperately. Can you guide me on how to do this and how to set up links for each product? I can imagine this being a pretty simple thing to do for that I apologise in advance however I am stumped at this point. If you need anymore info please let me know and I will provide as much as possible. Thanks in advance for any info. Kind regards Stevie Link to comment https://forums.phpfreaks.com/topic/208940-image-echo-from-mysql-database/ Share on other sites More sharing options...
tomtimms Posted July 26, 2010 Share Posted July 26, 2010 Not sure I see a problem in your code, what exactly do you mean one go? Link to comment https://forums.phpfreaks.com/topic/208940-image-echo-from-mysql-database/#findComment-1091404 Share on other sites More sharing options...
Steviep Posted July 26, 2010 Author Share Posted July 26, 2010 The issue is that from this part: echo "<li><a href='../images/products/categorythumbs/$cat_thumb'><img src='../images/products/categorythumbs/$cat_thumb' id='$CategoryID' alt='$title' /></a> \n"; echo "<h4>$title</h4></li> \n"; It will echo out on the page as the following: <div id="productcat"><p><ul id='photos'> <li><a href='../images/products/categorythumbs/animalhome.gif'><img src='../images/products/categorythumbs/animalhome.gif' id='' alt='Animal and Home' /></a> <h4>Animal and Home</h4></li> <li><a href='../images/products/categorythumbs/bee.gif'><img src='../images/products/categorythumbs/bee.gif' id='' alt='Bee Products' /></a> <h4>Bee Products</h4></li> <li><a href='../images/products/categorythumbs/drinks.gif'><img src='../images/products/categorythumbs/drinks.gif' id='' alt='Aloe Drinks' /></a> <h4>Aloe Drinks</h4></li> <li><a href='../images/products/categorythumbs/personal.gif'><img src='../images/products/categorythumbs/personal.gif' id='' alt='Personal Care' /></a> <h4>Personal Care</h4></li> <li><a href='../images/products/categorythumbs/skin.gif'><img src='../images/products/categorythumbs/skin.gif' id='' alt='Skin Care' /></a> <h4>Skin Care</h4></li> <li><a href='../images/products/categorythumbs/makeup.gif'><img src='../images/products/categorythumbs/makeup.gif' id='' alt='Make-Up' /></a> <h4>Make-Up</h4></li> <li><a href='../images/products/categorythumbs/packs.gif'><img src='../images/products/categorythumbs/packs.gif' id='' alt='Packs' /></a> <h4>Packs</h4></li> <li><a href='../images/products/categorythumbs/supplements.gif'><img src='../images/products/categorythumbs/supplements.gif' id='' alt='Supplements' /></a> <h4>Supplements</h4></li> <li><a href='../images/products/categorythumbs/specialist.gif'><img src='../images/products/categorythumbs/specialist.gif' id='' alt='Specialist Skin Care' /></a> <h4>Specialist Skin Care</h4></li> </ul></p></div> If the echo line was change to for example: echo "<li><a href='../images/products/categorythumbs/productname.jpg'><img src='../images/products/categorythumbs/productname.jpg' id='$CategoryID' alt='$title' /></a> \n"; echo "<h4>$title</h4></li> \n"; } it shows all as the same picture and/or link. My aim is to seperate these to echo each image and to also have individual links to each of the products which will also be held within the database. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/208940-image-echo-from-mysql-database/#findComment-1091406 Share on other sites More sharing options...
Steviep Posted July 27, 2010 Author Share Posted July 27, 2010 Finally got this solved. echo "<li><a href='../images/products/categorythumbs/$cat_thumb'><img src='../images/products/categorythumbs/$cat_thumb' id='$CategoryID' alt='$title' /></a> \n"; echo "<h4>$title</h4></li> \n"; is now changed to echo "<li><a href='../images/products/categorythumbs/product.php?cat=$categoryID'><img src='../images/products/categorythumbs/$cat_thumb' id='$CategoryID' alt='$title' /></a> \n"; echo "<h4>$title</h4></li> \n"; Now I can get on!! Cheers Stevie Link to comment https://forums.phpfreaks.com/topic/208940-image-echo-from-mysql-database/#findComment-1091609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.