RE: Globals or Super Global Variables To Be Reused from For Loops

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

 



Hi, 


  Sorry, I cannot use that because I am supposed to turn the string into something that looks like regions.name LIKE '%47406' OR regions.name LIKE '%Detroit', which I had to fix $string3 variable to   

  $string3="regions.name LIKE '%" . $stringChunk2[$j] . "'";

  The goal is that the $message variable would be only a $_POST['message'] variable so that the where clause can be generated dynamically. 
  The code I have above is part of my where clause in the full SQL statement I intend to
construct, which means I have to reuse this $string3 variable somewhere
else.
  
This is what my global declaration looks like: 

  if ($j <$count_chunk_2) {

         $string2= " OR ";
         $string3=$string3.$string2;
         global $string3;
   }
     else {
         //Don't do anything
   }
       echo $string3;
  }
    echo $string3;

   The last $string3 echo only gives me regions.name
LIKE '%Detroit' according to the current construct and not regions.name
LIKE '%47406' OR regions.name LIKE '%Detroit'. Is there something else I should do to have it give me the same output as the echo $string3 as I have had after the second to last curly brace? 

Thanks again for your help.

Alice


> Date: Thu, 6 Nov 2008 10:22:44 -0500
> From: phpster@xxxxxxxxx
> To: ajwei@xxxxxxxxxxxxx
> CC: php-general@xxxxxxxxxxxxx
> Subject: Re:  Globals or Super Global Variables To Be Reused from For Loops
> 
> [snip]
> [/snip]
> 
> Alice,
> 
> The big problem here is that you are resetting the $string3 variable in the
> loop
> 
>   for ($j=0; $j<$count_chunk2; $j++) {
> 
>          $string3= $stringChunk2[$j];                //  <<<------ resetting
> the value
>      if ($j <$count_chunk_2) {
>         $string2= " OR ";
>         $string3=$string3.$string2;
>   }
>     else {
>         //Don't do anything
>   }
>       echo $string3;
>  }
> 
> 
> I am not sure of your goal since you have not stated it, but it certainly
> should be easier to just replace the PIPE  with the OR
> 
> $message = str_replace("|", " OR ", $message);
> 
> 
> 
> -- 
> 
> Bastien
> 
> Cat, the other other white meat

_________________________________________________________________
Express yourself with gadgets on Windows Live Spaces
http://discoverspaces.live.com?source=hmtag1&loc=us

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux