php-general Digest 12 Jul 2010 15:27:29 -0000 Issue 6842

2010-07-12 Thread php-general-digest-help

php-general Digest 12 Jul 2010 15:27:29 - Issue 6842

Topics (messages 306829 through 306833):

Recupero di pen drive e memory card non più accessibili
306829 by: RDNewsLetter

Re: There has to be a better way!!
306830 by: Richard Quadling

Re: Static Class Member References
306831 by: Richard Quadling

help with sql statement
306832 by: Adam
306833 by: Ashley Sheridan

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Non vedi più i tuoi dati personali o le foto a te più care contenute nella tua 
pen drive o memory card perchè il supporto non viene più
riconosciuto dal sistema?

Devi sapere che abbiamo il 99% di casi positivi di recupero dati e files da pen 
drive o memory card.

Goditi l'estate ci penseremo noi a recuperare tutti i files nella tua memoria 
statica danneggiata.

Caratteristiche EcoStatic:

1.Ritiro del supporto a carico della RD data Rescue (valido solo per l'Italia e 
la Svizzera);
2.Entro 90 gg riceverai l'esito, e se: Non ci sono files, non ci sono costi;
3.Per diagnosi positiva riceverai i tuoi file a solo 250,00 €;
4.Scaricherai i tuoi files comodamente dal tuo computer (fino ad 1Gb compresso, 
altrimenti su DVD).

Per ulteriori informazioni contattaci:

- 800.031.677 (Italia)
- 091.68.20.545 (Svizzera)

Il servizio EcoStatic ha una durata limitata nel tempo, a discrezione della 
direzione di RD data Rescue Sagl che ne comunicherà il termine con una
nuova comunicazione.

 
Cambia la tua sottoscrizione (
http://lnx.rddatarescue.it/joomla/index.php?option=com_acajoomItemid=999act=changesubscriber=88083cle=7c921edaf253c451737bf94d12a5b3bclistid=45
 )
Cancellati (
http://lnx.rddatarescue.it/joomla/index.php?option=com_acajoomItemid=999act=unsubscribesubscriber=88083cle=7c921edaf253c451737bf94d12a5b3bclistid=45
)

Powered by Joobi ( http://www.ijoobi.com )
---End Message---
---BeginMessage---
On 11 July 2010 02:26, Jason Pruim li...@pruimphotography.com wrote:

 On Jul 10, 2010, at 12:03 PM, Ashley Sheridan wrote:

 On Sat, 2010-07-10 at 11:58 -0400, Jason Pruim wrote:

 Okay so I've been fighting with this for awhile now and haven't found
 a better way yet

 What I want to do, is I have a small portion of my website included
 into a template. It is displaying hosting plans so on the main site
 index.php I want it to display a little bit of text (Same as on the
 main hosting page) and just 1 random hosting plan. then if they click
 on that plan and go into the main hosting section, I want them to see
 ALL the hosting plans.

 Here's the code that I'm using:

 if($_SERVER['PHP_SELF'] = /index.php) {
    $sql = SELECT * FROM `hosting` ORDER BY RAND() LIMIT 1;
 }else{
    $sql = SELECT * FROM `hosting` ORDER BY `hostingSort` ASC;

 }

 Now... I know there MUST be a better way to do it but I can't see the
 tree's through the forest.

 Any other way I could do it?

 I'm avoiding having lots of duplicate code/text on my pages.





 To avoid duplicating code, use an include file. If you already have some
 form of include (for a DB for example) then you can include your other
 includes in that.

 Also, not sure if it was a type in your email, but I think you want to
 use == in your if statement there, instead of = ;)

 Hey Ash,

 I may not have explained it properly :)

 I have 2 files... hosting.php and hostingsmall.php which have the EXACT same
 content in them other then the SQL statement. Hostingsmall.php has a LIMIT
 1 at the end...

 What I want to do is be able to get rid of hostingsmall.php which is
 currently included on my main page and run it all off of hosting.php but
 still be able to limit the query at the front page...

 the $_SERVER['PHP_SELF'] seems to be doing the trick... Just wanted to find
 a better way since I've heard you should trust PHP_SELF...

 But if that's my best bet since it's working I can stick with it :)

If the only difference between the 2 files is the SQL statement, then
maybe you could ...

?php
// hosting.php

// Define SQL
$sql = ' ... ';

// Include template
include 'template.php';
?

And the same for hostingsmall.php, except you have a different SQL statement.
---End Message---
---BeginMessage---
On 11 July 2010 23:19, Daniel Kolbo kolb0...@umn.edu wrote:
 Hello PHPers,

 I'm having some trouble understanding some PHP behaviour.  The following
 example script exhibits the behaviour which I cannot understand.
 [code]
 ?php

 class A
 {
        public static $a = 3;

        function __construct()
        {
                //self::$a = $this; //[i]
                self::$a = $this; //[ii]
        }
 }

 class B extends  A
 {
        function __construct()
        {
                parent::__construct();
      

[PHP] Recupero di pen drive e memory card non più accessibili

2010-07-12 Thread RDNewsLetter
Non vedi più i tuoi dati personali o le foto a te più care contenute nella tua 
pen drive o memory card perchè il supporto non viene più
riconosciuto dal sistema?

Devi sapere che abbiamo il 99% di casi positivi di recupero dati e files da pen 
drive o memory card.

Goditi l'estate ci penseremo noi a recuperare tutti i files nella tua memoria 
statica danneggiata.

Caratteristiche EcoStatic:

1.Ritiro del supporto a carico della RD data Rescue (valido solo per l'Italia e 
la Svizzera);
2.Entro 90 gg riceverai l'esito, e se: Non ci sono files, non ci sono costi;
3.Per diagnosi positiva riceverai i tuoi file a solo 250,00 €;
4.Scaricherai i tuoi files comodamente dal tuo computer (fino ad 1Gb compresso, 
altrimenti su DVD).

Per ulteriori informazioni contattaci:

- 800.031.677 (Italia)
- 091.68.20.545 (Svizzera)

Il servizio EcoStatic ha una durata limitata nel tempo, a discrezione della 
direzione di RD data Rescue Sagl che ne comunicherà il termine con una
nuova comunicazione.

 
Cambia la tua sottoscrizione (
http://lnx.rddatarescue.it/joomla/index.php?option=com_acajoomItemid=999act=changesubscriber=88083cle=7c921edaf253c451737bf94d12a5b3bclistid=45
 )
Cancellati (
http://lnx.rddatarescue.it/joomla/index.php?option=com_acajoomItemid=999act=unsubscribesubscriber=88083cle=7c921edaf253c451737bf94d12a5b3bclistid=45
)

Powered by Joobi ( http://www.ijoobi.com )


Re: [PHP] There has to be a better way!!

2010-07-12 Thread Richard Quadling
On 11 July 2010 02:26, Jason Pruim li...@pruimphotography.com wrote:

 On Jul 10, 2010, at 12:03 PM, Ashley Sheridan wrote:

 On Sat, 2010-07-10 at 11:58 -0400, Jason Pruim wrote:

 Okay so I've been fighting with this for awhile now and haven't found
 a better way yet

 What I want to do, is I have a small portion of my website included
 into a template. It is displaying hosting plans so on the main site
 index.php I want it to display a little bit of text (Same as on the
 main hosting page) and just 1 random hosting plan. then if they click
 on that plan and go into the main hosting section, I want them to see
 ALL the hosting plans.

 Here's the code that I'm using:

 if($_SERVER['PHP_SELF'] = /index.php) {
    $sql = SELECT * FROM `hosting` ORDER BY RAND() LIMIT 1;
 }else{
    $sql = SELECT * FROM `hosting` ORDER BY `hostingSort` ASC;

 }

 Now... I know there MUST be a better way to do it but I can't see the
 tree's through the forest.

 Any other way I could do it?

 I'm avoiding having lots of duplicate code/text on my pages.





 To avoid duplicating code, use an include file. If you already have some
 form of include (for a DB for example) then you can include your other
 includes in that.

 Also, not sure if it was a type in your email, but I think you want to
 use == in your if statement there, instead of = ;)

 Hey Ash,

 I may not have explained it properly :)

 I have 2 files... hosting.php and hostingsmall.php which have the EXACT same
 content in them other then the SQL statement. Hostingsmall.php has a LIMIT
 1 at the end...

 What I want to do is be able to get rid of hostingsmall.php which is
 currently included on my main page and run it all off of hosting.php but
 still be able to limit the query at the front page...

 the $_SERVER['PHP_SELF'] seems to be doing the trick... Just wanted to find
 a better way since I've heard you should trust PHP_SELF...

 But if that's my best bet since it's working I can stick with it :)

