RE: Is this query even possible?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Susan Ator [mailto:SAtor@npr.org]
> Sent: 10 June 2003 16:18
> 
> > This is what I am trying to do:
> > 
> > 	if ($FUNC==("USERPOST") || $FUNC==("MODU")) {
> > 		$sql = "UPDATE newdacs
> > 			SET emailfwd='$emailfwd',
> > 			mformat='$mformat',
> > 			filter_code='$filter_code'
> > 			if ($FUNC=='USERPOST') {
> > 				,unote='$unote'
> > 			}
> > 			WHERE user_id='$user_id'";
> > 		$set_newdacs_result = mysql_query($sql) or print
> > mysql_error();
> > 	}

Well, you're burying a PHP conditional inside what should be the SQL query,
which ain't gonna work very well.  Try separating it out -- two possible
ways are to (i) use the ?: conditional operator, like this:

	$sql = "UPDATE newdacs"
		. " SET emailfwd='$emailfwd'"
			. ",mformat='$mformat'"
			. ",filter_code='$filter_code'"
			. ($FUNC=='USERPOST' ? ",unote='$unote'" : '')
		. " WHERE user_id='$user_id'";

or (ii) a fully-blown if(), like this:

	$sql = "UPDATE newdacs"
		. " SET emailfwd='$emailfwd'"
			. ",mformat='$mformat'"
			. ",filter_code='$filter_code'";
	if ($FUNC=='USERPOST'):
		$sql .= ",unote='$unote'"
	endif;
	$sql .= " WHERE user_id='$user_id'";

There are probably umpteen other ways of approaching this -- use whatever
floats your boat! ;)


Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux