Re: [PHP] Retrieving function values

2010-11-15 Thread Richard Quadling
On 15 November 2010 03:12, Ron Piggott ron.pigg...@actsministries.org wrote:
 I am writing a custom function and I need to be able to retrieve 3 values 
 from it.

 string_parse_tool ( $string_to_parse )

 The 3 variables I need to retrieve from the function are:

 $string_to_parse
 $string_to_display
 $continue_parsing

 I only know how to retrieve 1 variable from a function, not 3.  Could someone 
 help me please?

 Thank you.

 Ron

Beside the array() return you could ...

function string_parse_tool($string_source, $string_to_parse,
$string_to_display, $continue_parsing) {
}

Now you can use ...
string_parse_tool($string_source, $string_to_parse,
$string_to_display, $continue_parsing);

Depending upon your code, you could drop the first parameter
completely, but that would always overwrite the supplied value with
the return value.
-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



[PHP] Switch Question...

2010-11-15 Thread Steve Staples
Ok, dumb question, and i have tested, but I want to ensure that my tests
were accurate, and behavior is correct.

Ok, i have an integer, that based on what it is, does certain things...

switch ((int)$intval)
{
}

now, if i need to do something on a few of the numbers, then:
case 0:
# do nothing as strings will be (int) as 0
break;
case 1:
# do this
break;
case 12:
# do this
break;
default:
# do everything that is general to this

which this works, as the $intval should never be anything that i am not
expecting as there is another part of the code that decides which int's
to send to this class.

but is there a better way to do this?   this could potentially do a lot
more, and be more dynamic, but there is also the possibilty that i need
to have more custom commands based on an integer value, and not
something that is generic.

Is there a way to only do from like cases 2-11, without doing:
case 2:
case 3:
case 4:
.
case 11:
# do this stuff
break;


am I just overthinking things?  i dunno... it's monday...  brains still
on weekend mode.

Steve


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



Re: [PHP] Switch Question...

2010-11-15 Thread Ashley Sheridan
On Mon, 2010-11-15 at 16:27 -0500, Steve Staples wrote:

 Ok, dumb question, and i have tested, but I want to ensure that my tests
 were accurate, and behavior is correct.
 
 Ok, i have an integer, that based on what it is, does certain things...
 
 switch ((int)$intval)
 {
 }
 
 now, if i need to do something on a few of the numbers, then:
   case 0:
   # do nothing as strings will be (int) as 0
   break;
   case 1:
   # do this
   break;
   case 12:
   # do this
   break;
   default:
   # do everything that is general to this
 
 which this works, as the $intval should never be anything that i am not
 expecting as there is another part of the code that decides which int's
 to send to this class.
 
 but is there a better way to do this?   this could potentially do a lot
 more, and be more dynamic, but there is also the possibilty that i need
 to have more custom commands based on an integer value, and not
 something that is generic.
 
 Is there a way to only do from like cases 2-11, without doing:
   case 2:
   case 3:
   case 4:
   .
   case 11:
   # do this stuff
   break;
 
 
 am I just overthinking things?  i dunno... it's monday...  brains still
 on weekend mode.
 
 Steve
 
 


There is actually a very cool way you can use a switch in PHP to do what
you want:

switch(true)
{
case ($intval = 2  $intval = 11):
{
// stuff here for cases 2-11 inclusive
break;
}
}

Although I think in your case a series of if/else if statements would
work, and might possibly be more readable in your code.

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




Re: [PHP] Switch Question...

2010-11-15 Thread Steve Staples
On Mon, 2010-11-15 at 22:43 +, Ashley Sheridan wrote:
 On Mon, 2010-11-15 at 16:27 -0500, Steve Staples wrote:
 
  Ok, dumb question, and i have tested, but I want to ensure that my tests
  were accurate, and behavior is correct.
  
  Ok, i have an integer, that based on what it is, does certain things...
  
  switch ((int)$intval)
  {
  }
  
  now, if i need to do something on a few of the numbers, then:
  case 0:
  # do nothing as strings will be (int) as 0
  break;
  case 1:
  # do this
  break;
  case 12:
  # do this
  break;
  default:
  # do everything that is general to this
  
  which this works, as the $intval should never be anything that i am not
  expecting as there is another part of the code that decides which int's
  to send to this class.
  
  but is there a better way to do this?   this could potentially do a lot
  more, and be more dynamic, but there is also the possibilty that i need
  to have more custom commands based on an integer value, and not
  something that is generic.
  
  Is there a way to only do from like cases 2-11, without doing:
  case 2:
  case 3:
  case 4:
  .
  case 11:
  # do this stuff
  break;
  
  
  am I just overthinking things?  i dunno... it's monday...  brains still
  on weekend mode.
  
  Steve
  
  
 
 
 There is actually a very cool way you can use a switch in PHP to do what
 you want:
 
 switch(true)
 {
 case ($intval = 2  $intval = 11):
 {
 // stuff here for cases 2-11 inclusive
 break;
 }
 }
 
 Although I think in your case a series of if/else if statements would
 work, and might possibly be more readable in your code.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 