If the only difference between the 2 files is the SQL statement, then
maybe you could ...

?php
// hosting.php

// Define SQL
$sql = ' ... ';

// Include template
include 'template.php';
?

And the same for hostingsmall.php, except you have a different SQL statement.

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



Re: [PHP] Static Class Member References

2010-07-12 Thread Richard Quadling
On 11 July 2010 23:19, Daniel Kolbo kolb0...@umn.edu wrote:
 Hello PHPers,

 I'm having some trouble understanding some PHP behaviour.  The following
 example script exhibits the behaviour which I cannot understand.
 [code]
 ?php

 class A
 {
        public static $a = 3;

        function __construct()
        {
                //self::$a = $this; //[i]
                self::$a = $this; //[ii]
        }
 }

 class B extends  A
 {
        function __construct()
        {
                parent::__construct();
        }
 }

 class C {
        var $c;

        function __construct()
        {
                $this-c = A::$a;
        }

 }


 $c = new C;
 $b = new B;
 $cee = new C;

 var_dump($c-c); // [i] prints object(B), but [ii] prints int 3
 var_dump($cee-c); // [i] prints object(B), and [ii] prints object(B)

 ?
 [/code]

 Why does $c-c print 'int 3' ?

 I'm nervous to use self::$a = $this; because I don't want to be
 copying the whole object.  However, isn't $this just a reference to the
 object, so self::$a = $this; is just copying the reference and not the
 actual object, right?

 Thanks in advance


What do you think the value should be?

A static property is bound to the class and not to an instance of the class.

So, A::$a is a reference to the static value. If you alter the value,
it will be altered for a subclasses of A and for any other reference
to it.

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



[PHP] help with sql statement

2010-07-12 Thread Adam
I was google searching, and the only SQL mailing list I found is 
currently giving a 503 error, so I hope you don't mind me asking my SQL 
question here, since there are a lot of SQL gurus here.  I am having a 
syntax problem:


Instead of doing a query like this::

select SMS_R_SYSTEM.Name from SMS_R_System where 
(SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC) or 
(SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/XYZ)


I'd like to shorten it in the where clause to:

select SMS_R_SYSTEM.Name from SMS_R_System where 
(SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC, 
example.com/COMPUTERS/MAIN CAMPUS/XYZ)


But I'm getting a syntax error.  Any idea why my SQL syntax isn't valid?



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



Re: [PHP] help with sql statement

2010-07-12 Thread Ashley Sheridan
On Mon, 2010-07-12 at 10:24 -0500, Adam wrote:

 I was google searching, and the only SQL mailing list I found is 
 currently giving a 503 error, so I hope you don't mind me asking my SQL 
 question here, since there are a lot of SQL gurus here.  I am having a 
 syntax problem:
 
 Instead of doing a query like this::
 
 select SMS_R_SYSTEM.Name from SMS_R_System where 
 (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC) or 
 (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/XYZ)
 
 I'd like to shorten it in the where clause to:
 
 select SMS_R_SYSTEM.Name from SMS_R_System where 
 (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN CAMPUS/ABC, 
 example.com/COMPUTERS/MAIN CAMPUS/XYZ)
 
 But I'm getting a syntax error.  Any idea why my SQL syntax isn't valid?
 
 
 


The short answer is your syntax isn't valid, which means that what
you've written isn't valid SQL :p

What I think you're looking for instead is something like this:

SELECT SMS_R_SYSTEM.Name FROM SMS_R_System WHERE
SMS_R_System.SystemOUName IN (example.com/COMPUTERS/MAIN CAMPUS/ABC,
example.com/COMPUTERS/MAIN CAMPUS/XYZ)

which lets MySQL compare the field against an array of different values
within the brackets.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] help with sql statement

2010-07-12 Thread Tommy Pham
 -Original Message-
 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
 Sent: Monday, July 12, 2010 8:26 AM
 To: Adam
 Cc: PHP General
 Subject: Re: [PHP] help with sql statement
 
 On Mon, 2010-07-12 at 10:24 -0500, Adam wrote:
 
  I was google searching, and the only SQL mailing list I found is
  currently giving a 503 error, so I hope you don't mind me asking my
  SQL question here, since there are a lot of SQL gurus here.  I am
  having a syntax problem:
 
  Instead of doing a query like this::
 
  select SMS_R_SYSTEM.Name from SMS_R_System where
  (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN
 CAMPUS/ABC)
  or (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN
  CAMPUS/XYZ)
 
  I'd like to shorten it in the where clause to:
 
  select SMS_R_SYSTEM.Name from SMS_R_System where
  (SMS_R_System.SystemOUName = example.com/COMPUTERS/MAIN
 CAMPUS/ABC,
  example.com/COMPUTERS/MAIN CAMPUS/XYZ)
 
  But I'm getting a syntax error.  Any idea why my SQL syntax isn't valid?
 
 
 
 
 
 The short answer is your syntax isn't valid, which means that what you've
 written isn't valid SQL :p
 
 What I think you're looking for instead is something like this:
 
 SELECT SMS_R_SYSTEM.Name FROM SMS_R_System WHERE
 SMS_R_System.SystemOUName IN (example.com/COMPUTERS/MAIN
 CAMPUS/ABC, example.com/COMPUTERS/MAIN CAMPUS/XYZ)
 

Even shorter ;)

SELECT srs.Name FROM SMS_R_System srs WHERE srs.SystemOUName IN
(example.com/COMPUTERS/MAIN CAMPUS/ABC, example.com/COMPUTERS/MAIN
CAMPUS/XYZ)

 which lets MySQL compare the field against an array of different values
 within the brackets.

Given his syntax, I'd guess that his RDBMS is MS SQL and he's trying to get
some info from the DB that's populated by MS' SMS.

Regards,
Tommy

 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 



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



[PHP] Looking for a little MySQL help as well

2010-07-12 Thread Phillip Baker
Hey All,

I am looking for a little MySQL Query help as well.
I am not getting any response form the MySQl Email list to my query.
And knowing there are some SQL wizards on this list I thought I would as for
help as well.

