Jump to content

Archived

This topic is now archived and is closed to further replies.

miz_luvly@hotmail.com

Select Columns using PHP/mysql

Recommended Posts

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:

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[!--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

Thanks
Sab

Share this post


Link to post
Share on other sites
Can I see your code that contain the query ?
And would you mind re-explain again ? I didn't get what you mean.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.