greens85 Posted April 10, 2008 Share Posted April 10, 2008 Hi All, I'm new to PHP so if this is a dumb question appologies. I have a table in mySQL that looks like the following: ID | SYM1 | SYM2 | SYM3 |TAGGED ----------------------------------- 1 | 7 | 2 | 4 | Yes/No ----------------------------------- 2 | 6 | 1 | 3 | Yes/No ----------------------------------- 3 | 9 | 1 | 1 | Yes/No ----------------------------------- 4 | 9 | 9 | 9 | Yes/No ----------------------------------- I need each number to represent an image, like the following: 1 = Apple 2 = Orange 3 = Pear 4 = Banana 6 = Cherry 7 = Strawberry 9 = Blackberry Is it possible to do this in PHP, so that if i say use id 1 then images of a strawberry, orange and banana will be displayed???? I thought of something like an IF statement along the following lines: IF number1 Choose = Strawberry.jpg Display Strawberry.jpg The tagged field is simply so that if an ID has been called it gets removed from the database to stop it being called again. Thanks for any help in advance. Quote Link to comment https://forums.phpfreaks.com/topic/100455-image-array/ Share on other sites More sharing options...
Daniel0 Posted April 10, 2008 Share Posted April 10, 2008 You could setup an associative array in your script: <?php $fruits = array( 1 => 'apple.jpg', 2 => 'orange.jpg', // etc. ); ?> Then to get the filename of the image just do $filename = $fruits[$num]; or something like that. Quote Link to comment https://forums.phpfreaks.com/topic/100455-image-array/#findComment-513717 Share on other sites More sharing options...
greens85 Posted April 10, 2008 Author Share Posted April 10, 2008 Again sorry if this is a silly question, But with this code, does this mean if i connected to my database then ran a query something along the lines of: $query = mysql_query ("SELECT * FROM symbolstable WHERE id=1"); That query in my eyes would return 7, 2 and 4 - so would this then reference the array and return: Strawberry.JPG Orange.JPG Banana.JPG Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/100455-image-array/#findComment-513730 Share on other sites More sharing options...
Daniel0 Posted April 10, 2008 Share Posted April 10, 2008 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/100455-image-array/#findComment-513736 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.