Switches come in handy here...

Switch($valueChk)
{
  case 1:
    do_whatever1();
  case 2:
    do_whatever2();
  case 3:
    do_whatever3();
    break;
}

If the variable is 1, then all three functions will be called. 

I don't remember what the original question was or if this even applies,
but it's a better solution than all of the IFs that was just posted...

---John Holmes...

> -----Original Message-----
> From: Naintara Jain [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 04, 2002 5:47 PM
> To: Ricardo Fitzgerald
> Cc: Php-General@Lists. Php. Net
> Subject: FW: [PHP] Logic -- conditional statements
> 
> One correction, Ricardo
> 
> for appending the rows, you will have to change the condition
> 
> //for 1st row
> if($valueChk >= 1 && $valueChk <= 3)
> 
> //for 2nd row
> if($valueChk >= 2 && $valueChk <= 3)
> 
> //for 3rd row
> if($valueChk == 3)
> 
> 
> 
> -----Original Message-----
> From:
[EMAIL PROTECTED]
>
[mailto:[EMAIL PROTECTED]
> t]On Behalf Of Naintara Jain
> Sent: Tuesday, June 04, 2002 2:37 PM
> To: Ricardo Fitzgerald; [EMAIL PROTECTED]
> Subject: RE: [PHP] Logic -- conditional statements
> 
> 
> The problem here is that you have defined three different variables
> $value1,$value2,$value3.
> 
> Keep only one variable (say,$valueChk) that can take values 1,2 or 3.
> Then check for the condition.
> And there's another mistake in the script, you are checking
> ---if ($value2 ==0)---
> twice, you probably mean to check for "$value1 ==1" (for the first of
the
> "$value2 ==0" checks).
> 
> Once you are through with these changes, your script will work
perfectly.
> And if you feel like improving it you need not repeat the <td>
statements.
> You can merely append the additional rows depending on the value of
the
> variable you set (say, $valueChk).
> 
> the following isn't the actual script, but mainly the logic.
> 
> $table="<table>"
> if($valueChk==0)
> exit
> if($valueChk==1)
> {
> //.....append the first <TR><TD> statement to $table variable
> $table .= "<TR><TD> ";
> 
> }
> 
> if($valueChk==2)
> {
> //.....append the second <TR><TD> statement to $table variable
> }
> 
> if($valueChk==3)
> {
> //.....append the third <TR><TD> statement to $table variable
> }
> 
> //now close the table tag and echo the $table variable
> 
> you'll get the table with the desired number of rows.
> 
> -Naintara
> 
> -----Original Message-----
> From:
[EMAIL PROTECTED]
>
[mailto:[EMAIL PROTECTED]
> t]On Behalf Of Ricardo Fitzgerald
> Sent: Friday, July 10, 2893 3:44 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Logic -- conditional statements
> 
> 
> Hi to all,
> 
> I'm trying to echo a neat table with values from a form, depending on
> the values it echoes a table with one row with two or with three:
> Then I have conditional nested statements, to validate these variables
> and wrote the table with the proper values in each case, the problem
> is the table is displayed 3 times instead of 1 each time it finds a
> value TRUE!
> 
> I need it to display only once, I mean in the first instance the
> table, has 1 row, the second 2 rows, the third 3 rows, and they are
> independent.
> 
> The code is something like:
> //Value1 is always 1
> if ($value1 == 0)
> {
> exit
> }
> if ($value2 ==0)
> {
> echo // echoes the table
> .
> .
> ."<td ... >$variable1 ...
> ."<td ... >$variable2...
> ."<td ... >$variable3 ...
> ."<td ... >$variable4 ...
> 
> }
> if($value2 == 0)
> {
> 
> .
> .
> echo // echoes the table
> .
> .
> ."<td ... >$variable1 ...
> ."<td ... >$variable2...
> ."<td ... >$variable3 ...
> ."<td ... >$variable4 ...
> 
> ."<tr>  /next row
> .
> ."<td ... >$variable5 ...
> ."<td ... >$variable6...
> ."<td ... >$variable7 ...
> ."<td ... >$variable8 ...
> ."</tr>
> .
> .
> }
> if($value3 == 3)
> {
> 
> .
> .
> echo // echoes the table
> .
> .
> ."<td ... >$variable1 ...
> ."<td ... >$variable2...
> ."<td ... >$variable3 ...
> ."<td ... >$variable4 ...
> 
> ."<tr>  /next row
> .
> ."<td ... >$variable5 ...
> ."<td ... >$variable6...
> ."<td ... >$variable7 ...
> ."<td ... >$variable8 ...
> ."</tr>
> .
> .
> ."<td ... >$variable9 ...
> ."<td ... >$variable10...
> ."<td ... >$variable11 ...
> ."<td ... >$variable12 ...
> ."</tr>
> .
> .
> //and then closes the php script,
> 
> TIA
> 
> Regards,
> 
> Rick
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002
> 
> 
> --
> 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

Reply via email to