0

here is my code

<?php 
while($rowcall=mysql_fetch_array($qry_call))
{
?>
  <table>
  <tr>
  <td><?php echo $rowcall['caller_id'];?></td>
  <td><?php echo $rowcall['did']; ?></td>
  <td><?php echo $rowcall['start_time']; ?></td>
  <td><?php echo $rowcall['end_time']; ?></td>
  <td><?php echo $rowcall['call_duration']; ?></td>
  </tr>
 </table> 
 <?php } ?>

I need to store this table in php variable $result.

3
  • Did you tried something? Commented Sep 6, 2013 at 5:59
  • do concatenation using . operator Commented Sep 6, 2013 at 6:01
  • Interesting that no Stop Using mysql_* comments here yet, but really you should :) Commented Sep 6, 2013 at 6:19

7 Answers 7

4
<?php

  $result = '';
  while($rowcall=mysql_fetch_array($qry_call))
  {
     $result .= '<table>';
     $result .= '<tr>';
     $result .= '<td>'.$rowcall['caller_id'].'</td>';
     $result .= '<td>'.$rowcall['did'].'</td>';
     $result .= '<td>'.$rowcall['start_time'].'</td>';
     $result .= '<td>'.$rowcall['end_time'].'</td>';
     $result .= '<td>'.$rowcall['call_duration'].'</td>';
     $result .= '</tr>';
     $result .= '</table>';
  }

  echo $result;

?>
Sign up to request clarification or add additional context in comments.

5 Comments

With this code you would generate a seperate table for every element you get from the database
Yep, I know. But that's what @user2732605 want if I see his question
@BjornSmeets thats what the OP has asked, right? "To store mysql row result as table format in php variable"
You are right, my bad. I misunderstood the question and thought he wanted 1 big table with all the data as rows inside that table
Exactly @rakeshjain .
1

Pretty basic PHP;

<?php 
$result="";
while($rowcall=mysql_fetch_array($qry_call))
{
    $result.="  <table>";
    $result.="  <tr>";
    $result.="  <td>".$rowcall['caller_id']."</td>";
    $result.="  <td>".$rowcall['did']."</td>";
    $result.="  <td>".$rowcall['start_time']."</td>";
    $result.="  <td>".$rowcall['end_time']."</td>";
    $result.="  <td>".$rowcall['call_duration']."</td>";
    $result.="  </tr>";
    $result.=" </table>"; 
}
?>

Comments

1
    *<?php

  $result = '';
  while($rowcall=mysql_fetch_array($qry_call))
  {
     $result .= '<table>';
     $result .= '<tr>';
     $result .= '<td>'.$rowcall['caller_id'].'</td>';
     $result .= '<td>'.$rowcall['did'].'</td>';
     $result .= '<td>'.$rowcall['start_time'].'</td>';
     $result .= '<td>'.$rowcall['end_time'].'</td>';
     $result .= '<td>'.$rowcall['call_duration'].'</td>';
     $result .= '</tr>';
     $result .= '</table>';
  }

  echo $result;

?>*

Comments

1

You could do it like this:

<?php 
    $result = "";
    while($rowcall=mysql_fetch_array($qry_call))
    {
        $result .= "<table>";
        $result .= "<tr>";
        $result .= "<td>".$rowcall['caller_id']."</td>";
        $result .= "<td>".$rowcall['did']."</td>";
        $result .= "<td>".$rowcall['start_time']."</td>";
        $result .= "<td>".$rowcall['end_time']."</td>";
        $result .= "<td>".$rowcall['call_duration']."</td>";
        $result .= "</tr>";
        $result .= "</table>";
    } 

    echo $result;
?>

Comments

0

Try on these lines. Also switch to mysqli_* rather than mysql_* as the one you are using is deprecated

<?php 
$str="";
while($rowcall=mysql_fetch_array($qry_call))
{
  $str .= "<table>
  <tr>
  <td>{$rowcall['caller_id']}</td>
  <td>{$rowcall['did']}</td>
  <td>{$rowcall['start_time']}</td>
  <td>{$rowcall['end_time']}</td>
  <td>{$rowcall['call_duration']}</td>
  </tr>
 </table>"; 
} 
?>

1 Comment

@BjornSmeets thats what the OP has asked, right? "To store mysql row result as table format in php variable"
0

I strongly advise you to see docs at http://www.php.net/manual/en/language.types.string.php

Comments

0

start and end the <table></table> tag out side while loop no inside it will create a new table for every row but that's you don't want

Comments

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.