Jump to content


Photo

Select Columns using PHP/mysql


  • Please log in to reply
3 replies to this topic

#1 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 23 June 2006 - 12:18 PM

Hi

I want to know how to select columns from mysql usng php. I know I can select columns in mysql using the following statement:

Select column1, column2 from table where company like '%abc%'

how do i do the same using php, is it going to be:

select '".$_GET['column']."' from table where comapny like '%".$_GET['abc']."%'

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 advance
Sab

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 24 June 2006 - 12:40 AM

This is how you do query in php,
$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());


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 26 June 2006 - 03:17 PM

[!--quoteo(post=387330:date=Jun 23 2006, 07:40 PM:name=hackerkts)--][div class=\'quotetop\']QUOTE(hackerkts @ Jun 23 2006, 07:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
This is how you do query in php,
$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());
[/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

Thanks
Sab

#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 27 June 2006 - 08:45 AM

Can I see your code that contain the query ?
And would you mind re-explain again ? I didn't get what you mean.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users