[PHP-DB] Is this query even possible?

2003-06-10 Thread Susan Ator
 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();
   }
 
 There are several more queries like this which is why I want to avoid
 duplicating the code since there are only 1 or 2 differences between them
 depending on function call.
 
 This is the error I am getting:
 
   You have an error in your SQL syntax near 'if (USERPOST=='USERPOST')
 { ,unote='' } WHERE user_id='2'' at line 5
 
 Is what I am attempting possible or am I spinning my wheels?
 
 susan

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



RE: [PHP-DB] Is this query even possible?

2003-06-10 Thread Matthew Moldvan
I would say something like the following would work better:

if($FUNC==USERPOST || $FUNC==MODU)
{
$sql .= UPDATE newdacs;
$sql .= SET emailfwd='$emailfwd',;
$sql .= mformat='$mformat',
$sql .= filter_code='$filter_code';
if($FUNC=='USERPOST')
$sql .= , unote='$unote';
$sql .= WHERE user_id='$user_id';

$result = mysql_query($sql) or die('mysql error #'.mysql_errno.':
'mysql_error());
}

Try that ... also look into www.php.net under string manipulation for other
options.

Regards,
Matthew Moldvan
 
System Administrator
Trilogy International, Inc.

-Original Message-
From: Susan Ator [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 10, 2003 11:18 AM
To: '[EMAIL PROTECTED]'
Subject: [PHP-DB] Is this query even possible?


 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();
   }
 
 There are several more queries like this which is why I want to avoid
 duplicating the code since there are only 1 or 2 differences between them
 depending on function call.
 
 This is the error I am getting:
 
   You have an error in your SQL syntax near 'if (USERPOST=='USERPOST')
 { ,unote='' } WHERE user_id='2'' at line 5
 
 Is what I am attempting possible or am I spinning my wheels?
 
 susan

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

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



RE: [PHP-DB] Is this query even possible?

2003-06-10 Thread Hutchins, Richard
Yup, Matthew's right. I definitely forgot the other $sql. = that needs to go
in front of the WHERE clause.

Question for Matthew though:

Is this:
   $sql .= UPDATE newdacs;
   $sql .= SET emailfwd='$emailfwd',;
   $sql .= mformat='$mformat',
   $sql .= filter_code='$filter_code';

Pretty much the same as this:
  $sql = UPDATE newdacs
  SET emailfwd='$emailfwd',
  mformat='$mformat',
  filter_code='$filter_code';

I mean, the line breaks in the second example won't cause the query to bomb,
will they? I agree that using the $sql .= is cleaner, but the other way
isn't wrong, is it?

Rich

 -Original Message-
 From: Matthew Moldvan [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, June 10, 2003 11:33 AM
 To: 'Susan Ator'; '[EMAIL PROTECTED]'
 Subject: RE: [PHP-DB] Is this query even possible?
 
 
 I would say something like the following would work better:
 
 if($FUNC==USERPOST || $FUNC==MODU)
 {
   $sql .= UPDATE newdacs;
   $sql .= SET emailfwd='$emailfwd',;
   $sql .= mformat='$mformat',
   $sql .= filter_code='$filter_code';
   if($FUNC=='USERPOST')
   $sql .= , unote='$unote';
   $sql .= WHERE user_id='$user_id';
 
   $result = mysql_query($sql) or die('mysql error 
 #'.mysql_errno.':
 'mysql_error());
 }
 
 Try that ... also look into www.php.net under string 
 manipulation for other
 options.
 
 Regards,
 Matthew Moldvan
  
 System Administrator
 Trilogy International, Inc.
 
 -Original Message-
 From: Susan Ator [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, June 10, 2003 11:18 AM
 To: '[EMAIL PROTECTED]'
 Subject: [PHP-DB] Is this query even possible?
 
 
  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();
  }
  
  There are several more queries like this which is why I 
 want to avoid
  duplicating the code since there are only 1 or 2 
 differences between them
  depending on function call.
  
  This is the error I am getting:
  
  You have an error in your SQL syntax near 'if 
 (USERPOST=='USERPOST')
  { ,unote='' } WHERE user_id='2'' at line 5
  
  Is what I am attempting possible or am I spinning my wheels?
  
  susan
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

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



RE: [PHP-DB] Is this query even possible?

2003-06-10 Thread Matthew Moldvan
Keep in mind the code I sent is untested ...  and I realized some errors
when I pasted it into a PHP page.  Corrections are below.

As for the line breaks, I've used SQL formatted that way before and it
hasn't cause me any problems.

Regards,
Matt.

Corrections: $sql .= mformat='$mformat', should have a trailing ;
 $result = mysql_query($sql) or die('mysql error
#'.mysql_errno.': 'mysql_error()); should have a . before mysql_error());

-Original Message-
From: Hutchins, Richard [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 10, 2003 11:42 AM
To: '[EMAIL PROTECTED]'
Subject: RE: [PHP-DB] Is this query even possible?


Yup, Matthew's right. I definitely forgot the other $sql. = that needs to go
in front of the WHERE clause.

Question for Matthew though:

Is this:
   $sql .= UPDATE newdacs;
   $sql .= SET emailfwd='$emailfwd',;
   $sql .= mformat='$mformat',
   $sql .= filter_code='$filter_code';

Pretty much the same as this:
  $sql = UPDATE newdacs
  SET emailfwd='$emailfwd',
  mformat='$mformat',
  filter_code='$filter_code';

I mean, the line breaks in the second example won't cause the query to bomb,
will they? I agree that using the $sql .= is cleaner, but the other way
isn't wrong, is it?

Rich

 -Original Message-
 From: Matthew Moldvan [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, June 10, 2003 11:33 AM
 To: 'Susan Ator'; '[EMAIL PROTECTED]'
 Subject: RE: [PHP-DB] Is this query even possible?
 
 
 I would say something like the following would work better:
 
 if($FUNC==USERPOST || $FUNC==MODU)
 {
   $sql .= UPDATE newdacs;
   $sql .= SET emailfwd='$emailfwd',;
   $sql .= mformat='$mformat',
   $sql .= filter_code='$filter_code';
   if($FUNC=='USERPOST')
   $sql .= , unote='$unote';
   $sql .= WHERE user_id='$user_id';
 
   $result = mysql_query($sql) or die('mysql error 
 #'.mysql_errno.':
 'mysql_error());
 }
 
 Try that ... also look into www.php.net under string 
 manipulation for other
 options.
 
 Regards,
 Matthew Moldvan
  
 System Administrator
 Trilogy International, Inc.
 
 -Original Message-
 From: Susan Ator [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, June 10, 2003 11:18 AM
 To: '[EMAIL PROTECTED]'
 Subject: [PHP-DB] Is this query even possible?
 
 
  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();
  }
  
  There are several more queries like this which is why I 
 want to avoid
  duplicating the code since there are only 1 or 2 
 differences between them
  depending on function call.
  
  This is the error I am getting:
  
  You have an error in your SQL syntax near 'if 
 (USERPOST=='USERPOST')
  { ,unote='' } WHERE user_id='2'' at line 5
  
  Is what I am attempting possible or am I spinning my wheels?
  
  susan
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

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

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



RE: [PHP-DB] Is this query even possible?

2003-06-10 Thread Ford, Mike [LSS]
 -Original Message-
 From: Susan Ator [mailto:[EMAIL PROTECTED]
 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: [EMAIL PROTECTED]
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



RE: [PHP-DB] Is this query even possible?

2003-06-10 Thread Susan Ator
See, this is why I cringe when I hear the management say 'No open source.
There's no support'.

You guys are great. It works a treat. (I ended up going with the conditional
operator)

Thanks!

susan

-Original Message-
From: Matthew Moldvan [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 10, 2003 11:50 AM
To: 'Hutchins, Richard'; '[EMAIL PROTECTED]'
Subject: RE: [PHP-DB] Is this query even possible?


Keep in mind the code I sent is untested ...  and I realized some errors
when I pasted it into a PHP page.  Corrections are below.

As for the line breaks, I've used SQL formatted that way before and it
hasn't cause me any problems.

Regards,
Matt.

Corrections: $sql .= mformat='$mformat', should have a trailing ;
 $result = mysql_query($sql) or die('mysql error
#'.mysql_errno.': 'mysql_error()); should have a . before mysql_error());

-Original Message-
From: Hutchins, Richard [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 10, 2003 11:42 AM
To: '[EMAIL PROTECTED]'
Subject: RE: [PHP-DB] Is this query even possible?


Yup, Matthew's right. I definitely forgot the other $sql. = that needs to go
in front of the WHERE clause.

Question for Matthew though:

Is this:
   $sql .= UPDATE newdacs;
   $sql .= SET emailfwd='$emailfwd',;
   $sql .= mformat='$mformat',
   $sql .= filter_code='$filter_code';

Pretty much the same as this:
  $sql = UPDATE newdacs
  SET emailfwd='$emailfwd',
  mformat='$mformat',
  filter_code='$filter_code';

I mean, the line breaks in the second example won't cause the query to bomb,
will they? I agree that using the $sql .= is cleaner, but the other way
isn't wrong, is it?

Rich

 -Original Message-
 From: Matthew Moldvan [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, June 10, 2003 11:33 AM
 To: 'Susan Ator'; '[EMAIL PROTECTED]'
 Subject: RE: [PHP-DB] Is this query even possible?
 
 
 I would say something like the following would work better:
 
 if($FUNC==USERPOST || $FUNC==MODU)
 {
   $sql .= UPDATE newdacs;
   $sql .= SET emailfwd='$emailfwd',;
   $sql .= mformat='$mformat',
   $sql .= filter_code='$filter_code';
   if($FUNC=='USERPOST')
   $sql .= , unote='$unote';
   $sql .= WHERE user_id='$user_id';
 
   $result = mysql_query($sql) or die('mysql error 
 #'.mysql_errno.':
 'mysql_error());
 }
 
 Try that ... also look into www.php.net under string 
 manipulation for other
 options.
 
 Regards,
 Matthew Moldvan
  
 System Administrator
 Trilogy International, Inc.
 
 -Original Message-
 From: Susan Ator [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, June 10, 2003 11:18 AM
 To: '[EMAIL PROTECTED]'
 Subject: [PHP-DB] Is this query even possible?
 
 
  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();
  }
  
  There are several more queries like this which is why I 
 want to avoid
  duplicating the code since there are only 1 or 2 
 differences between them
  depending on function call.
  
  This is the error I am getting:
  
  You have an error in your SQL syntax near 'if 
 (USERPOST=='USERPOST')
  { ,unote='' } WHERE user_id='2'' at line 5
  
  Is what I am attempting possible or am I spinning my wheels?
  
  susan
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

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

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

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



RE: [PHP-DB] Is this query even possible?

2003-06-10 Thread Ford, Mike [LSS]
 -Original Message-
 From: Matthew Moldvan [mailto:[EMAIL PROTECTED]
 Sent: 10 June 2003 16:50
 
 As for the line breaks, I've used SQL formatted that way before and it
 hasn't cause me any problems.

It's a matter of preference, but I prefer to keep my query strings as lean as possible 
-- bear in mind that this version:

 $sql = UPDATE newdacs
 SET emailfwd='$emailfwd',
 mformat='$mformat',
 filter_code='$filter_code';

will include not only the linebreaks but also all the leading whitespace on every line.

Personally, I like the technique of breaking my query up logically onto multiple 
lines, but I also prefer not to include unnecessary whitespace in the constructed 
query.  In addition, it seems to me that the repetitive inclusion of $sql .=  on 
every line is not only distracting but also slightly inefficient, as you perform a 
concatenation and assignment for every line -- by using the form I showed in my 
previous response, you can reduce this to just a concatenation per line, and a single 
assignment:

$sql = UPDATE newdacs
  . SET emailfwd='$emailfwd',
  . mformat='$mformat',
  . filter_code='$filter_code';

Of course, this is all completely IMHO, and I wouldn't say that any of the other ways 
of doing it is absolutely wrong.

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: [EMAIL PROTECTED]
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