dev1902 Posted August 8, 2013 Share Posted August 8, 2013 (edited) Hello, Can someone help me to come up with a condition for an input to filter out a large table to a smaller table with a code. > My files are already uploaded to my db(database) and I already I already created a code to display the information in a table. > To clarify what i need help with, I populated a text field with information from my db and then when i submit it, it will filter the large table and only include any information that has to do with the information that i submitted. >> To further clarify, here is an example : There is a db with usernames, and I populated a text field with all the user ids. >> When i select the user id and click 'submit', all the information on that specific user id is pulled up and displayed on another page. --> but there is also an option to display two user ids at the same time. I know how to do it individually like this: <?php $query = mysql_query("SELECT * FROM `gfr` WHERE numInter > 0 AND geneSymbolTranscript1 = 'ERG'"); ?> but, i want to be able to do it for two columns and all their rows. Thanks in advance. Edited August 8, 2013 by dev1902 Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 8, 2013 Share Posted August 8, 2013 Well as for your example to get all rows where username equals two or more usernames, here is an example: SELECT * FROM table_name WHERE username IN ('bob', 'sally') Quote Link to comment Share on other sites More sharing options...
dev1902 Posted August 8, 2013 Author Share Posted August 8, 2013 I know. I was saying, what if i populated a text field with those names on one page, and the i submit that specific name(s) and it displays all the related infromation with that name(s) on another page. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted August 8, 2013 Share Posted August 8, 2013 AbraCadaver is correct, you want to create the query to select MORE than 1 row. When you have selected the rows, then use a while loop to iterate over the returned rows and display them how you wish. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 8, 2013 Share Posted August 8, 2013 I know. I was saying, what if i populated a text field with those names on one page, and the i submit that specific name(s) and it displays all the related infromation with that name(s) on another page. You probably don't want a text box, maybe a multiple select box. If you must use a text box, then you would have to delimit the names with a space or comma or something. Then you would just explode on that delimiter and implode back into a string lik 'bob','sally' and use that in the IN clause of the SELECT. Quote Link to comment Share on other sites More sharing options...
dev1902 Posted August 9, 2013 Author Share Posted August 9, 2013 is there a way to do it using an IF statement? Quote Link to comment Share on other sites More sharing options...
Solution dev1902 Posted August 13, 2013 Author Solution Share Posted August 13, 2013 (edited) Thanks again. I figured it out. Edited August 13, 2013 by dev1902 Quote Link to comment 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.