I have one table with products that many have one or more categories.
I am using an index table and am having trouble getting a proper result set.

Table 1
Product_id  |  Product_Name
1|  Product A
2|  Product B
3|  Product C

Table 2
Category_id  |  Category_Name
1 |   Admin
2 |   Marketing
3 |   Support
4 |   IT


Table 3
Product_id  |  Category_id
1|  1
1|  3
2|  2
3|  3
3|  4

Result would look like
Product A, Admin, Support
Product B, Marketing
Product C, Support, IT

I believe this is a one to many using an index table?
I appreciate any help.
Thanks.

Blessed Be

Phillip

If you try to protect idiots from themselves, even if you succeed, you just
wind up filling the world with idiots.
   - - Doug Casey


[PHP] Validate if the field of a form is empty

2010-07-12 Thread te0t3l
Hi, I need to validate a field that work with Multifile plugin of Jquery,
I want to check if the field is empty with php.

[code]
input name=archivo[] class=multi type=file accept=gif|jpg|png/
input name=button type=submit value=Submit
[code]

I've tried different ways but it does not work:
for example:
$field = $_FILES[archivo][name];
$field = $_FILES[archivo[]][name];

i dont know how to validate it, any help would be appreciated.

Thanks,


Re: [PHP] Looking for a little MySQL help as well

2010-07-12 Thread Jim Lucas
Phillip Baker wrote:
 Hey All,
 
 I am looking for a little MySQL Query help as well.
 I am not getting any response form the MySQl Email list to my query.
 And knowing there are some SQL wizards on this list I thought I would as for
 help as well.
 
 I have one table with products that many have one or more categories.
 I am using an index table and am having trouble getting a proper result set.
 
 Table 1
 Product_id  |  Product_Name
 1|  Product A
 2|  Product B
 3|  Product C
 
 Table 2
 Category_id  |  Category_Name
 1 |   Admin
 2 |   Marketing
 3 |   Support
 4 |   IT
 
 
 Table 3
 Product_id  |  Category_id
 1|  1
 1|  3
 2|  2
 3|  3
 3|  4
 
 Result would look like
 Product A, Admin, Support
 Product B, Marketing
 Product C, Support, IT
 
 I believe this is a one to many using an index table?
 I appreciate any help.
 Thanks.
 
 Blessed Be
 
 Phillip
 
 If you try to protect idiots from themselves, even if you succeed, you just
 wind up filling the world with idiots.
- - Doug Casey
 


SELECT
  products.Product_Name,
  categories.Category_Name
FROM
  products,
  categories,
  p2c_map
WHERE
  products.Product_ID = p2c_map.Product_ID
AND
  categories.Category_ID = p2c_map.Category_ID

Gives the results that you are looking for.  Once you get the data, you must
concat things your self, but it is everything that you are looking for.

To search for Categories of a given product, you would add this to the WHERE 
section

AND
  products.Product_Name = 'Product A'

of, if you were looking for all the products in a given category, you would add 
this

AND
  categories.Category_Name = 'Category 1'


The following is the table structure that I am using with mock data.

