Save <table></table> contain array in to the new table of database after extract from the Previous database

I write code to extract data from database Example’a’ and save thay in to the … data within is array . following code:

 <?php
        @mysql_connect("localhost","root","") or die('connection error');
     mysql_query('SET NAMES \'utf8\'');
       mysql_select_db('gas') or die('Can not connect to the database');
      $result = mysql_query('SELECT * FROM `wp_farsc`');

        if($result && mysql_num_rows ($result)> 0){
        echo '<table border="2px" cellspacing="5px" width="100%">'.PHP_EOL;
           echo '<tr bgcolor="yellow"><th>سکه</th><th>online price</th><th>changing </th><th>lowest</th>               <th>topest</th><th>update date</th>  </tr>'.PHP_EOL;
              while($row = mysql_fetch_assoc($result)){

                echo'<tr>';
           echo '<td>'.$row ['titile'].'</td>';
           echo '<td>'.$row ['liveprice'].'</td>';
            echo '<td>'.$row ['changing'].'</td>';
            echo '<td>'.$row ['lowest'].'</td>';
         echo '<td>'.$row ['topest'].'</td>';
            echo '<td>'.$row ['time'].'</td>';
          echo'</tr>'.PHP_EOL;
         }

         }  
           mysql_close();

Now I want save in to the new table (name is posts) of database.

example: databse fileds

title:today price / content: top html table with contains ,…

example:

foreach($row as $tr) { // foreach row { // avoid headers
  $sql = "INSERT INTO `posts`(post_title,post_content) VALUES ('today price','<table></table>')";

mysql_query($sql);

top html table

Your top priority should be to replace all those antiquated and soon to be removed mysql_ calls with their mysqli_ or PDO equivalents (as you should have started doing at least five years ago).

I found Solution. I imported table in to the function price_table(); // after I saved function in to the database but don’t save dynamic table , only save function name … (price_table():wink: not saved <table>contains</table>

  <?php
      function writeMsg(){
      @mysql_connect("localhost","root","") or die('connection error');
      
      mysql_query('SET NAMES \'utf8\'');
      mysql_select_db('gas') or die('Can not connect to the database');
      $result = mysql_query('SELECT * FROM `wp_farsc`');
      
      
      
      if($result && mysql_num_rows ($result)> 0){
          echo '<table border="2px" cellspacing="5px" width="100%">'.PHP_EOL;
          echo '<tr bgcolor="yellow"><th>سکه</th><th>قیمت انلاین</th><th>تغییر قیمت</th><th>کمترین</th><th>بیشترین</th><th>زمان بروز رسانی</th></tr>'.PHP_EOL;
          while($row = mysql_fetch_assoc($result)){
      
             echo'<tr>';
             echo '<td>'.$row ['titile'].'</td>';
             echo '<td>'.$row ['liveprice'].'</td>';
             echo '<td>'.$row ['changing'].'</td>';
             echo '<td>'.$row ['lowest'].'</td>';
             echo '<td>'.$row ['topest'].'</td>';
             echo '<td>'.$row ['time'].'</td>';
             echo'</tr>'.PHP_EOL;
          }
              
          }
           mysql_close();

              @mysql_connect("localhost","root","") or die('connection error');
               mysql_select_db('gas') or die('Can not connect to the database');
              mysql_query("set names utf8");
              $title ="عنوان مطلب امروز";
      $content ="echo writemsg();";
      $statuse="Publish";
      $pingo="open";
      $commento="open";
      $typee="post";
      $auther="1";
       $sql = "INSERT INTO `wp_posts`(	post_author,post_title,post_content,post_status,post_type,ping_status,comment_status) VALUES('$auther','$title','$content','$statuse','$typee','$pingo','$commento')";
        mysql_query($sql);
      mysql_close();
?>

EDIT
This post has been reformatted by enclosing the code block in 3 backticks
```
on their own lines.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.