zhangy Posted August 1, 2009 Share Posted August 1, 2009 Hi, Im trying to display msql database info based on the content of a identifier row. find the value of the row and display the content based on that value. so for example: if the row colors = green then display all content from all rows where color = green. but if the row color = red then display all content from all rows where color = red or if the row color = blue ... Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/ Share on other sites More sharing options...
GingerRobot Posted August 1, 2009 Share Posted August 1, 2009 I don't think i understand. I assume you didn't mean something like the following: $color = 'green'; $sql = "SELECT * FROM yourtable WHERE color='$color'"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); //display the results Or did you mean that the colour in question is selected from the colour of another row given by some criteria? Something like a "show similar articles (or colours)"? In which case, you can either perform one query to extract the colour or do it in one: SELECT * FROM yourtable WHERE colour=(SELECT colour FROM `incoming` WHERE ...) Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888273 Share on other sites More sharing options...
zhangy Posted August 1, 2009 Author Share Posted August 1, 2009 ok but the color can be any one of the three colors (red, green or blue) based upon info passed in the url. Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888279 Share on other sites More sharing options...
GingerRobot Posted August 1, 2009 Share Posted August 1, 2009 I'm still not sure i follow exactly, but did you want something like this then? $colors = array($_GET['color1'],$_GET['color2'],$_GET['color3']); $colors = implode("','",$colors); $sql = "SELECT * FROM yourtable WHERE colors IN '$colors'"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); //display the results Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888284 Share on other sites More sharing options...
zhangy Posted August 1, 2009 Author Share Posted August 1, 2009 Ok so there is the id passed in the url which lets say is equal to 1. if this row thats id is equal to 1 has red as the value in the (sorry) COLUMN "colors" let all rows with the value "red" in the COLUMN "colors" be dispayed if blue is the value then let all blue be displayed. or if its green then let green be displayed. I hope this makes better sense. $id = (int) $_GET['id']; $sql = "SELECT * FROM $table WHERE id=$id"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888295 Share on other sites More sharing options...
GingerRobot Posted August 1, 2009 Share Posted August 1, 2009 Well that's roughly what i posted here: SELECT * FROM yourtable WHERE colour=(SELECT colour FROM `incoming` WHERE ...) Fitting it in with what you have: $id = (int) $_GET['id']; $sql = "SELECT * FROM yourtable WHERE colors=(SELECT colors FROM `incoming` WHERE id=$id)"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888310 Share on other sites More sharing options...
zhangy Posted August 2, 2009 Author Share Posted August 2, 2009 ok sorry, what does 'incoming' mean here? is that a place holder for the table thats passed in the url? cause in this case they are the same table. so by your example 'incoming' should be "yourtable"? Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888885 Share on other sites More sharing options...
GingerRobot Posted August 2, 2009 Share Posted August 2, 2009 ok sorry, what does 'incoming' mean here? is that a place holder for the table thats passed in the url? cause in this case they are the same table. so by your example 'incoming' should be "yourtable"? Apologies, yes. I'm not really sure where incoming came from. I guess i must have been doing two things at once Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888897 Share on other sites More sharing options...
zhangy Posted August 2, 2009 Author Share Posted August 2, 2009 Ok great it works. Thanks GingerRobot! One last question for this please! Now I am displaying posts that are the color "red". The list includes the post with the id that is passed in the url. is there a way to pass all the red posts except for the one that has the same id as that which was passed in the url? Thanks again for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888898 Share on other sites More sharing options...
GingerRobot Posted August 2, 2009 Share Posted August 2, 2009 Sure, just add another condition to your WHERE clause: SELECT * FROM yourtable WHERE colors=(SELECT colors FROM yourtable WHERE id=$id) AND id != $id Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-888987 Share on other sites More sharing options...
zhangy Posted August 3, 2009 Author Share Posted August 3, 2009 Oh that simple! Thank you GingerRobot! Quote Link to comment https://forums.phpfreaks.com/topic/168396-solved-displaying-data-based-on-identifier-in-row/#findComment-889201 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.