CREATE TABLE IF NOT EXISTS `categories` (
  `Category_ID` int(11) NOT NULL auto_increment,
  `Category_Name` varchar(16) collate latin1_bin NOT NULL,
  PRIMARY KEY  (`Category_ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=5 ;

INSERT INTO `categories` (`Category_ID`, `Category_Name`) VALUES
(1, 'Category 1'),(2, 'Category 2'),(3, 'Category 3'),(4, 'Category 4');

CREATE TABLE IF NOT EXISTS `p2c_map` (
  `Product_id` int(11) NOT NULL,
  `Category_ID` int(11) NOT NULL,
  PRIMARY KEY  (`Product_id`,`Category_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin;

INSERT INTO `p2c_map` (`Product_id`, `Category_ID`) VALUES
(1, 1),(1, 2),(1, 4),(2, 2),(2, 3),(3, 4),(4, 1),(4, 4);

CREATE TABLE IF NOT EXISTS `products` (
  `Product_ID` int(11) NOT NULL auto_increment,
  `Product_Name` varchar(16) collate latin1_bin NOT NULL,
  PRIMARY KEY  (`Product_ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=5 ;

INSERT INTO `products` (`Product_ID`, `Product_Name`) VALUES
(1, 'Product A'),(2, 'Product B'),(3, 'Product C'),(4, 'Product D');

-- 
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

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



Re: [PHP] Validate if the field of a form is empty

2010-07-12 Thread Jim Lucas
te0t3l wrote:
 Hi, I need to validate a field that work with Multifile plugin of Jquery,
 I want to check if the field is empty with php.
 
 [code]
 input name=archivo[] class=multi type=file accept=gif|jpg|png/
 input name=button type=submit value=Submit
 [code]
 
 I've tried different ways but it does not work:
 for example:
 $field = $_FILES[archivo][name];
 $field = $_FILES[archivo[]][name];
 
 i dont know how to validate it, any help would be appreciated.
 
 Thanks,
 

To see what is happening, look at the output of print_r($_FILES);

But, you should be doing it like this.

foreach ( $_FILES[archivo] AS $file ) {
  $field = $file['name'];
  ...
}


-- 
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

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



Re: [PHP] Looking for a little MySQL help as well

2010-07-12 Thread Phillip Baker
Thanks Jim,

This outputs 2 results.
Is there a way to get the one result set per product regardless of the
number of categories associated with the product, yet displaying all the
categories associated with said prodcut?

Blessed Be

Phillip

If you try to protect idiots from themselves, even if you succeed, you just
wind up filling the world with idiots.
   - - Doug Casey


On Mon, Jul 12, 2010 at 12:21 PM, Jim Lucas li...@cmsws.com wrote:

 Phillip Baker wrote:
  Hey All,
 
  I am looking for a little MySQL Query help as well.
  I am not getting any response form the MySQl Email list to my query.
  And knowing there are some SQL wizards on this list I thought I would as
 for
  help as well.
 
  I have one table with products that many have one or more categories.
  I am using an index table and am having trouble getting a proper result
 set.
 
  Table 1
  Product_id  |  Product_Name
  1|  Product A
  2|  Product B
  3|  Product C
 
  Table 2
  Category_id  |  Category_Name
  1 |   Admin
  2 |   Marketing
  3 |   Support
  4 |   IT
 
 
  Table 3
  Product_id  |  Category_id
  1|  1
  1|  3
  2|  2
  3|  3
  3|  4
 
  Result would look like
  Product A, Admin, Support
  Product B, Marketing
  Product C, Support, IT
 
  I believe this is a one to many using an index table?
  I appreciate any help.
  Thanks.
 
  Blessed Be
 
  Phillip
 
  If you try to protect idiots from themselves, even if you succeed, you
 just
  wind up filling the world with idiots.
 - - Doug Casey
 


 SELECT
  products.Product_Name,
  categories.Category_Name
 FROM
  products,
  categories,
  p2c_map
 WHERE
  products.Product_ID = p2c_map.Product_ID
 AND
  categories.Category_ID = p2c_map.Category_ID

 Gives the results that you are looking for.  Once you get the data, you
 must
 concat things your self, but it is everything that you are looking for.

 To search for Categories of a given product, you would add this to the
 WHERE section

 AND
  products.Product_Name = 'Product A'

 of, if you were looking for all the products in a given category, you would
 add this

 AND
  categories.Category_Name = 'Category 1'


 The following is the table structure that I am using with mock data.

 CREATE TABLE IF NOT EXISTS `categories` (
  `Category_ID` int(11) NOT NULL auto_increment,
  `Category_Name` varchar(16) collate latin1_bin NOT NULL,
  PRIMARY KEY  (`Category_ID`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=5
 ;

 INSERT INTO `categories` (`Category_ID`, `Category_Name`) VALUES
 (1, 'Category 1'),(2, 'Category 2'),(3, 'Category 3'),(4, 'Category 4');

 CREATE TABLE IF NOT EXISTS `p2c_map` (
  `Product_id` int(11) NOT NULL,
  `Category_ID` int(11) NOT NULL,
  PRIMARY KEY  (`Product_id`,`Category_ID`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin;

 INSERT INTO `p2c_map` (`Product_id`, `Category_ID`) VALUES
 (1, 1),(1, 2),(1, 4),(2, 2),(2, 3),(3, 4),(4, 1),(4, 4);

 CREATE TABLE IF NOT EXISTS `products` (
  `Product_ID` int(11) NOT NULL auto_increment,
  `Product_Name` varchar(16) collate latin1_bin NOT NULL,
  PRIMARY KEY  (`Product_ID`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=5
 ;

 INSERT INTO `products` (`Product_ID`, `Product_Name`) VALUES
 (1, 'Product A'),(2, 'Product B'),(3, 'Product C'),(4, 'Product D');

 --
 Jim Lucas

 A: Maybe because some people are too annoyed by top-posting.
 Q: Why do I not get an answer to my question(s)?
 A: Because it messes up the order in which people normally read text.
 Q: Why is top-posting such a bad thing?



[PHP] Serial Numbers

2010-07-12 Thread Gary
I'm sure it is possible, but I am unsure how to do this.  I have created a 
Sale coupon that I was going to put up on a site that I manage, for visitors 
to print out and bring to the store. The coupon is currently a .png, however 
I was planning on converting to a pdf.  I would like to put on the coupon a 
serial number that increases by 1 everytime the page is viewed. I dont 
really care if someone refreshes the page and skews the numbers.

Is this possible and could someone give me some help?

Thanks

Gary 



__ Information from ESET Smart Security, version of virus signature 
database 5273 (20100712) __

The message was checked by ESET Smart Security.

http://www.eset.com





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



Re: [PHP] Serial Numbers

2010-07-12 Thread Shreyas Agasthya
Perhaps using a static variable might help? I am just guessing.

--Shreyas

On Tue, Jul 13, 2010 at 12:22 AM, Gary gp...@paulgdesigns.com wrote:

 I'm sure it is possible, but I am unsure how to do this.  I have created a
 Sale coupon that I was going to put up on a site that I manage, for
 visitors
 to print out and bring to the store. The coupon is currently a .png,
 however
 I was planning on converting to a pdf.  I would like to put on the coupon a
 serial number that increases by 1 everytime the page is viewed. I dont
 really care if someone refreshes the page and skews the numbers.

 Is this possible and could someone give me some help?

 Thanks

 Gary



 __ Information from ESET Smart Security, version of virus signature
 database 5273 (20100712) __

 The message was checked by ESET Smart Security.

 http://www.eset.com





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




-- 
Regards,
Shreyas Agasthya


Re: [PHP] Serial Numbers

2010-07-12 Thread Ashley Sheridan
On Mon, 2010-07-12 at 14:52 -0400, Gary wrote:

 I'm sure it is possible, but I am unsure how to do this.  I have created a 
 Sale coupon that I was going to put up on a site that I manage, for visitors 
 to print out and bring to the store. The coupon is currently a .png, however 
 I was planning on converting to a pdf.  I would like to put on the coupon a 
 serial number that increases by 1 everytime the page is viewed. I dont 
 really care if someone refreshes the page and skews the numbers.
 
 Is this possible and could someone give me some help?
 
 Thanks
 
 Gary 
 
 
 
 __ Information from ESET Smart Security, version of virus signature 
 database 5273 (20100712) __
 
 The message was checked by ESET Smart Security.
 
 http://www.eset.com
 
 
 
 
 


You need some indicator on your server to keep track of the number. To
me, the ideal solution would appear to be a MySQL database. You can set
up a table with an auto_increment field and use the id generated from
that.

Two things to maybe note:


 1. Don't use MAX(id) in a query to get the next auto value, use
something like mysql_insert_id() instead. The MAX() method is
just a race condition waiting to happen.
 2. If you expect a lot of traffic, then consider setting this table
to use the InnoDB engine instead of MyIsam which is usually the
default. This allows MySQL to apply row-level locking instead of
table-level, which can improve performance when PHP has to wait
for MySQL.


Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Serial Numbers

2010-07-12 Thread Floyd Resler

On Jul 12, 2010, at 2:52 PM, Gary wrote:

 I'm sure it is possible, but I am unsure how to do this.  I have created a 
 Sale coupon that I was going to put up on a site that I manage, for visitors 
 to print out and bring to the store. The coupon is currently a .png, however 
 I was planning on converting to a pdf.  I would like to put on the coupon a 
 serial number that increases by 1 everytime the page is viewed. I dont 
 really care if someone refreshes the page and skews the numbers.
 
 Is this possible and could someone give me some help?
 
 Thanks
 
 Gary 
 

Is there any particular reason you need it to be a PDF?  If not and the GD 
library is installed in your PHP, I would suggest using the GD library to draw 
your serial number on the coupon.  As for keeping track of the counter I would 
do it either in a database table or save the number to file.

Take care,
Floyd


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



Re: [PHP] Serial Numbers

2010-07-12 Thread Ashley Sheridan
On Mon, 2010-07-12 at 15:17 -0400, Floyd Resler wrote:

 On Jul 12, 2010, at 2:52 PM, Gary wrote:
 
  I'm sure it is possible, but I am unsure how to do this.  I have created a 
  Sale coupon that I was going to put up on a site that I manage, for 
  visitors 
  to print out and bring to the store. The coupon is currently a .png, 
  however 
  I was planning on converting to a pdf.  I would like to put on the coupon a 
  serial number that increases by 1 everytime the page is viewed. I dont 
  really care if someone refreshes the page and skews the numbers.
  
  Is this possible and could someone give me some help?
  
  Thanks
  
  Gary 
  
 
 Is there any particular reason you need it to be a PDF?  If not and the GD 
 library is installed in your PHP, I would suggest using the GD library to 
 draw your serial number on the coupon.  As for keeping track of the counter I 
 would do it either in a database table or save the number to file.
 
 Take care,
 Floyd
 
 


I can think of a good reason for making it as a PDF. A PDF is built for
printing to scale exactly as you need, whereas a bitmap is very
different. Traditionally, GD creates screen images, which are 72dpi,
whereas print usually uses 300dpi bitmaps, and they generally don't
scale well.

Having said that, writing it in GD will be a fair bit easier!

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Serial Numbers

2010-07-12 Thread Floyd Resler

On Jul 12, 2010, at 3:22 PM, Ashley Sheridan wrote:

 On Mon, 2010-07-12 at 15:17 -0400, Floyd Resler wrote:
 
 On Jul 12, 2010, at 2:52 PM, Gary wrote:
 
  I'm sure it is possible, but I am unsure how to do this.  I have created a 
  Sale coupon that I was going to put up on a site that I manage, for 
  visitors 
  to print out and bring to the store. The coupon is currently a .png, 
  however 
  I was planning on converting to a pdf.  I would like to put on the coupon 
  a 
  serial number that increases by 1 everytime the page is viewed. I dont 
  really care if someone refreshes the page and skews the numbers.
  
  Is this possible and could someone give me some help?
  
  Thanks
  
  Gary 
  
 
 Is there any particular reason you need it to be a PDF?  If not and the GD 
 library is installed in your PHP, I would suggest using the GD library to 
 draw your serial number on the coupon.  As for keeping track of the counter 
 I would do it either in a database table or save the number to file.
 
 Take care,
 Floyd
 
 
 
 I can think of a good reason for making it as a PDF. A PDF is built for 
 printing to scale exactly as you need, whereas a bitmap is very different. 
 Traditionally, GD creates screen images, which are 72dpi, whereas print 
 usually uses 300dpi bitmaps, and they generally don't scale well.
 
 Having said that, writing it in GD will be a fair bit easier!
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 

Having said that, writing it in GD will be a fair bit easier!

Yep, that's why I was asking! :)

Take care,
Floyd



Re: [PHP] Serial Numbers

2010-07-12 Thread Gary

Floyd Resler fres...@adex-intl.com wrote in message 
news:e6321b00-590d-4294-9b81-81cc92883...@adex-intl.com...

On Jul 12, 2010, at 2:52 PM, Gary wrote:

 I'm sure it is possible, but I am unsure how to do this.  I have created a
 Sale coupon that I was going to put up on a site that I manage, for 
 visitors
 to print out and bring to the store. The coupon is currently a .png, 
 however
 I was planning on converting to a pdf.  I would like to put on the coupon 
 a
 serial number that increases by 1 everytime the page is viewed. I dont
 really care if someone refreshes the page and skews the numbers.

 Is this possible and could someone give me some help?

 Thanks

 Gary


Is there any particular reason you need it to be a PDF?  If not and the GD 
library is installed in your PHP, I would suggest using the GD library to 
draw your serial number on the coupon.  As for keeping track of the counter 
I would do it either in a database table or save the number to file.

Take care,
Floyd


Floyd

Thanks for your reponse.

No real reason that the file has to be a pdf, that was my original plan 
before I came up with the counter idea..  I also thought it might not be as 
difficult to put the script on a pdf.

I have used the GD library in the past, so it is installed on the server, 
however I dont know how to apply to this situation..

After I posted the question, the thought came to me to simply create the 
coupon in html and include a simple counter, like a hit counter, but since I 
had the png already created, I was hoping there was a way to include the 
script on it instead of recreating in html/php.

Gary




__ Information from ESET Smart Security, version of virus signature 
database 5273 (20100712) __

The message was checked by ESET Smart Security.

http://www.eset.com





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



RE: [PHP] Looking for a little MySQL help as well

2010-07-12 Thread Tommy Pham
 -Original Message-
 From: Phillip Baker [mailto:phil...@freewolf.net]
 Sent: Monday, July 12, 2010 11:36 AM
 To: Jim Lucas
 Cc: PHP General List
 Subject: Re: [PHP] Looking for a little MySQL help as well
 
 Thanks Jim,
 
 This outputs 2 results.
 Is there a way to get the one result set per product regardless of the
number
 of categories associated with the product, yet displaying all the
categories
 associated with said prodcut?
 
 Blessed Be
 
 Phillip
 
snip

Phillip,

What you're asking for requires the use of (IIRC) 'cursors'.  I don't know
if MySQL's meaning/usage of 'cursors' is the same as MSSQL.  Either way,
you'll need to write some serious (read pain in the a**) Stored Procedure
(SP).  You're better off implementing that in PHP loop containing 'if' since
you're not a DBA ;).

Regards,
Tommy


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



Re: [PHP] Serial Numbers

2010-07-12 Thread Gary




Ashley Sheridan a...@ashleysheridan.co.uk wrote in message 
news:1278962039.2202.5.ca...@localhost...
 On Mon, 2010-07-12 at 14:52 -0400, Gary wrote:

 I'm sure it is possible, but I am unsure how to do this.  I have created 
 a
 Sale coupon that I was going to put up on a site that I manage, for 
 visitors
 to print out and bring to the store. The coupon is currently a .png, 
 however
 I was planning on converting to a pdf.  I would like to put on the coupon 
 a
 serial number that increases by 1 everytime the page is viewed. I dont
 really care if someone refreshes the page and skews the numbers.

 Is this possible and could someone give me some help?

 Thanks

 Gary



 __ Information from ESET Smart Security, version of virus 
 signature database 5273 (20100712) __

 The message was checked by ESET Smart Security.

 http://www.eset.com







 You need some indicator on your server to keep track of the number. To
 me, the ideal solution would appear to be a MySQL database. You can set
 up a table with an auto_increment field and use the id generated from
 that.

 Two things to maybe note:


 1. Don't use MAX(id) in a query to get the next auto value, use
something like mysql_insert_id() instead. The MAX() method is
just a race condition waiting to happen.
 2. If you expect a lot of traffic, then consider setting this table
to use the InnoDB engine instead of MyIsam which is usually the
default. This allows MySQL to apply row-level locking instead of
table-level, which can improve performance when PHP has to wait
for MySQL.


 Thanks,
 Ash
 http://www.ashleysheridan.co.uk


Ashley

Thanks for your reply.

I was not going to go to the trouble of calling the AI number from a 
database, although that is an interesting concept.

The question really becomes How to insert into an image I could just write 
a simple hit counter and create a new php/html page, but since the image 
(coupon) was already created, I thought it would be easier, not to mention 
expand my abilities.

It is a small shop and if they get 100 coupons, they will be extatic, so it 
will not kill us if it were too much trouble.

I have gone to using  InnoDB as my standard table, mainly for the foreign 
key ability, but I do keep reading that there are more and more advantage to 
using is over Myisam.

Thanks again for your reply.

Gary
 



__ Information from ESET Smart Security, version of virus signature 
database 5273 (20100712) __

The message was checked by ESET Smart Security.

http://www.eset.com





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



Re: [PHP] Looking for a little MySQL help as well

2010-07-12 Thread Phillip Baker
Thanks Tommy,

Damn.
I was hoping to avoid that and get all the information in one query rather
than running a ton of queries. :-(
But might be why I am having trouble finding an answer for this on the net.

Blessed Be

Phillip

If you try to protect idiots from themselves, even if you succeed, you just
wind up filling the world with idiots.
   - - Doug Casey


On Mon, Jul 12, 2010 at 1:37 PM, Tommy Pham tommy...@gmail.com wrote:

  -Original Message-
  From: Phillip Baker [mailto:phil...@freewolf.net]
  Sent: Monday, July 12, 2010 11:36 AM
  To: Jim Lucas
  Cc: PHP General List
  Subject: Re: [PHP] Looking for a little MySQL help as well
 
  Thanks Jim,
 
  This outputs 2 results.
  Is there a way to get the one result set per product regardless of the
 number
  of categories associated with the product, yet displaying all the
 categories
  associated with said prodcut?
 
  Blessed Be
 
  Phillip
 
 snip

 Phillip,

 What you're asking for requires the use of (IIRC) 'cursors'.  I don't know
 if MySQL's meaning/usage of 'cursors' is the same as MSSQL.  Either way,
 you'll need to write some serious (read pain in the a**) Stored Procedure
 (SP).  You're better off implementing that in PHP loop containing 'if'
 since
 you're not a DBA ;).

 Regards,
 Tommy


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




RE: [PHP] Looking for a little MySQL help as well

2010-07-12 Thread Tommy Pham
From: Phillip Baker [mailto:phil...@freewolf.net] 
Sent: Monday, July 12, 2010 1:33 PM
To: Tommy Pham
Cc: PHP General List
Subject: Re: [PHP] Looking for a little MySQL help as well

Thanks Tommy,

Damn.
I was hoping to avoid that and get all the information in one query rather
than running a ton of queries. :-(
But might be why I am having trouble finding an answer for this on the net.

Blessed Be

Phillip



Phillip,

I think you misunderstood.  Your query is still 1 query.  You just loop
through the results and compare certain field for changes using 'if' to get
the desired effect for your sample tables:

Table 1
Product_id  |  Product_Name
1|  Product A
2|  Product B
3|  Product C

Table 2
Category_id  |  Category_Name
1 |   Admin
2 |   Marketing
3 |   Support
4 |   IT


Table 3
Product_id  |  Category_id
1|  1
1|  3
2|  2
3|  3
3|  4

Result would look like
Product A, Admin, Support
Product B, Marketing
Product C, Support, IT



Here's the pseudo code:

$last_product_id = null;
$current_product_id = null;
Loop $result_set if not end of $result_set
  $current_product_id = get(Product_id) from $result_set;
  If ($last_product_id != $current_product_id)
  {
 $last_product_id = $current_product_id;
 $product_name = get(Product_Name) from  $result_set;
 $category_name = get(Category_Name) from $result_set;
   }
   Else
  {
 $category_name .= ', '. get(Category_Name) from $result_set;
}

//  do as you will with $product_name  $category_name

Next loop iteration

IMO, this is way faster to implement than trying to figure out all that SP
stuff since we're not DBAs ;) .  As for overall performance, I don't know if
this is faster than SP.  You'll just have to analyze your data size and what
kind of traffic you're getting vs. hardware(s) you have to see if it's worth
the time to learn how to write SP.  Just an FYI, once you get into complex
situations, SP have higher security and generally have better performance
than just standard queries.

Regards,
Tommy


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



Re: [PHP] Static Class Member References

2010-07-12 Thread Daniel Kolbo
Richard Quadling wrote:
 On 11 July 2010 23:19, Daniel Kolbo kolb0...@umn.edu wrote:
 Hello PHPers,

 I'm having some trouble understanding some PHP behaviour.  The following
 example script exhibits the behaviour which I cannot understand.
 [code]
 ?php

 class A
 {
public static $a = 3;

function __construct()
{
//self::$a = $this; //[i]
self::$a = $this; //[ii]
}
 }

 class B extends  A
 {
function __construct()
{
parent::__construct();
}
 }

 class C {
var $c;

function __construct()
{
$this-c = A::$a;
}

 }


 $c = new C;
 $b = new B;
 $cee = new C;

 var_dump($c-c); // [i] prints object(B), but [ii] prints int 3
 var_dump($cee-c); // [i] prints object(B), and [ii] prints object(B)

 ?
 [/code]

 Why does $c-c print 'int 3' ?

 I'm nervous to use self::$a = $this; because I don't want to be
 copying the whole object.  However, isn't $this just a reference to the
 object, so self::$a = $this; is just copying the reference and not the
 actual object, right?

 Thanks in advance
 
 
 What do you think the value should be?
 
 A static property is bound to the class and not to an instance of the class.
 
 So, A::$a is a reference to the static value. If you alter the value,
 it will be altered for a subclasses of A and for any other reference
 to it.
 

I think
var_dump($c-c); would print object(B), but it's printing int 3.

The reference is *not* being updated.  I think this is a bug.  What do
you think?

Thanks
`


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



Re: [PHP] Looking for a little MySQL help as well

2010-07-12 Thread Jim Lucas
Phillip Baker wrote:
 Thanks Jim,
 
 This outputs 2 results.
 Is there a way to get the one result set per product regardless of the
 number of categories associated with the product, yet displaying all the
 categories associated with said prodcut?

Run this:

SELECT
  p.Product_Name,
  GROUP_CONCAT(c.Category_Name SEPARATOR ', ') AS Category_Names
FROM
  p2c_map AS pc
INNER JOIN
  products AS p ON p.Product_ID = pc.Product_ID
INNER JOIN
  categories AS c ON FIND_IN_SET(c.Category_ID, pc.Category_ID)  0
GROUP BY
  pc.Product_ID

When I run this in phpMyAdmin it gives me a blob result, but when you run it
from the CLI it will return the correct thing.

 
 Blessed Be
 
 Phillip
 
 If you try to protect idiots from themselves, even if you succeed, you just
 wind up filling the world with idiots.
- - Doug Casey
 
 
 On Mon, Jul 12, 2010 at 12:21 PM, Jim Lucas li...@cmsws.com wrote:
 
 Phillip Baker wrote:
 Hey All,

 I am looking for a little MySQL Query help as well.
 I am not getting any response form the MySQl Email list to my query.
 And knowing there are some SQL wizards on this list I thought I would as
 for
 help as well.

 I have one table with products that many have one or more categories.
 I am using an index table and am having trouble getting a proper result
 set.
 Table 1
 Product_id  |  Product_Name
 1|  Product A
 2|  Product B
 3|  Product C

 Table 2
 Category_id  |  Category_Name
 1 |   Admin
 2 |   Marketing
 3 |   Support
 4 |   IT


 Table 3
 Product_id  |  Category_id
 1|  1
 1|  3
 2|  2
 3|  3
 3|  4

 Result would look like
 Product A, Admin, Support
 Product B, Marketing
 Product C, Support, IT

 I believe this is a one to many using an index table?
 I appreciate any help.
 Thanks.

 Blessed Be

 Phillip

 If you try to protect idiots from themselves, even if you succeed, you
 just
 wind up filling the world with idiots.
- - Doug Casey


 SELECT
  products.Product_Name,
  categories.Category_Name
 FROM
  products,
  categories,
  p2c_map
 WHERE
  products.Product_ID = p2c_map.Product_ID
 AND
  categories.Category_ID = p2c_map.Category_ID

 Gives the results that you are looking for.  Once you get the data, you
 must
 concat things your self, but it is everything that you are looking for.

 To search for Categories of a given product, you would add this to the
 WHERE section

 AND
  products.Product_Name = 'Product A'

 of, if you were looking for all the products in a given category, you would
 add this

 AND
  categories.Category_Name = 'Category 1'


 The following is the table structure that I am using with mock data.

 CREATE TABLE IF NOT EXISTS `categories` (
  `Category_ID` int(11) NOT NULL auto_increment,
  `Category_Name` varchar(16) collate latin1_bin NOT NULL,
  PRIMARY KEY  (`Category_ID`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=5
 ;

 INSERT INTO `categories` (`Category_ID`, `Category_Name`) VALUES
 (1, 'Category 1'),(2, 'Category 2'),(3, 'Category 3'),(4, 'Category 4');

 CREATE TABLE IF NOT EXISTS `p2c_map` (
  `Product_id` int(11) NOT NULL,
  `Category_ID` int(11) NOT NULL,
  PRIMARY KEY  (`Product_id`,`Category_ID`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin;

 INSERT INTO `p2c_map` (`Product_id`, `Category_ID`) VALUES
 (1, 1),(1, 2),(1, 4),(2, 2),(2, 3),(3, 4),(4, 1),(4, 4);

 CREATE TABLE IF NOT EXISTS `products` (
  `Product_ID` int(11) NOT NULL auto_increment,
  `Product_Name` varchar(16) collate latin1_bin NOT NULL,
  PRIMARY KEY  (`Product_ID`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=5
 ;

 INSERT INTO `products` (`Product_ID`, `Product_Name`) VALUES
 (1, 'Product A'),(2, 'Product B'),(3, 'Product C'),(4, 'Product D');

 --
 Jim Lucas

 A: Maybe because some people are too annoyed by top-posting.
 Q: Why do I not get an answer to my question(s)?
 A: Because it messes up the order in which people normally read text.
 Q: Why is top-posting such a bad thing?

 


-- 
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

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



RE: [PHP] Serial Numbers

2010-07-12 Thread Daevid Vincent
 -Original Message-
 From: Gary [mailto:gp...@paulgdesigns.com] 
 Sent: Monday, July 12, 2010 11:53 AM
 
 I'm sure it is possible, but I am unsure how to do this.  I 
 have created a 
 Sale coupon that I was going to put up on a site that I 
 manage, for visitors 
 to print out and bring to the store. The coupon is currently 
 a .png, however 
 I was planning on converting to a pdf.  I would like to put 
 on the coupon a 
 serial number that increases by 1 everytime the page is 
 viewed. I dont 
 really care if someone refreshes the page and skews the numbers.
 
 Is this possible and could someone give me some help?

Is there a reason you need to increment by 1? I mean, are you going to
validate the coupon someone brings in to see if it's in the database or is
used already? Since you say you don't care if the number is skewed, it
sounds as if you don't care about the code either really.

Point being, why not just use md5(time()) or uniqid() or something and make
some truly unique code (that you may or may not wish to store in a DB).
This will be obscure enough the average person won't know that it isn't
tracked and most likely won't try to make their own. If I saw 123457, I'm
pretty sure I could make a coupon with 123500 on it. But if I saw
6ccd780c-baba-1026-9564-0040f4311e29 then I'm not really going to try and
fudge one of those. Then I'd use the barcode library to print the code
(again, doesn't have to actually work if you're not going to do a lookup)
just to add more realizm to it. There are a billion different ways to
make a unique ID. Even IF you are going to track them, you really shouldn't
do a sequential code as you originally wanted to do.

http://us.php.net/manual/en/function.uniqid.php
http://php.net/manual/en/function.com-create-guid.php
http://us.php.net/manual/en/function.mssql-guid-string.php
http://us.php.net/manual/en/function.md5.php
http://us.php.net/manual/en/function.sha1.php
http://us.php.net/manual/en/function.hash.php
http://us.php.net/manual/en/function.time.php
http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#functio
n_uuid

Heck, you could even just use ip2long() on their IP address and then when
someone redeems the coupon code, a simple long2ip() would tell you if
it's a valid IP format rather than some hacked up string.
http://us.php.net/manual/en/function.ip2long.php
http://us.php.net/manual/en/function.long2ip.php

Daevid.
http://daevid.com

Some people, when confronted with a problem, think 'I know, I'll use
XML.'
Now they have two problems. 


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



Re: [PHP] Login using just cookies, bad idea?

2010-07-12 Thread Stuart Dallas

On 08/07/10 17:53, Michael Calkins wrote:


I right now have a complete user login and registration system
however it uses cookies when you login to store information.  Is this
a bad thing?$_COOKIE vs $_SESSION for login systems


Encrypt the cookie, make sure you don't store the password in there, 
make sure it's salted, and validate the contents before using them.


http://stut.net/2008/07/26/sessionless-sessions-2/

-Stuart

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



Re: [PHP] Serial Numbers

2010-07-12 Thread Gary

Daevid Vincent dae...@daevid.com wrote in message 
news:a380a1570d4c4351b38e1cce2aabe...@mascorp.com...
 -Original Message-
 From: Gary [mailto:gp...@paulgdesigns.com]
 Sent: Monday, July 12, 2010 11:53 AM

 I'm sure it is possible, but I am unsure how to do this.  I
 have created a
 Sale coupon that I was going to put up on a site that I
 manage, for visitors
 to print out and bring to the store. The coupon is currently
 a .png, however
 I was planning on converting to a pdf.  I would like to put
 on the coupon a
 serial number that increases by 1 everytime the page is
 viewed. I dont
 really care if someone refreshes the page and skews the numbers.

 Is this possible and could someone give me some help?

 Is there a reason you need to increment by 1? I mean, are you going to
 validate the coupon someone brings in to see if it's in the database or is
 used already? Since you say you don't care if the number is skewed, it
 sounds as if you don't care about the code either really.

 Point being, why not just use md5(time()) or uniqid() or something and 
 make
 some truly unique code (that you may or may not wish to store in a DB).
 This will be obscure enough the average person won't know that it isn't
 tracked and most likely won't try to make their own. If I saw 123457, I'm
 pretty sure I could make a coupon with 123500 on it. But if I saw
 6ccd780c-baba-1026-9564-0040f4311e29 then I'm not really going to try and
 fudge one of those. Then I'd use the barcode library to print the code
 (again, doesn't have to actually work if you're not going to do a lookup)
 just to add more realizm to it. There are a billion different ways to
 make a unique ID. Even IF you are going to track them, you really 
 shouldn't
 do a sequential code as you originally wanted to do.

 http://us.php.net/manual/en/function.uniqid.php
 http://php.net/manual/en/function.com-create-guid.php
 http://us.php.net/manual/en/function.mssql-guid-string.php
 http://us.php.net/manual/en/function.md5.php
 http://us.php.net/manual/en/function.sha1.php
 http://us.php.net/manual/en/function.hash.php
 http://us.php.net/manual/en/function.time.php
 http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#functio
 n_uuid

 Heck, you could even just use ip2long() on their IP address and then when
 someone redeems the coupon code, a simple long2ip() would tell you if
 it's a valid IP format rather than some hacked up string.
 http://us.php.net/manual/en/function.ip2long.php
 http://us.php.net/manual/en/function.long2ip.php

 Daevid.
 http://daevid.com

 Some people, when confronted with a problem, think 'I know, I'll use
 XML.'
 Now they have two problems.

Daevid

Thanks for your reply.

The numbers are not for show, we are not trying to make it seem like we have 
thousands of coupons.  We are going to use the numbers to guage how many 
times people see the coupon and to see how many it takes before we have 
someone show up to use it, but dont really care if someone gets a kick out 
of hitting the refresh button 10 or 20 times to watch the number go up.

I was going to start the number at 72010001 (July 2010, 001) and if someone 
figured out what it was, we dont really care. As I mentioned, it is a small 
shop (one man show) that the site gets and average of 350 visits per month 
(which he is very happy with over what he had).

Although I do like the idea of using there ip address...

Thanks for your reply and all the links.

Gary




__ Information from ESET Smart Security, version of virus signature 
database 5273 (20100712) __

The message was checked by ESET Smart Security.

http://www.eset.com





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



Re: [PHP] Looking for a little MySQL help as well

2010-07-12 Thread Jim Lucas
Jim Lucas wrote:
 Phillip Baker wrote:
 Thanks Jim,

 This outputs 2 results.
 Is there a way to get the one result set per product regardless of the
 number of categories associated with the product, yet displaying all the
 categories associated with said prodcut?
 
 Run this:
 
 SELECT
   p.Product_Name,
   GROUP_CONCAT(c.Category_Name SEPARATOR ', ') AS Category_Names
 FROM
   p2c_map AS pc
 INNER JOIN
   products AS p ON p.Product_ID = pc.Product_ID
 INNER JOIN
   categories AS c ON FIND_IN_SET(c.Category_ID, pc.Category_ID)  0
 GROUP BY
   pc.Product_ID
 
 When I run this in phpMyAdmin it gives me a blob result, but when you run it
 from the CLI it will return the correct thing.

Forgot to give create where credit is due.  I found an example of this method
here and munged it to make it work with the example table structure and data
examples.

http://www.tek-tips.com/viewthread.cfm?qid=1541787page=15

And I looked here for usage of MySQLs GROUP_CONCAT()

http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html#function_group-concat

Enjoy,

Jim

 
 Blessed Be

 Phillip

 If you try to protect idiots from themselves, even if you succeed, you just
 wind up filling the world with idiots.
- - Doug Casey


 On Mon, Jul 12, 2010 at 12:21 PM, Jim Lucas li...@cmsws.com wrote:

 Phillip Baker wrote:
 Hey All,

 I am looking for a little MySQL Query help as well.
 I am not getting any response form the MySQl Email list to my query.
 And knowing there are some SQL wizards on this list I thought I would as
 for
 help as well.

 I have one table with products that many have one or more categories.
 I am using an index table and am having trouble getting a proper result
 set.
 Table 1
 Product_id  |  Product_Name
 1|  Product A
 2|  Product B
 3|  Product C

 Table 2
 Category_id  |  Category_Name
 1 |   Admin
 2 |   Marketing
 3 |   Support
 4 |   IT


 Table 3
 Product_id  |  Category_id
 1|  1
 1|  3
 2|  2
 3|  3
 3|  4

 Result would look like
 Product A, Admin, Support
 Product B, Marketing
 Product C, Support, IT

 I believe this is a one to many using an index table?
 I appreciate any help.
 Thanks.

 Blessed Be

 Phillip

 If you try to protect idiots from themselves, even if you succeed, you
 just
 wind up filling the world with idiots.
- - Doug Casey

 SELECT
  products.Product_Name,
  categories.Category_Name
 FROM
  products,
  categories,
  p2c_map
 WHERE
  products.Product_ID = p2c_map.Product_ID
 AND
  categories.Category_ID = p2c_map.Category_ID

 Gives the results that you are looking for.  Once you get the data, you
 must
 concat things your self, but it is everything that you are looking for.

 To search for Categories of a given product, you would add this to the
 WHERE section

 AND
  products.Product_Name = 'Product A'

 of, if you were looking for all the products in a given category, you would
 add this

 AND
  categories.Category_Name = 'Category 1'


 The following is the table structure that I am using with mock data.

 CREATE TABLE IF NOT EXISTS `categories` (
  `Category_ID` int(11) NOT NULL auto_increment,
  `Category_Name` varchar(16) collate latin1_bin NOT NULL,
  PRIMARY KEY  (`Category_ID`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=5
 ;

 INSERT INTO `categories` (`Category_ID`, `Category_Name`) VALUES
 (1, 'Category 1'),(2, 'Category 2'),(3, 'Category 3'),(4, 'Category 4');

 CREATE TABLE IF NOT EXISTS `p2c_map` (
  `Product_id` int(11) NOT NULL,
  `Category_ID` int(11) NOT NULL,
  PRIMARY KEY  (`Product_id`,`Category_ID`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin;

 INSERT INTO `p2c_map` (`Product_id`, `Category_ID`) VALUES
 (1, 1),(1, 2),(1, 4),(2, 2),(2, 3),(3, 4),(4, 1),(4, 4);

 CREATE TABLE IF NOT EXISTS `products` (
  `Product_ID` int(11) NOT NULL auto_increment,
  `Product_Name` varchar(16) collate latin1_bin NOT NULL,
  PRIMARY KEY  (`Product_ID`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=5
 ;

 INSERT INTO `products` (`Product_ID`, `Product_Name`) VALUES
 (1, 'Product A'),(2, 'Product B'),(3, 'Product C'),(4, 'Product D');

 --
 Jim Lucas

 A: Maybe because some people are too annoyed by top-posting.
 Q: Why do I not get an answer to my question(s)?
 A: Because it messes up the order in which people normally read text.
 Q: Why is top-posting such a bad thing?

 
 


-- 
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

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



RE: [PHP] Looking for a little MySQL help as well

2010-07-12 Thread Tommy Pham
 -Original Message-
 From: Jim Lucas [mailto:li...@cmsws.com]
 Sent: Monday, July 12, 2010 3:51 PM
 To: Phillip Baker
 Cc: PHP General List
 Subject: Re: [PHP] Looking for a little MySQL help as well
 
 Jim Lucas wrote:
  Phillip Baker wrote:
  Thanks Jim,
 
  This outputs 2 results.
  Is there a way to get the one result set per product regardless of
  the number of categories associated with the product, yet displaying
  all the categories associated with said prodcut?
 
  Run this:
 
  SELECT
p.Product_Name,
GROUP_CONCAT(c.Category_Name SEPARATOR ', ') AS Category_Names
 FROM
p2c_map AS pc
  INNER JOIN
products AS p ON p.Product_ID = pc.Product_ID INNER JOIN
categories AS c ON FIND_IN_SET(c.Category_ID, pc.Category_ID)  0
  GROUP BY
pc.Product_ID
 
  When I run this in phpMyAdmin it gives me a blob result, but when you
  run it from the CLI it will return the correct thing.
 
 Forgot to give create where credit is due.  I found an example of this
method
 here and munged it to make it work with the example table structure and
 data examples.
 
 http://www.tek-tips.com/viewthread.cfm?qid=1541787page=15
 
 And I looked here for usage of MySQLs GROUP_CONCAT()
 
 http://dev.mysql.com/doc/refman/5.1/en/group-by-
 functions.html#function_group-concat
 
 Enjoy,
 
 Jim
 

snip

Interesting links, Jim.  Thanks.  Phillip, just an FYI, GROUP_CONCAT() is
non ANSI-SQL compliant.  If you intend to migrate to another DBMS in the
near future, you'll have to find another way to make it work as this
built-in function is MySQL only.

Regards,
Tommy


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



Re: [PHP] Serial Numbers

2010-07-12 Thread Paul M Foster
On Mon, Jul 12, 2010 at 02:52:39PM -0400, Gary wrote:

 I'm sure it is possible, but I am unsure how to do this.  I have created a
 Sale coupon that I was going to put up on a site that I manage, for visitors
 to print out and bring to the store. The coupon is currently a .png, however
 I was planning on converting to a pdf.  I would like to put on the coupon a
 serial number that increases by 1 everytime the page is viewed. I dont
 really care if someone refreshes the page and skews the numbers.
 
 Is this possible and could someone give me some help?

Doing this in a PDF is pretty easy. Check out the FPDF library. It's
pretty lightweight. I print invoices to PDF all the time, so I have to
insert numbers into PDFs created by FPDF. Check the documentation.

Paul

-- 
Paul M. Foster

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