miz_luvly@hotmail.com Posted June 23, 2006 Share Posted June 23, 2006 HiI want to know how to select columns from mysql usng php. I know I can select columns in mysql using the following statement:[code]Select column1, column2 from table where company like '%abc%'[/code]how do i do the same using php, is it going to be:[code]select '".$_GET['column']."' from table where comapny like '%".$_GET['abc']."%'[/code]basically I have a survey table with 12 columns, I want users to only search and view columns they want e.g. user1 wants to view companies with higher market position, user2 wants to see brands, companies and display items, user3 wants to see companies with multi branches and their top selling brands.Is it possible and can someone point me to the right direction.Thanks in advanceSab Quote Link to comment https://forums.phpfreaks.com/topic/12722-select-columns-using-phpmysql/ Share on other sites More sharing options...
hackerkts Posted June 24, 2006 Share Posted June 24, 2006 This is how you do query in php,[code]$colunm = $_GET['column'];$abc = $_GET['abc'];$query = "select $column from table where comapny like '%$abc%'";$result = mysql_query($query) or die("Query failed: " . mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12722-select-columns-using-phpmysql/#findComment-48951 Share on other sites More sharing options...
miz_luvly@hotmail.com Posted June 26, 2006 Author Share Posted June 26, 2006 [!--quoteo(post=387330:date=Jun 23 2006, 07:40 PM:name=hackerkts)--][div class=\'quotetop\']QUOTE(hackerkts @ Jun 23 2006, 07:40 PM) [snapback]387330[/snapback][/div][div class=\'quotemain\'][!--quotec--]This is how you do query in php,[code]$colunm = $_GET['column'];$abc = $_GET['abc'];$query = "select $column from table where comapny like '%$abc%'";$result = mysql_query($query) or die("Query failed: " . mysql_error());[/code][/quote]Thanks for your help, how do i display selected columns close together. I am dispalying results in a table, when I select 1st and 9th column I get huge space in between how do i get rid of that.Should be displayed like this:Search Results column1 column9 cxc No gfg No rtrt No ThanksSab Quote Link to comment https://forums.phpfreaks.com/topic/12722-select-columns-using-phpmysql/#findComment-49688 Share on other sites More sharing options...
hackerkts Posted June 27, 2006 Share Posted June 27, 2006 Can I see your code that contain the query ?And would you mind re-explain again ? I didn't get what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/12722-select-columns-using-phpmysql/#findComment-49993 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.