yeah, totally forgot about putting logic into the case... yep... still
monday here...

thanks ash!


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



RE: [PHP] PHP loop to issue sql insert

2010-11-15 Thread admin
Example:

$simple = select count(*) as count, searchkeywords from searchtable group
by searchkeywords order by count desc;
$stuff = mysql_query($simple);

If(mysql_num_rows($stuff) = 1)
{
While($toarray = mysql_fetch_assoc($stuff))
{
$doit = mysql_query(INSERT INTO mytable (count, color) values
('$toarray[count]', '$toarray[searchkeywords]'));
Echo mysql_error();
}
}


I am not sure why, don't care. Here is a very simple pull from this table
insert into this table with the looped data.


Richard L. Buskirk







-Original Message-
From: Simon J Welsh [mailto:si...@welsh.co.nz] 
Sent: Sunday, November 14, 2010 8:16 PM
To: Rick Dwyer
Cc: php-general@lists.php.net
Subject: Re: [PHP] PHP loop to issue sql insert

On 15/11/2010, at 12:47 PM, Rick Dwyer wrote:

 Hello List.
 
 I have a sql command that counts, groups and sorts data from a table.  I
need to insert the results of that sql command into different table.
 
 My sql SELECT looks like  this:
 
 select count(*) as count, searchkeywords from searchtable group by
searchkeywords order by count desc;
 
 and returns records like this:
 
 578   green
 254   blue
 253   red
 253   yellow
 118   orange
  etc.
 
 My PHP looks like this so far:
 
 $sql = select count(*) as count, searchkeywords from searchtable group by
searchkeywords order by count desc;
 $result = @mysql_query($sql,$connection) or die(Couldn't execute checkcat
query);
 $num = mysql_num_rows($result);
 echo $num;
 
 
 The echo is of course returning the total number of records not data
as listed above.
 
 I know a WHILE statement is to be used here, but can't get it to work.
 
 How do I loop through the above found data, inserting each value as like
this:
 
 insert into mytable (count, color) values (578, green);
 insert into mytable (count, color) values (254, blue);
 ...etc
 
 
 
 Thanks,
 
 
 --Rick

Personally I'll get MySQL to do it for me using: insert into mytable (count,
color) select count(*) as count, searchkeywords from searchtable group by
searchkeywords order by count desc (see
http://dev.mysql.com/doc/refman/5.1/en/insert-select.html for more
information on INSERT ... SELECT)

Otherwise, you'll want to use mysql_fetch_assoc($result). Examples and
information can be found at http://php.net/mysql_fetch_assoc
---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never,
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e

-- 
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



[PHP] Is it possible to install PHP on IIS?

2010-11-15 Thread Himani Aggarwal
Hi Folks, is it possible to install PHP on IIS? If yes, can someone please
guide me on how to go about doing it? Thanks


Re: [PHP] Is it possible to install PHP on IIS?

2010-11-15 Thread Aman Singh
Himani,
See
http://blogs.iis.net/bills/archive/2006/09/19/how-to-install-php-on-iis7-_2800_rc1_2900_.aspx?WT.mc_id=soc-c-in-loc--cfp.
Also, see
http://blogs.iis.net/donraman/archive/2009/10/07/installing-php-on-windows.aspx?WT.mc_id=soc-c-in-loc--cfp

On Tue, Nov 16, 2010 at 12:16 PM, Himani Aggarwal 
incrediblehim...@gmail.com wrote:

 Hi Folks, is it possible to install PHP on IIS? If yes, can someone please
 guide me on how to go about doing it? Thanks