/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Saving SQL select parameters in an array

I would like to be able to store some search paramaters in an array so that a user can search on certain fields in a database. The way I saw this happening in my mind was along the lines as follows

[code=php]
$selectParams[0] = “status=’open'”;
$selectParams[0] = “user=’$currentUser'”;

$sql = ‘SELECT * FROM hd_incident WHERE ‘;
$sql .= foreach($selectParams[] as $param){
echo $param;
}[/code]

The problem with this is, how would I get the AND statement into the equation? Also, the above is just an example. The real query would probably be longer with between 0 and 7 parameters (Maybe more).

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@nashruddinJun 23.2008 — [code=php]
<?php
$selectParams[0] = "status='open'";
$selectParams[1] = "user='$currentUser'";

$sql = "SELECT * FROM hd_incident WHERE " . implode(' AND ', $selectParams);

/*
$sql = SELECT * FROM hd_incident WHERE status='open' AND user='blah'
*/
?>
[/code]
Copy linkTweet thisAlerts:
@DoppleauthorJun 23.2008 — Thanks nashruddin. appreciate it.
×

Success!

Help @Dopple spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...