php condition in a tabel with html and php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elia

    php condition in a tabel with html and php

    Hello,

    I would like to show a line in a tabel in html if there is quantity of
    article choosed.

    My code is:

    <? if ($quantite1 0) {
    echo('
    <tr>
    <td align="left" nowrap="nowrap" >Article 1</td>
    <td align="center"> <? echo $quantite1 ?</td>
    <td align="center"> 20 &euro;</td>
    <td align="center"< ? echo $montant1 ?&euro;</td>
    </tr>');
    }
    else{
    echo("");
    }
    ?>

    If there is no article >no line
    If there is article >show the line

    Problem: I can have the variable $quantite1 and $montant1 en php

  • Sandman

    #2
    Re: php condition in a tabel with html and php

    In article <1160384144.408 791.288410@m73g 2000cwd.googleg roups.com>,
    "elia" <joseph@pcl.chw rote:
    Hello,
    >
    I would like to show a line in a tabel in html if there is quantity of
    article choosed.
    >
    My code is:
    >
    <? if ($quantite1 0) {
    echo('
    <tr>
    <td align="left" nowrap="nowrap" >Article 1</td>
    <td align="center"> <? echo $quantite1 ?</td>
    <td align="center"> 20 &euro;</td>
    <td align="center"< ? echo $montant1 ?&euro;</td>
    </tr>');
    }
    else{
    echo("");
    }
    ?>
    >
    If there is no article >no line
    If there is article >show the line
    >
    Problem: I can have the variable $quantite1 and $montant1 en php
    You can't break into php code inside a echo.

    Try:

    echo "<td$montan t1 </td>";

    And not:

    echo('<td<? echo $montant1 ?</td>');
    ^ ^
    1 2


    1. Using ' means that variables won't be parsed, but printed.
    2. <? ... ?is for the parsing engine, not to be used within PHP code.

    --
    Sandman[.net]

    Comment

    • elia

      #3
      Re: php condition in a tabel with html and php

      Thanks, but so it's my problem! If I write ...

      <? if ($quantite1 0) {
      echo('
      <tr>
      <td article1 </td>
      <td $quantite1</td>
      <td 20 &euro;</td>
      <td $montant1 &euro;</td>
      </tr>');
      }
      else{
      echo("");
      }
      ?>

      ...."$quantite1 " and "$montant1" is not take as variable php.
      Until "4" ou "7" or "10" it's write "$quantite1 "
      Pascal

      Comment

      • Peter Fox

        #4
        Re: php condition in a tabel with html and php

        Following on from elia's message. . .
        >Hello,
        >
        >I would like to show a line in a tabel in html if there is quantity of
        >article choosed.
        >
        >My code is:
        broken.


        * use _double_ quotes to get $-variables rendered.
        * to escape double quotes use \"
        * nowrap html syntax!
        * print() is same as echo()
        * Euro combined with montant
        * I've modified your table format to remove redundant and space
        consuming bits.


        // print column headings before loop
        print("<tr><th> Article</th><th>Montant</th></tr>\n");


        // inside the loop
        if ($quantite1 0) { // ignore if no quantity
        // tidy up montant for pretty printing
        if(!$montant==0 ){ // assuming $montant is numeric
        $m = sprintf('&euro; %6.2f",$montant ); // to nice currency string
        }else{
        $m='';
        }
        print("<tr>
        <td align=\"center\ ">$quantite 1</td>
        <td align=\"right\" >$m</td>
        </tr>");
        }


        --
        PETER FOX Not the same since the e-commerce business came to a .
        peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
        2 Tees Close, Witham, Essex.
        Gravity beer in Essex <http://www.eminent.dem on.co.uk>

        Comment

        • Sandman

          #5
          Re: php condition in a tabel with html and php

          In article <1160385826.277 060.94330@c28g2 000cwb.googlegr oups.com>,
          "elia" <joseph@pcl.chw rote:
          Thanks, but so it's my problem! If I write ...
          >
          <? if ($quantite1 0) {
          echo('
          <tr>
          <td article1 </td>
          <td $quantite1</td>
          <td 20 &euro;</td>
          <td $montant1 &euro;</td>
          </tr>');
          }
          else{
          echo("");
          }
          ?>
          >
          ..."$quantite1 " and "$montant1" is not take as variable php.
          Until "4" ou "7" or "10" it's write "$quantite1 "
          Pascal
          Read my reply again. If you use

          echo('$foobar') ;

          it till print a dollar sign and then foobar. If you use

          echo("$foobar") ;

          it will print the content of the variable $foobar. Not the difference.


          --
          Sandman[.net]

          Comment

          • Pedro Graca

            #6
            Re: php condition in a tabel with html and php

            elia wrote:
            I would like to show a line in a tabel in html if there is quantity of
            article choosed.
            >
            My code is:
            <? if ($quantite1 0) {
            echo <<<LINE
            <tr>
            <td align="left" nowrap="nowrap" >Article 1</td>
            <td align="center"> $quantite1</td>
            <td align="center"> 20 &euro;</td>
            <td align="center"> $montant1 &euro;</td>
            </tr>
            LINE;
            //}
            //else{
            //echo("");
            }
            ?>

            --
            File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

            Comment

            • elia

              #7
              Re: php condition in a tabel with html and php

              Thanks but it doesn't work! Pascal

              Comment

              • Pedro Graca

                #8
                Re: php condition in a tabel with html and php

                elia wrote:
                Thanks but it doesn't work! Pascal
                Why? What happens? What did you expect? *How* does it not work?
                See http://www.php.net/string

                <?php
                error_reporting (E_ALL);
                ini_set('displa y_errors', '1');

                $quantite1 = 6;
                $montant1 = 42;

                ### Method 1: double quote delimited string with embedded double quotes
                if ($quantite1 0) {
                echo "<tr>
                <td align=\"left\" nowrap=\"nowrap \">Article 1</td>
                <td align=\"center\ ">$quantite 1</td>
                <td align=\"center\ ">20 &euro;</td>
                <td align=\"center\ ">$montant1 &euro;</td>
                </tr>";
                }

                ### Method 1: double quote delimited string with embedded single quotes
                if ($quantite1 0) {
                echo "<tr>
                <td align='left' nowrap='nowrap' >Article 1</td>
                <td align='center'> $quantite1</td>
                <td align='center'> 20 &euro;</td>
                <td align='center'> $montant1 &euro;</td>
                </tr>";
                }

                ### Method 3: single quote delimited string with embedded double quotes
                if ($quantite1 0) {
                echo '<tr>
                <td align="left" nowrap="nowrap" >Article 1</td>
                <td align="center"> ', $quantite1, '</td>
                <td align="center"> 20 &euro;</td>
                <td align="center"> ', $montant1, ' &euro;</td>
                </tr>';
                }

                ### Method 4: heredoc syntax with embedded double quotes
                if ($quantite1 0) {
                echo <<<LINE
                <tr>
                <td align="left" nowrap="nowrap" >Article 1</td>
                <td align="center"> $quantite1</td>
                <td align="center"> 20 &euro;</td>
                <td align="center"> $montant1 &euro;</td>
                </tr>
                LINE;
                }
                ?>

                --
                File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

                Comment

                • Jerry Stuckle

                  #9
                  Re: php condition in a tabel with html and php

                  elia wrote:
                  Hello,
                  >
                  I would like to show a line in a tabel in html if there is quantity of
                  article choosed.
                  >
                  My code is:
                  >
                  <? if ($quantite1 0) {
                  echo('
                  <tr>
                  <td align="left" nowrap="nowrap" >Article 1</td>
                  <td align="center"> <? echo $quantite1 ?</td>
                  <td align="center"> 20 &euro;</td>
                  <td align="center"< ? echo $montant1 ?&euro;</td>
                  </tr>');
                  }
                  else{
                  echo("");
                  }
                  ?>
                  >
                  If there is no article >no line
                  If there is article >show the line
                  >
                  Problem: I can have the variable $quantite1 and $montant1 en php
                  >
                  Two options:

                  <? if ($quantite1 0) {
                  echo('
                  <tr>
                  <td align="left" nowrap="nowrap" >Article 1</td>
                  <td align="center"> ' .$ quantite1 . '</td>
                  <td align="center"> 20 &euro;</td>
                  <td align="center"> ' . $montant1 . ' &euro;</td>
                  </tr>');
                  }
                  else{
                  echo("");
                  }
                  ?>

                  Or

                  <? if ($quantite1 0) {
                  echo("
                  <tr>
                  <td align=\"left\" nowrap=\"nowrap \">Article 1</td>
                  <td align=\"center\ ">$quantite 1</td>
                  <td align=\"center\ ">20 &euro;</td>
                  <td align=\"center\ ">$montant1 &euro;</td>
                  </tr>');
                  }
                  else{
                  echo("");
                  }
                  ?>

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • elia

                    #10
                    Re: php condition in a tabel with html and php

                    Fantastic!! It's works with the first solution. ' . $quantite1 . '
                    marvelous, thanks to you!! Pascal

                    Comment

                    Working...