nade93 Posted December 8, 2009 Share Posted December 8, 2009 Hi All I am trying to create a star system, so basically is the mysql field =5, 5 star images are displayed. Is there a way there a way to do this please? Quote Link to comment https://forums.phpfreaks.com/topic/184449-want-to-display-images-dependant-on-number-in-mysql-field/ Share on other sites More sharing options...
premiso Posted December 8, 2009 Share Posted December 8, 2009 str_pad is what you are going to be after. Quote Link to comment https://forums.phpfreaks.com/topic/184449-want-to-display-images-dependant-on-number-in-mysql-field/#findComment-973682 Share on other sites More sharing options...
nade93 Posted December 8, 2009 Author Share Posted December 8, 2009 sorry, i have no idea what you mean, i want to use my own customised stars Quote Link to comment https://forums.phpfreaks.com/topic/184449-want-to-display-images-dependant-on-number-in-mysql-field/#findComment-973726 Share on other sites More sharing options...
premiso Posted December 8, 2009 Share Posted December 8, 2009 Sorry, I meant str_repeat. My mistake, here is an example of it's usage: $result = mysql_query("SELECT field FROM table WHERE condition = x") or trigger_error("Query Failed: " . mysql_error()); $output = ""; while ($row = mysql_fetch_assoc($result)) { $output .= str_repeat('<img src="star.gif" />', $row['field']); } echo $output; Quote Link to comment https://forums.phpfreaks.com/topic/184449-want-to-display-images-dependant-on-number-in-mysql-field/#findComment-973743 Share on other sites More sharing options...
nade93 Posted December 9, 2009 Author Share Posted December 9, 2009 thanks, however this is not working, its not displaying the image, Quote Link to comment https://forums.phpfreaks.com/topic/184449-want-to-display-images-dependant-on-number-in-mysql-field/#findComment-974038 Share on other sites More sharing options...
nade93 Posted December 9, 2009 Author Share Posted December 9, 2009 just had a thought, my field is set up as a varchar utf8 general is that why the field is not displaying? Quote Link to comment https://forums.phpfreaks.com/topic/184449-want-to-display-images-dependant-on-number-in-mysql-field/#findComment-974040 Share on other sites More sharing options...
premiso Posted December 9, 2009 Share Posted December 9, 2009 I have no clue why it is not displaying. First up, you have to have "star.gif" image on your server. Second, you have to re-do that query to match your database. I do not know what you store in "field" if it is a number, then the code I provided should work. If the only problem is the image is not displaying that is because you have to modify that to be where you have the actual image. If you would like us to help you more, please provide some code so we can see what you are doing. Without it we are left to our psychic abilities (which mind you are not very good). Quote Link to comment https://forums.phpfreaks.com/topic/184449-want-to-display-images-dependant-on-number-in-mysql-field/#findComment-974162 Share on other sites More sharing options...
nade93 Posted December 9, 2009 Author Share Posted December 9, 2009 all sorted, just needed to change directory (../images instead of /images) thanks guys your brill! x Quote Link to comment https://forums.phpfreaks.com/topic/184449-want-to-display-images-dependant-on-number-in-mysql-field/#findComment-974185 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.