guttyguppy Posted January 5, 2007 Share Posted January 5, 2007 I have a mysql database of a bunch of images. I want only one image to be assigned as the "featured" image. How can I build a form to do this? When an image is designated as "featured", any other image should be not featured. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/33010-how-to-have-a-unique-featured-image-from-a-mysql-database/ Share on other sites More sharing options...
paul2463 Posted January 5, 2007 Share Posted January 5, 2007 have another column in your table called `featured` with a bool value then you can set the featured image by setting the bool to true(1) and all other to false(0) then the form need only pull the image with its `featured` value = 1 Link to comment https://forums.phpfreaks.com/topic/33010-how-to-have-a-unique-featured-image-from-a-mysql-database/#findComment-153694 Share on other sites More sharing options...
guttyguppy Posted January 6, 2007 Author Share Posted January 6, 2007 Thank you Paul. What query/php commands should I run to set all other featured values to false? Link to comment https://forums.phpfreaks.com/topic/33010-how-to-have-a-unique-featured-image-from-a-mysql-database/#findComment-153958 Share on other sites More sharing options...
Asheeown Posted January 6, 2007 Share Posted January 6, 2007 Set them to "0" 1 = featured 0 = not Link to comment https://forums.phpfreaks.com/topic/33010-how-to-have-a-unique-featured-image-from-a-mysql-database/#findComment-153963 Share on other sites More sharing options...
paul2463 Posted January 6, 2007 Share Posted January 6, 2007 [code]<?phpfunction setFeatured($idvalue){$query = "UPDATE table SET featured = 0";mysql_query($query)or die ('Error in query: $query. ' . mysql_error()); //sets all featured values in the table to false$query1 = "UPDATE table SET featured = 1 WHERE idtable = '$idvalue'";mysql_query($query1)or die ('Error in query: $query1. ' . mysql_error()); //sets the new one featured to true}[/code]so when you want to change the featured image, just run the function with the correct table names etc, passing it the idvalue of the image you wish to be featured for that day such as[code]<?phpsetFeatured(12); //would set image id 12 featured to true?>[/code]then to get the image for your page[code]<?php$query = "SELECT image FROM table WHERE featured = 1";$result = mysql_query($query)or die ('Error in query: $query. ' . mysql_error());$row = mysql_fetch_assoc($result);$featured_image = $row['image']; //from then on just use the variable $featured_image?>[/code] Link to comment https://forums.phpfreaks.com/topic/33010-how-to-have-a-unique-featured-image-from-a-mysql-database/#findComment-154236 Share on other sites More sharing options...
guttyguppy Posted January 7, 2007 Author Share Posted January 7, 2007 Thank you so much Paul, I will put it to good use! Link to comment https://forums.phpfreaks.com/topic/33010-how-to-have-a-unique-featured-image-from-a-mysql-database/#findComment-154843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.