0
$result = mysql_query("SELECT * FROM productlist1 order by pdesc ASC");


while($row = mysql_fetch_array($result))
$sold=$row['psold'];
$left=$row['pleft'];
$all=$left + $sold;
  {
    echo '<tr>';

      echo '<td>'.$row['pcode'].'</td>';
      echo '<td>'.$row['pdesc'].'</td>';
       echo '<td>'.$row['date'].'</td>';
        echo '<td>'.$row['time'].'</td>';
      echo '<td><div align="center">'.$row['psold'].'</div></td>';
      echo '<td><div align="center">'.$row['pleft'].'</div></td>';
      echo '<td><div align="center">'.$row['pprice'].'</div></td>';
    echo '<td><div align="center">'.$all.'</div></td>';

i want to add the pleft and psold, the $all doesn't work at all... what would i do with this code?

0

5 Answers 5

1

You have a syntax error. You need to place following 3 lines inside brackets:

$sold=$row['psold'];
$left=$row['pleft'];
$all=$left + $sold;

like:

while($row = mysql_fetch_array($result))
  {
  $sold=$row['psold'];
  $left=$row['pleft'];
  $all=$left + $sold;
    echo '<tr>';
    ....
Sign up to request clarification or add additional context in comments.

Comments

1

You have to put opening braces for while loop just after the while statement like.

while($row = mysql_fetch_array($result))
{
$sold=$row['psold'];
$left=$row['pleft'];
$all=$left + $sold;
  ...............

Comments

1

Put your addition inside while loop,

because outside while loop it doesn't work, because it does not get proper value

So , try like this

    <?php

    $result = mysql_query("SELECT * FROM productlist1 order by pdesc ASC");


    while($row = mysql_fetch_array($result))
    {
        $all=$row['psold'] + $row['pleft'];
        echo '<tr>';

          echo '<td>'.$row['pcode'].'</td>';
          echo '<td>'.$row['pdesc'].'</td>';
           echo '<td>'.$row['date'].'</td>';
            echo '<td>'.$row['time'].'</td>';
          echo '<td><div align="center">'.$row['psold'].'</div></td>';
          echo '<td><div align="center">'.$row['pleft'].'</div></td>';
          echo '<td><div align="center">'.$row['pprice'].'</div></td>';
        echo '<td><div align="center">'.$all.'</div></td>';

Comments

0

Try this.

 $result = mysql_query("SELECT * FROM productlist1 order by pdesc ASC");

    while($row = mysql_fetch_array($result))
      {
    $sold=$row['psold'];
    $left=$row['pleft'];
    $all=$left + $sold;
        echo '<tr>';
          echo '<td>'.$row['pcode'].'</td>';
          echo '<td>'.$row['pdesc'].'</td>';
           echo '<td>'.$row['date'].'</td>';
            echo '<td>'.$row['time'].'</td>';
          echo '<td><div align="center">'.$row['psold'].'</div></td>';
          echo '<td><div align="center">'.$row['pleft'].'</div></td>';
          echo '<td><div align="center">'.$row['pprice'].'</div></td>';
        echo '<td><div align="center">'.$all.'</div></td>';
echo '</tr>';
    }

Comments

-2

Try parsing the values to integer like

$all=intval($left)+intval($sold);

Yeah one more thing your while is misplaced!!

1 Comment

why -1 for this answer??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.