Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2012, 03:28 AM   PM User | #16
Prime8
New Coder

 
Join Date: Oct 2010
Posts: 51
Thanks: 2
Thanked 0 Times in 0 Posts
Prime8 is an unknown quantity at this point
It seems to work, although I don't have a table that matches the data yet. I'll try to throw one together.

Note: You did have 1 typo -
PHP Code:
while ($row mysql_fetch_array($result
PHP Code:
while ($row mysql_fetch_array($result)) 
I post that just for anyone reading this/potentially using your example, I'm not nitpicking your assistance. Thanks again.
Prime8 is offline   Reply With Quote
Old 12-15-2012, 03:42 AM   PM User | #17
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Use your own table and your own columns!

Since you didn't give us any real example to work with, I had to make one up.

I showed the basics: How to sort text and date and number columns. Just clone those sort functions and rename them/adapt them to match your data.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-01-2013, 09:42 AM   PM User | #18
rajdeep01
New Coder

 
Join Date: Dec 2012
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
rajdeep01 can only hope to improve
// Column name => column value
$filter = array(
'city' => $city,
'text' => $text,
'group' => $group,
);

$filter_sql = 'WHERE ';
foreach ($filter as $key=>$value)
$filter[$key] = "MATCH ($key) AGAINST ('$value') ";

$filter_sql .= implode($filter, ' AND ');

$query = "SELECT * FROM Posts
$filter_sql
ORDER by Date DESC LIMIT $limit_posts OFFSET $first_post";
rajdeep01 is offline   Reply With Quote
Old 01-02-2013, 02:51 AM   PM User | #19
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Rajdeep's naser *MIGHT* work, *IF* you have created a full text index for your table.

But it's way OVERKILL for the simple kind of query filtering needed here.

It's really a bad answer, overall.

Rajdeep: This answer is not a very good advertisement for your "Web Development Services". It would certainly make me suspect that you wouldn't do the best development job for me.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:52 PM.


Advertisement
Log in to turn off these ads.