[PHP] syntax question

2013-07-10 Thread Jim Giner
Can someone tell me what this syntax is?  I looked around but don't see 
any mention of it.


while(condition) : (statement);




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



Re: [PHP] syntax question

2013-07-10 Thread Přemysl Fiala

Hello,

is an alternative syntax.

http://php.net/manual/en/control-structures.alternative-syntax.php

Premek.


On Wed, 10 Jul 2013 13:15:22 +0200, Jim Giner  
jim.gi...@albanyhandball.com wrote:


Can someone tell me what this syntax is?  I looked around but don't see  
any mention of it.


while(condition) : (statement);






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



Re: [PHP] syntax question

2013-07-10 Thread Jim Giner

Thanks!

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



[PHP] syntax question

2012-02-07 Thread admin
I have been struggling with this issue for an hour and honestly I am not
sure why.

I consider myself to be pretty savvy with MySQL but I am running into an
syntax error that is just flat out eluding me.

 

$query = SELECT `table2`.`name` from `table1` ,`table2` WHERE
`table2`.`user_id`=`table1`.`seller_id` AND IF(`table2`.`name`='juice','No
Juice for YOU', `table2`.`name`=`table2`.`name`) LIMIT 1;

This query works!!

 

But If I try to add a GROUP BY to the query, complete failure.

$query = SELECT `table2`.`name`  FROM `table1` ,`table2` WHERE
`table2`.`user_id`=`table1`.`seller_id` AND IF(`table2`.`name`='juice','No
Juice for YOU', `table2`.`name`=`table2`.`name`) GROUP BY `table1`.`ID`
LIMIT 1;

 

The main goal here is to get only 1 return but MySQL is returning the same
row 2 times.

Before I beat my head in anymore I will toss this out to you guys and beat
myself up later for not drinking enough coffee or something .

 

 

 

 



Re: [PHP] syntax question

2012-02-07 Thread Louis Huppenbauer
Generally... Wouldn't grouping by an id (which is normally unique) have no
real benefit... Except some strange behaviour?

Just to clarify: Why aren't you sticking to the LIMIT 1?

2012/2/7 ad...@buskirkgraphics.com

 I have been struggling with this issue for an hour and honestly I am not
 sure why.

 I consider myself to be pretty savvy with MySQL but I am running into an
 syntax error that is just flat out eluding me.



 $query = SELECT `table2`.`name` from `table1` ,`table2` WHERE
 `table2`.`user_id`=`table1`.`seller_id` AND IF(`table2`.`name`='juice','No
 Juice for YOU', `table2`.`name`=`table2`.`name`) LIMIT 1;

 This query works!!



 But If I try to add a GROUP BY to the query, complete failure.

 $query = SELECT `table2`.`name`  FROM `table1` ,`table2` WHERE
 `table2`.`user_id`=`table1`.`seller_id` AND IF(`table2`.`name`='juice','No
 Juice for YOU', `table2`.`name`=`table2`.`name`) GROUP BY `table1`.`ID`
 LIMIT 1;



 The main goal here is to get only 1 return but MySQL is returning the same
 row 2 times.

 Before I beat my head in anymore I will toss this out to you guys and beat
 myself up later for not drinking enough coffee or something .












RE: [PHP] syntax question

2012-02-07 Thread admin

 -Original Message-
 From: Louis Huppenbauer [mailto:louis.huppenba...@gmail.com]
 Sent: Tuesday, February 07, 2012 9:24 AM
 To: ad...@buskirkgraphics.com
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] syntax question
 
 Generally... Wouldn't grouping by an id (which is normally unique) have
 no
 real benefit... Except some strange behaviour?
 
 Just to clarify: Why aren't you sticking to the LIMIT 1?
 
 2012/2/7 ad...@buskirkgraphics.com
 
  I have been struggling with this issue for an hour and honestly I am
 not
  sure why.
 
  I consider myself to be pretty savvy with MySQL but I am running into
 an
  syntax error that is just flat out eluding me.
 
 
 
  $query = SELECT `table2`.`name` from `table1` ,`table2` WHERE
  `table2`.`user_id`=`table1`.`seller_id` AND
 IF(`table2`.`name`='juice','No
  Juice for YOU', `table2`.`name`=`table2`.`name`) LIMIT 1;
 
  This query works!!
 
 
 
  But If I try to add a GROUP BY to the query, complete failure.
 
  $query = SELECT `table2`.`name`  FROM `table1` ,`table2` WHERE
  `table2`.`user_id`=`table1`.`seller_id` AND
 IF(`table2`.`name`='juice','No
  Juice for YOU', `table2`.`name`=`table2`.`name`) GROUP BY
 `table1`.`ID`
  LIMIT 1;
 
 
 
  The main goal here is to get only 1 return but MySQL is returning the
 same
  row 2 times.
 
  Before I beat my head in anymore I will toss this out to you guys and
 beat
  myself up later for not drinking enough coffee or something .
 
 



There is no real reason to have a LIMIT It was just yet another attempt to 
limit the results during the testing.
After reading my post back I see an error in the IF statement but not the 
resolution to the issue.

The IF should read
IF(`table2`.`name`='juice',`table2`.`name`=`table1`.`code`, 
`table2`.`name`=`table1`.`ref`)




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



Re: [PHP] syntax question

2012-02-07 Thread ma...@behnke.biz


ad...@buskirkgraphics.com hat am 7. Februar 2012 um 15:11 geschrieben:

 I have been struggling with this issue for an hour and honestly I am not
 sure why.

 I consider myself to be pretty savvy with MySQL but I am running into an
 syntax error that is just flat out eluding me.

 

 $query = SELECT `table2`.`name` from `table1` ,`table2` WHERE
 `table2`.`user_id`=`table1`.`seller_id` AND
IF(`table2`.`name`='juice','No
 Juice for YOU', `table2`.`name`=`table2`.`name`) LIMIT 1;

 This query works!!

 

 But If I try to add a GROUP BY to the query, complete failure.

 $query = SELECT `table2`.`name`  FROM `table1` ,`table2` WHERE
 `table2`.`user_id`=`table1`.`seller_id` AND
IF(`table2`.`name`='juice','No
 Juice for YOU', `table2`.`name`=`table2`.`name`) GROUP BY `table1`.`ID`
 LIMIT 1;


This is a nice query but I am not sure if I understand what you want to do?
Maybe we could start with your error message and a table structure :-) That
would be handy.

You wanna get all users that have at least on sell? But only once?

Maybe something like that?

SELECT table2.name
FROM
  table2,
  (SELECT seller_id FROM table1 GROUP BY seller_id) as table1
WHERE
  table2.user_id = table1.seller_id
  AND IF(table2.name = 'juice','No Juice for YOU', table2.name =
table2.name)
;




Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

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



RE: [PHP] syntax question

2012-02-07 Thread admin

 -Original Message-
 From: ma...@behnke.biz [mailto:ma...@behnke.biz]
 Sent: Tuesday, February 07, 2012 10:47 AM
 To: php-general@lists.php.net; ad...@buskirkgraphics.com
 Subject: Re: [PHP] syntax question
 
 
 
 ad...@buskirkgraphics.com hat am 7. Februar 2012 um 15:11 geschrieben:
 
  I have been struggling with this issue for an hour and honestly I am
 not
  sure why.
 
  I consider myself to be pretty savvy with MySQL but I am running into
 an
  syntax error that is just flat out eluding me.
 
 
 
  $query = SELECT `table2`.`name` from `table1` ,`table2` WHERE
  `table2`.`user_id`=`table1`.`seller_id` AND
 IF(`table2`.`name`='juice','No
  Juice for YOU', `table2`.`name`=`table2`.`name`) LIMIT 1;
 
  This query works!!
 
 
 
  But If I try to add a GROUP BY to the query, complete failure.
 
  $query = SELECT `table2`.`name`  FROM `table1` ,`table2` WHERE
  `table2`.`user_id`=`table1`.`seller_id` AND
 IF(`table2`.`name`='juice','No
  Juice for YOU', `table2`.`name`=`table2`.`name`) GROUP BY
 `table1`.`ID`
  LIMIT 1;
 
 
 This is a nice query but I am not sure if I understand what you want to
 do?
 Maybe we could start with your error message and a table structure :-)
 That
 would be handy.
 
 You wanna get all users that have at least on sell? But only once?
 
 Maybe something like that?
 
 SELECT table2.name
 FROM
   table2,
   (SELECT seller_id FROM table1 GROUP BY seller_id) as table1
 WHERE
   table2.user_id = table1.seller_id
   AND IF(table2.name = 'juice','No Juice for YOU', table2.name =
 table2.name)
 ;
 
 
 
 
 Marco Behnke
 Dipl. Informatiker (FH), SAE Audio Engineer Diploma
 Zend Certified Engineer PHP 5.3
 
 Tel.: 0174 / 9722336
 e-Mail: ma...@behnke.biz
 
 Softwaretechnik Behnke
 Heinrich-Heine-Str. 7D
 21218 Seevetal
 
 http://www.behnke.biz



Marco,
Thank you but the whole issue stemed from the 2nd table in the FROM.
I just did an inner join using the If statement and it resolved the whole issue.
Maybe it was just a coffee thing because 2 cups later I seen it very clearly :)

Thanks so much.
 



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



[PHP] Syntax Question

2011-08-03 Thread Gates, Jeff
I, too, am a super newbie. I have a beginning knowledge of being able to
read php and understand its syntax but I can¹t write it. This is a bit
complicated but here¹s my problem:

I want to create a variable in PHP that I can use to link to an image in our
museum's image website. We have done it with ColdFusion here but I need the
same thing for PHP because I¹m building a site using a php-based CMS called
Omeka.

In ColdFusion the variable is written:
cfset tmpImageDirectory = getToken(artwork.accessionNumber, 1, .)

Basically, it¹s saying find the image on our server by looking for its
accession number within the year directory. Since the first part of the
accession number is the year we got the artwork this variable is saying look
for the accession number in the year directory by first looking at the first
part of that accession number (the year), look in that year directory and
then use the entire accession number to find the image within that
directory.  An example of an accession number is 2011.15. That¹s saying that
artwork was the 15th artwork brought into our collection in 2011. On our
image server it will be found in a directory called 2011. (Am I making
sense?)

Then the Coldfusion call is:

a 
href=http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart
.si.edu/images/#tmpImageDirectory#/#artwork.accessionNumber#_1a.jpg (the
1a.jpg is simply the size image we want to call).

I need to be able to do the same thing with PHP but have no idea how.

More information: within my site I¹m housing the accession number in a mySQL
database. I¹ve gotten a bit of help on this already (but not enough, that¹s
why I¹m turning to you).

I was told I need to create two variables [('Dublin Core','Identifier') is
the name of the field that houses the accession number):

$accessionNumber =  item('Dublin Core','Identifier');
$tmpImageDirectory = strtok($accessionNumber,.);

And then create a third variable to create a url variable

$url = 
http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.si.e
du/images/ 
http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.si.e
du/images/$tmpImageDirectory/$artwork.accessionNumber_1a.jpg  +
$tmpImageDirectory + / + $accessionNumber + _1ajpg;

That's as far as I've gotten. I don't know how to put all of these together
using proper PHP syntax. Can someone help me with this? Thanks.

Best, Jeff



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



RE: [PHP] Syntax Question

2011-08-03 Thread admin
 -Original Message-
 From: Gates, Jeff [mailto:gat...@si.edu]
 Sent: Wednesday, August 03, 2011 10:23 AM
 To: php-general@lists.php.net
 Subject: [PHP] Syntax Question
 
 I, too, am a super newbie. I have a beginning knowledge of being able
 to
 read php and understand its syntax but I can¹t write it. This is a
 bit
 complicated but here¹s my problem:
 
 I want to create a variable in PHP that I can use to link to an image
 in our
 museum's image website. We have done it with ColdFusion here but I need
 the
 same thing for PHP because I¹m building a site using a php-based CMS
 called
 Omeka.
 
 In ColdFusion the variable is written:
 cfset tmpImageDirectory = getToken(artwork.accessionNumber, 1, .)
 
 Basically, it¹s saying find the image on our server by looking for its
 accession number within the year directory. Since the first part of the
 accession number is the year we got the artwork this variable is saying
 look
 for the accession number in the year directory by first looking at the
 first
 part of that accession number (the year), look in that year directory
 and
 then use the entire accession number to find the image within that
 directory.  An example of an accession number is 2011.15. That¹s saying
 that
 artwork was the 15th artwork brought into our collection in 2011. On
 our
 image server it will be found in a directory called 2011. (Am I making
 sense?)
 
 Then the Coldfusion call is:
 
 a
 href=http://ids.si.edu/ids/dynamic?container.fullpageid=http://americ
 anart
 .si.edu/images/#tmpImageDirectory#/#artwork.accessionNumber#_1a.jpg
 (the
 1a.jpg is simply the size image we want to call).
 
 I need to be able to do the same thing with PHP but have no idea how.
 
 More information: within my site I¹m housing the accession number in a
 mySQL
 database. I¹ve gotten a bit of help on this already (but not enough,
 that¹s
 why I¹m turning to you).
 
 I was told I need to create two variables [('Dublin Core','Identifier')
 is
 the name of the field that houses the accession number):
 
 $accessionNumber =  item('Dublin Core','Identifier');
 $tmpImageDirectory = strtok($accessionNumber,.);
 
 And then create a third variable to create a url variable
 
 $url =
 http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart
 .si.e
 du/images/
 http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart
 .si.e
 du/images/$tmpImageDirectory/$artwork.accessionNumber_1a.jpg  +
 $tmpImageDirectory + / + $accessionNumber + _1ajpg;
 
 That's as far as I've gotten. I don't know how to put all of these
 together
 using proper PHP syntax. Can someone help me with this? Thanks.
 
 Best, Jeff
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




$url =
http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.si.e
du/images/
http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.si.e
du/images/. $tmpImageDirectory ./. $artwork .accessionNumber_1a.jpg .
$tmpImageDirectory ./. $accessionNumber ._1ajpg;

I am not sure I agree with the way you are setting the $url it looks like
you have mashed and a url hyperlink partially into 1.
Like you are trying to set the $url as a image with a link are you trying to
set a link or an image as the $url?

If you are trying to set a image as the $url do this.

$url = image
src=http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.s
i.edu/images/. $tmpImageDirectory ./. $accessionNumber ._1ajpg ALT='';

Sorry if this is not correct for what you are trying to do. I just do not
understand the intent.















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



Re: [PHP] Syntax Question

2011-08-03 Thread Gates, Jeff
On 8/3/11 10:41 AM, ad...@buskirkgraphics.com ad...@buskirkgraphics.com
wrote:

 -Original Message-
 From: Gates, Jeff [mailto:gat...@si.edu]
 Sent: Wednesday, August 03, 2011 10:23 AM
 To: php-general@lists.php.net
 Subject: [PHP] Syntax Question
 
 I, too, am a super newbie. I have a beginning knowledge of being able
 to
 read php and understand its syntax but I can¹t write it. This is a
 bit
 complicated but here¹s my problem:
 
 I want to create a variable in PHP that I can use to link to an image
 in our
 museum's image website. We have done it with ColdFusion here but I need
 the
 same thing for PHP because I¹m building a site using a php-based CMS
 called
 Omeka.
 
 In ColdFusion the variable is written:
 cfset tmpImageDirectory = getToken(artwork.accessionNumber, 1, .)
 
 Basically, it¹s saying find the image on our server by looking for its
 accession number within the year directory. Since the first part of the
 accession number is the year we got the artwork this variable is saying
 look
 for the accession number in the year directory by first looking at the
 first
 part of that accession number (the year), look in that year directory
 and
 then use the entire accession number to find the image within that
 directory.  An example of an accession number is 2011.15. That¹s saying
 that
 artwork was the 15th artwork brought into our collection in 2011. On
 our
 image server it will be found in a directory called 2011. (Am I making
 sense?)
 
 Then the Coldfusion call is:
 
 a
 href=http://ids.si.edu/ids/dynamic?container.fullpageid=http://americ
 anart
 .si.edu/images/#tmpImageDirectory#/#artwork.accessionNumber#_1a.jpg
 (the
 1a.jpg is simply the size image we want to call).
 
 I need to be able to do the same thing with PHP but have no idea how.
 
 More information: within my site I¹m housing the accession number in a
 mySQL
 database. I¹ve gotten a bit of help on this already (but not enough,
 that¹s
 why I¹m turning to you).
 
 I was told I need to create two variables [('Dublin Core','Identifier')
 is
 the name of the field that houses the accession number):
 
 $accessionNumber =  item('Dublin Core','Identifier');
 $tmpImageDirectory = strtok($accessionNumber,.);
 
 And then create a third variable to create a url variable
 
 $url =
 http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart
 .si.e
 du/images/
 http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart
 .si.e
 du/images/$tmpImageDirectory/$artwork.accessionNumber_1a.jpg  +
 $tmpImageDirectory + / + $accessionNumber + _1ajpg;
 
 That's as far as I've gotten. I don't know how to put all of these
 together
 using proper PHP syntax. Can someone help me with this? Thanks.
 
 Best, Jeff
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 $url =
 http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.si.e
 du/images/
 http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.si.e
 du/images/. $tmpImageDirectory ./. $artwork .accessionNumber_1a.jpg .
 $tmpImageDirectory ./. $accessionNumber ._1ajpg;
 
 I am not sure I agree with the way you are setting the $url it looks like
 you have mashed and a url hyperlink partially into 1.
 Like you are trying to set the $url as a image with a link are you trying to
 set a link or an image as the $url?
 
 If you are trying to set a image as the $url do this.
 
 $url = image
 src=http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.s
 i.edu/images/. $tmpImageDirectory ./. $accessionNumber ._1ajpg ALT='';
 
 Sorry if this is not correct for what you are trying to do. I just do not
 understand the intent.
 

To be honest with you, I'm not sure what that $url is supposed to do. This
is the info (albeit without any explanation) someone told me to use. But he
didn't tell me how to use it.

Basically, I need to be able to link to an image on our web server
dynamically. The structure of the web server is as I described: each image
has an accession number and each image is housed in a directory on that
server that is named the year that artwork was accessioned. We can retrieve
the accession number that is stored in the data field ('Dublin
Core','Identifier')

An example of an actual (non-dynamic) link to the image server might look
like this: 
http://ids.si.edu/ids/dynamic?container.fullpageid=http://americanart.si.ed
u/images/2011/2011.15_1a.jpg

I just need to be able to build that link dynamically for each artwork on
the site. (Personally, I'm not wedded to the code I posted earlier if
someone can find a better way of doing it. This is just what I was told to
use. Again, I'm a newbie.)


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



[PHP] syntax question

2007-03-26 Thread Ross
Can I put post values directly into insert statements?

$query = INSERT INTO categories (category_name) VALUES 
('$_POST['cat_name']); 

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



Re: [PHP] syntax question

2007-03-26 Thread cajbecu
Ross wrote:
 Can I put post values directly into insert statements?
 
 $query = INSERT INTO categories (category_name) VALUES 
 ('$_POST['cat_name']); 
 

Yes you can, but it is not secure to do that!

use (insecure):

$query = INSERT INTO categories (category_name) VALUES
('{$_POST['cat_name']}');

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



Re: [PHP] syntax question

2007-03-26 Thread Brad Bonkoski

Ross wrote:

Can I put post values directly into insert statements?

$query = INSERT INTO categories (category_name) VALUES 
('$_POST['cat_name']); 

  

Yes, although this is not recommended.
What is someone puts a single quote in there?  Or some other bad 
characters


otherwise... 2 options:

$query = INSERT INTO categories (category_name) VALUES 
('.$_POST['cat_name'].');

-or-
$query = INSERT INTO categories (category_name) VALUES 
('{$_POST['cat_name']}');


-Brad 



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



Re: [PHP] syntax question

2007-03-26 Thread tedd

At 3:59 PM +0100 3/26/07, Ross wrote:

Can I put post values directly into insert statements?

$query = INSERT INTO categories (category_name) VALUES
('$_POST['cat_name']);



Open to sql injection.

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] syntax question

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 9:59 am, Ross wrote:
 Can I put post values directly into insert statements?

 $query = INSERT INTO categories (category_name) VALUES
 ('$_POST['cat_name']);

Sure!

If you want your webserver to get hacked by the Bad Guys, just go
right ahead and do that.

[that was tounge-in-cheek]

Start reading here:
http://phpsec.org

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] syntax question

2007-03-26 Thread itoctopus
Escape it, use either htmlentities (with ENT_QUOTES) or addslashes.

--
itoctopus - http://www.itoctopus.com
Richard Lynch [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Mon, March 26, 2007 9:59 am, Ross wrote:
  Can I put post values directly into insert statements?
 
  $query = INSERT INTO categories (category_name) VALUES
  ('$_POST['cat_name']);

 Sure!

 If you want your webserver to get hacked by the Bad Guys, just go
 right ahead and do that.

 [that was tounge-in-cheek]

 Start reading here:
 http://phpsec.org

 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some indie artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?

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



[PHP] syntax question

2003-03-06 Thread Jimmy
I'm looking through some existing code for a project I'm working on, but
I keep running into this syntax that I really don't understand. Here's
an example:

$a=strpos($a,'-')?explode('-',$a,2):array($a);

What do the ? and the : do here?  I'm seeing this sort of thing all over
and just have no idea what ? : do. Thanks. 



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



Re: [PHP] syntax question

2003-03-06 Thread Leif K-Brooks
It's fairly simple.  The code you posted could also be written:
if(strpos($a,'-')){
$a = explode('-',$a,2);
}else{
$a = array($a);
}
It's called the ternary conditional operator.  Unfortunatley, it's 
buried in the PHP manual. 
http://us2.php.net/manual/en/language.expressions.php

Jimmy wrote:

I'm looking through some existing code for a project I'm working on, but
I keep running into this syntax that I really don't understand. Here's
an example:
$a=strpos($a,'-')?explode('-',$a,2):array($a);

What do the ? and the : do here?  I'm seeing this sort of thing all over
and just have no idea what ? : do. Thanks. 



 

--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.


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


[PHP] syntax question

2003-02-19 Thread Anthony Ritter
Greetings...
The following is the _third_ part of a script found in Julie Meloni's book
PHP Essentials on page 118.

The script dynmically generates a form box of field names, field types and
field sizes for a mysql table depending on what the user chooses.

My question is about syntax or logic in the following snippet:

The variables:
$field_name
$field_type
$field_length

are carried over from the previous script.

.

$sql = CREATE TABLE $table_name (;

   for ($i = 0; $i  count($field_name); $i++) {

  $sql .= $field_name[$i] $field_type[$i];

  if ($field_length[$i] != ) {
   $sql .=  ($field_length[$i]),;
  } else {
   $sql .= ,;
  }
 }

 $sql = substr($sql, 0, -1);

 $sql .= );

...

My question is about the snippet:

.
  if ($field_length[$i] != ) {
   $sql .=  ($field_length[$i]),;
  } else {
   $sql .= ,;
  }
..

In that it would say that if the field_length variable is not empty then add
the (number) and comma to the sql statement

If it is empty, then just add a comma.

The question:

Is the reasoning that a comma *must* be added since this is _within_ a loop?

As in:
CREATE TABLE chairs (
id INT(5),
item VARCHAR(50),
desc TEXT ,
price FLOAT , // common should be deleted but there is no way of knowing
this within the loop.
  // that's why after the loop closes there is a
substr() function to delete the comma.
);


And that after the loop ends, the comma is then deleted using the substr()
function to complete the sql statement.

TIA,
Tony Ritter
..

The complete script:


!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 3.2//EN
HTML
HEAD
TITLECreate a Database Table: Step 3/TITLE
style
p {font-family:arial;
font-size: .75em;}

input {border: 1px solid black;}

th {font-family:arial;
font-size: .75em;
color:red;}

h2 {font-family:arial;
font-size: 1em;}
/style


/HEAD
BODY

h2Adding ?php echo $table_name; ? Table/h2

?

 $sql = CREATE TABLE $table_name (;

   for ($i = 0; $i  count($field_name); $i++) {

  $sql .= $field_name[$i] $field_type[$i];

  if ($field_length[$i] != ) {
   $sql .=  ($field_length[$i]),;
  } else {
   $sql .= ,;
  }
 }

 $sql = substr($sql, 0, -1);

 $sql .= );

 $connection = mysql_connect(,,)
  or die(Couldn't connect to server.);

 $db = mysql_select_db(database, $connection)
  or die(Couldn't select database.);

 $sql_result = mysql_query($sql,$connection)
  or die(Couldn't execute query.);

 if (!$sql_result) {
  echo PCouldn't create table!;
 } else {
  echo P$table_name [table] has been created!;
 }



?


/BODY
/HTML





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




Re: [PHP] syntax question

2003-02-19 Thread Ernest E Vogelsinger
At 18:06 19.02.2003, Anthony Ritter spoke out and said:
[snip] 
The question:

Is the reasoning that a comma *must* be added since this is _within_ a loop?

As in:
CREATE TABLE chairs (
id INT(5),
item VARCHAR(50),
desc TEXT ,
price FLOAT , // common should be deleted but there is no way of knowing
[snip] 

No. The reason for the comma is that SQL dictates that column names in a
create table statement are separated by a comma.

This is valid SQL:
create table chairs(
id int(5),
item varchar(50),
desc text,
price float
);

This is invalid and generates an SQL error when passed to the server:
create table chairs(
id int(5)
item varchar(50)
desc text
price float
);



-- 
   O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
^ http://www.vogelsinger.at/


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




Re: [PHP] syntax question

2003-02-19 Thread Anthony Ritter
This is what I was getting at.

The following is correct mysql syntax in which a comma must be added after
each field - except for the last field - in this case price:

i.e.,
.

CREATE TABLE chairs(
id int(5),
item varchar(50),
desc text,
price float
);
.

However, within the loop in her script it says to add the comma after _each_
field since there is no way of knowing when the loop will end.

Thus, why is she directing the script - after the loop has ended - to lop
off the last comma by using the

substr() function call as in:

if ($field_length[$i] != )
 {
 $sql .= ($field_length[$i]) , ;
}
else
{
 $sql .= , ;
}

loop is finished.

and then...

$sql=substr($sql,0,-1); //which basically says to take the existing sql
statement string from the beginning  to the next to last character and
return it to the variable $sql thus taking off the comma.

Am I on the right track?

Thank you.
Tony Ritter
...


Ernest E Vogelsinger [EMAIL PROTECTED]

 No. The reason for the comma is that SQL dictates that column names in a
 create table statement are separated by a comma.

 This is valid SQL:
 create table chairs(
 id int(5),
 item varchar(50),
 desc text,
 price float
 );

 This is invalid and generates an SQL error when passed to the server:
 create table chairs(
 id int(5)
 item varchar(50)
 desc text
 price float
 );




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




Re[2]: [PHP] syntax question

2003-02-19 Thread Tom Rogers
Hi,

Thursday, February 20, 2003, 3:34:31 AM, you wrote:
AR This is what I was getting at.

AR The following is correct mysql syntax in which a comma must be added after
AR each field - except for the last field - in this case price:

AR i.e.,
AR .

AR CREATE TABLE chairs(
AR id int(5),
AR item varchar(50),
AR desc text,
AR price float
AR );
AR .

AR However, within the loop in her script it says to add the comma after _each_
AR field since there is no way of knowing when the loop will end.

AR Thus, why is she directing the script - after the loop has ended - to lop
AR off the last comma by using the

AR substr() function call

you can rework the logic a bit and only add a comma if it is not the first run
through the loop :

   $sql = CREATE TABLE $table_name (;
   for ($i = 0; $i  count($field_name); $i++) {
 if($i) $sql .= ',';   //first time i = 0 and this line ignored
 $sql .= $field_name[$i] $field_type[$i];
 if ($field_length[$i] != ) {
   $sql .=  ($field_length[$i]),;
 }
   }
   $sql .= );

But you are right there was a need to nuke the comma in the original script
-- 
regards,
Tom


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




Re: [PHP] syntax question

2003-02-19 Thread Jason k Larson
Anthony -

The column list is a comma seperated list, the last column cannot have a 
comma after it or the SQL server will expect another column to be listed.

However in that code segment it is not trying to determine if there is 
or is not a column, it is simply attempting to add the (length) 
attribute to the column getting created.  Regardless of length being 
specified, a comma is assumed to be needed to be appended to the $sql 
string during the loop.

Then as you have already stated, the last comma is removed after the 
loop is completed.  This should result in the correct SQL syntax as you 
shown.

Hope that helps ...
Jason k Larson


Anthony Ritter wrote:
This is what I was getting at.

The following is correct mysql syntax in which a comma must be added after
each field - except for the last field - in this case price:

i.e.,
.

CREATE TABLE chairs(
id int(5),
item varchar(50),
desc text,
price float
);
.

However, within the loop in her script it says to add the comma after _each_
field since there is no way of knowing when the loop will end.

Thus, why is she directing the script - after the loop has ended - to lop
off the last comma by using the

substr() function call as in:

if ($field_length[$i] != )
 {
 $sql .= ($field_length[$i]) , ;
}
else
{
 $sql .= , ;
}

loop is finished.

and then...

$sql=substr($sql,0,-1); //which basically says to take the existing sql
statement string from the beginning  to the next to last character and
return it to the variable $sql thus taking off the comma.

Am I on the right track?

Thank you.
Tony Ritter
...





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




Re: [PHP] syntax question

2003-02-19 Thread Anthony Ritter
Many thanks Jason.
TR





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




[PHP] syntax question...

2002-11-12 Thread Kelly Meeks
I saw this used in a script, but after a couple of searches didn't come up with 
anything on php.net.

?
$var=content
table
tr
td
font color=red
$phpvarhere
/font
/td
/tr
/table
content;
echo $var;
?

So, does this allow you to output mixed html/php without having to escape offending 
characters with no echo or print?
Conceptually, would the syntax above work?

TIA

Kelly 

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




Re: [PHP] syntax question...

2002-11-12 Thread bahwi
There are typically called a 'heredoc' or 'here document'. basically it 
changes the double quotation mark() to
'content' (in this case). To start, do this content

and to end it just type content;
on a line by itself.

The example you showed does echo the stuff out. It sets all the internal 
html to $var and echo's $var afterwards.

Hope this helps!

--Joseph Guhlin
http://www.bahwi.cc/
Web Developer / Unix Consultant

Kelly Meeks wrote:

I saw this used in a script, but after a couple of searches didn't come up with anything on php.net.

?
$var=content
table
tr
td
font color=red
$phpvarhere
/font
/td
/tr
/table
content;
echo $var;
?

So, does this allow you to output mixed html/php without having to escape offending characters with no echo or print?
Conceptually, would the syntax above work?

TIA

Kelly 
 



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




Re: [PHP] syntax question...

2002-11-12 Thread @ Edwin
Hello

Kelly Meeks [EMAIL PROTECTED] wrote:

 I saw this used in a script, but after a couple of searches didn't come up
with anything on php.net.

I think you're looking for this:

http://www.php.net/manual/en/language.types.string.php#language.types.string
.syntax.heredoc

- E

...[snip]...

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




[PHP] syntax question

2002-09-29 Thread Jeff Bluemel

couple of questions...  I'm am learning php  mysql without any books (will
also be using postgres, and informix, but assuming most of these are about
the same other then sql syntax), and through internet resources.  there are
a lot of good step throughs on a lot of stuff, but there are some things I'm
having a hard time finding how to's on...

for instance - if there a command that will give me the name of the fields
in the result set?  how to I test for a null value?  how do I go from one
row to the next, or how do I filter a result set based on a value in a
column?  is there a way to sum a specific field?

would appreciate whatever help I can get, and even better if somebody know's
a step through that goes through all the basic's of database syntaxes in
php.
--

Thanks,

Jeff Bluemel



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




Re: [PHP] syntax question

2002-09-29 Thread Justin French

on 30/09/02 2:44 PM, Jeff Bluemel ([EMAIL PROTECTED]) wrote:

if there a command that will give me the name of the fields
 in the result set?

mysql_field_name() might help... but generally I know what fields I want to
grab, so I don't need this...  I found this answer on http://php.net/mysql.
just as you could :)


 how to I test for a null value?

empty()?  isset()?  if($var == )?  if($var == NULL)??  have a look in
the php manual for string functions, and comparison operators


 how do I go from one row to the next

A while loop for the result set, row by row would look something like this,
printing the id, author and date for each row in the table

?
$sql = SELECT * FROM tablename WHERE blah blah;
$result = mysql_query($sql);
if($result)
{
while($myrow = mysql_fetch_array($result))
{
echo $myrow['id'];
echo $myrow['title'];
echo $myrow['author'];
}
}
?


 or how do I filter a result set based on a value in a
 column?

rather than filter a result set, write the right query to start with:

SELECT * FROM tablename WHERE colname='value' AND colname2='othervalue'

also check out:

ORDER BY colname 

and

LIMIT

in the mysql manual


 is there a way to sum a specific field?

SELECT SUM(colname) as mysum FROM tablename WHERE type='fiction'



 would appreciate whatever help I can get, and even better if somebody know's
 a step through that goes through all the basic's of database syntaxes in
 php.

It's not PHP that you neccessarily need to read up on the real power
comes from the SQL queries you write.  You need to spend time playing around
with code, and then asking us specific questions... needless to say, a hunt
through the manuals first would help, as would a search of the archives :)

This page is a pretty good start for MySQL:
http://www.mysql.com/doc/en/Function_Index.html


Justin French


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




Re: [PHP] syntax question

2002-09-29 Thread Chris Shiflett

Justin French wrote:

on 30/09/02 2:44 PM, Jeff Bluemel ([EMAIL PROTECTED]) wrote:
  

how to I test for a null value?


empty()?  isset()?  if($var == )?  if($var == NULL)??  have a look in
the php manual for string functions, and comparison operators


I think he maybe meant testing for null values in SQL.

If this is true, there is the null keyword: is null and is not null.

select * from table_name where column_name is not null

This selects all rows from a table where the data in column column_name 
is not null. Be careful with this, as it actually tests for null and not 
an empty string, for example. If you want to test whether a value is 
null once you have assigned it to a PHP variable, you can use one of 
Justin's suggestions.

In addition, PHP has null as well.

Happy hacking.

Chris


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




RE: [PHP] syntax question

2002-09-29 Thread Smith, Benjamin

Check out this tutorial on the MySQL website:

http://www.mysql.com/articles/mysql_intro.html

It contains links to the basics of SQL and its syntax, as well as giving you a good 
grounding in MySQL specifically.

As others have stated, most of the functionality you really need should be built into 
the SQL query. It's redundant to request excessive results from the database server, 
only to filter them out with custom php routines.

-Original Message-
From: Chris Shiflett [mailto:[EMAIL PROTECTED]]
Sent: Monday, 30 September 2002 3:30 PM
To: Justin French
Cc: Jeff Bluemel; [EMAIL PROTECTED]
Subject: Re: [PHP] syntax question


Justin French wrote:

on 30/09/02 2:44 PM, Jeff Bluemel ([EMAIL PROTECTED]) wrote:
  

how to I test for a null value?


empty()?  isset()?  if($var == )?  if($var == NULL)??  have a look in
the php manual for string functions, and comparison operators


I think he maybe meant testing for null values in SQL.

If this is true, there is the null keyword: is null and is not null.

select * from table_name where column_name is not null

This selects all rows from a table where the data in column column_name 
is not null. Be careful with this, as it actually tests for null and not 
an empty string, for example. If you want to test whether a value is 
null once you have assigned it to a PHP variable, you can use one of 
Justin's suggestions.

In addition, PHP has null as well.

Happy hacking.

Chris


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


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




Re: [PHP] syntax question

2002-09-29 Thread Jeff Bluemel

 mysql_field_name() might help... but generally I know what fields I want
to
 grab, so I don't need this...  I found this answer on
http://php.net/mysql.
 just as you could :)

I've been coding in other languages for about 6 years now, and I have looked
through a lot of the mysql stuff, and the explanations just don't make sense
for me (or the examples, I can make them work, but don't understand why they
work).  it seems there are just basic's of the language they expect that you
understand.  piece by piece I'm getting it, but I'm not happy just copying
code, and seeing something work.  I've got to know why something worked, and
feel like I understand more of the in's and out's.  I think the howto's skip
over a lot of things that have me confused.

it seems like a lot of this stuff deals more with array's, and that's
something I never learned to handle in other languages.  this may be part of
my problem...

as far as using the select queries, that's an option most times, but there
are some situations where there are too many calls to the database, and the
code isn't efficient.

here's a sample of things I made work, but don't understand...

TABLE border=3 cellspacing=2 cellpadding=2 bordercolor=#045C00
width=100%
  TR align=center
   TD align=leftDate/TD
   TDANI/TD
   TDDNIS/TD
   TDCountry/TD
   TDDestination/TD
   TDPay Phone/TD
   TDCost/TD
   TD align=rightMinutes/TD
  /TR

no - obviously here I understand what fields I'm getting out of the
database, but I'd prefer to use a syntax that would print the field names in
the top column of the table, and make my code more transportable.  with the
stuff I'm doing this would be a great help.

  ?
  mysql_data_seek ($sql, 0);
  while ($row = mysql_fetch_assoc ($sql))

now - from what I understand from the php.net doc's page this is putting
things in the array.  does that mean that in order to parse a result set I
have to turn it into an array, or can I directly access the recordset?  (all
examples point to creating an array out of it, not sure if this is
necessity, or just a better way to parse a result set)

now - my misunderstanding of this while statement throws me for a loop...  I
don't see anything in this code that moves a pointer to the next row, and
yet it seems to?

  {
  echo TR\n;
  foreach ($row as $column)
  {
  echo TD$column/TD\n;
  }
   echo /TR\n;
  }
  echo /TABLE;



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




Re: [PHP] syntax question

2002-09-29 Thread Jeff Bluemel

let me be more specific...

if a field value is null how do I test for it in the result set, or the
array?

here's a real live example...  I'm working with prepaid phone cards, and if
a card has not expired yet then the field zombie_date will be null.

so - when I do the mysql_fetch_assoc ($sql) what value will the field
contain if the resulting recordset was a null?  instead of leaving that
table space blank I would like to populate it with Not Expired or
something like that.  (I have a lot of scenario's where I would like to use
that).


Chris Shiflett [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Justin French wrote:

 on 30/09/02 2:44 PM, Jeff Bluemel ([EMAIL PROTECTED]) wrote:
 
 
 how to I test for a null value?
 
 
 empty()?  isset()?  if($var == )?  if($var == NULL)??  have a look in
 the php manual for string functions, and comparison operators
 

 I think he maybe meant testing for null values in SQL.

 If this is true, there is the null keyword: is null and is not null.

 select * from table_name where column_name is not null

 This selects all rows from a table where the data in column column_name
 is not null. Be careful with this, as it actually tests for null and not
 an empty string, for example. If you want to test whether a value is
 null once you have assigned it to a PHP variable, you can use one of
 Justin's suggestions.

 In addition, PHP has null as well.

 Happy hacking.

 Chris




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




[PHP] syntax question - eregi()

2002-09-19 Thread Anthony Ritter

I'm having difficulty understanding what the array does or refers to in the
eregi() function using php.

Listing below are returned strings with
[0]
[1]
[2]
..

?
$fp =fopen(C:\\TextFiles\\Test.htm,r);
$content = fread($fp,10);
eregi(b(.*)hr width,$content,$match);
$FinalLine=$match[2];
echo $FinalLine;
?
...

quick brown fox jumped over the lazy dog // output with $match[1]
.

quick brown fox jumped over the lazy dog.
hr width // output with $match[0]
..

file://output is nothing with $match[2]
...

Description:
int eregi ( string pattern, string string [, array regs])


Thank you.
Tony Ritter





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




[PHP] PHP Syntax question.

2001-08-31 Thread Erols

Sorry for my ignorance.
I just saw some PHP syntax that I am not aware of. Could someone please shed
some light on this.
What is the purpose of the @ in the following call to the PHP mail method?

@mail( /* some parameters */ );

If I remove the @, then php compiler complains.

Thank you in advance.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] PHP Syntax question.

2001-08-31 Thread Jon Haworth

The @ suppresses any warning/error messages that are produced - hence the
complaints when it's taken out :-)

Cheers
Jon

-Original Message-
From: Erols [mailto:[EMAIL PROTECTED]]
Sent: 31 August 2001 01:06
To: [EMAIL PROTECTED]
Subject: [PHP] PHP Syntax question.


Sorry for my ignorance.
I just saw some PHP syntax that I am not aware of. Could someone please shed
some light on this.
What is the purpose of the @ in the following call to the PHP mail method?

@mail( /* some parameters */ );

If I remove the @, then php compiler complains.

Thank you in advance.


**
'The information included in this Email is of a confidential nature and is 
intended only for the addressee. If you are not the intended addressee, 
any disclosure, copying or distribution by you is prohibited and may be 
unlawful. Disclosure to any party other than the addressee, whether 
inadvertent or otherwise is not intended to waive privilege or confidentiality'

**

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]