Dear Nasreen,
You could also do something like this:
$query = select * FROM gig g, venue v, genre ge ;
if($gig_name) {
$wheres[] = g.gigName LIKE '%.$gig_name.%';
}
if($gig_date) {
$wheres[] = g.gig_date LIKE '%.$sdate.%';
}
if(is_array($wheres)) {
$wheres = implode( OR , $wheres);
Michael,
Yes. Just go ahead, and echo $sql to see what you have. You can build quite
complex queries this way, dependent upon input from picklists, checkboxes,
etc., adding and dropping conditions according to whether or not they have
been selected/set.
So why not $sql = UPDATE $fieldlist
Is it possible to do a sort of dynamic sql. For instance, if I have a form with a
bunch of field/data variables and I send them to a php processor, can I just create a
loop to have it update all the fields without having to specify each field.
In scratch code, I guess I'm looking for something
Have you tried it? I've done this sort of thing before, and it works
just fine. By the time the query string is executed, the variables have
been interpreted.
So, if $colName = id, and $id = 12, then your query variable looks
something like select * from myTable where $colName = $id. By
Rich, thanks. I got the dynamic sql to work (i had a syntax problem), now my problem
is what's the most efficient way to loop it through all the form fields that are
passed to the processor? This is my current sql statement which handles 1 field:
$sql_update = UPDATE md_users SET .$formName. =
/Mysql DBA
Coretrek, Norway
+47 51978597 / +47 916 23566
-Original Message-
From: Matthew Loff [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 09, 2001 2:20 AM
To: 'Ben Bleything'; 'Mark Gordon'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Dynamic SQL + result resource error
Ha ha... I
___
-Original Message-
From: Mark Gordon [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 09, 2001 1:54 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Dynamic SQL + result resource error
Why is this code generating an error when it outputs a
valid SQL
Why is this code generating an error when it outputs a
valid SQL statement? (there are no parse errors)
//$find is text box input
$wordsarray = explode( ,$find);
$sql = SELECT bandname FROM bands WHERE (bandname
LIKE ;
$i = 0;
while ($i count($wordsarray))
{
$word =
);
$i++;
}
print $sqlhr;
$queryResult = mysql_query($sql);
while ($myrow=mysql_fetch_row($queryResult))
{
print $myrow[0],p;
}
-Original Message-
From: Mark Gordon [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 08, 2001 7:54 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Dynamic SQL
Sure he is. Right here:
$queryResult = mysql_query($sql);
what exact error is occurring?
-Original Message-
From: Matthew Loff [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 08, 2001 5:00 PM
To: 'Mark Gordon'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Dynamic SQL + result resource error
The code you're referencing is my modification of his original post. :)
-Original Message-
From: Ben Bleything [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 08, 2001 8:04 PM
To: 'Matthew Loff'; 'Mark Gordon'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Dynamic SQL + result resource error
: [PHP-DB] Dynamic SQL + result resource error
The code you're referencing is my modification of his original post. :)
-Original Message-
From: Ben Bleything [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 08, 2001 8:04 PM
To: 'Matthew Loff'; 'Mark Gordon'; [EMAIL PROTECTED]
Subject: RE
To: 'Matthew Loff'; 'Mark Gordon'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Dynamic SQL + result resource error
Guess I'm just a big dumbass then, aren't I =P
Oops.
I suppose that would cause it to fail then, wouldn't it?
= Ben
-Original Message-
From: Matthew Loff [mailto:[EMAIL
13 matches
Mail list logo