Try to display data from a database on the Internet, but some records were not shown

I'm starting to develop sites. And I added some data to the phpMyAdmin database. Here is the database:

Database screenshots

And this is my code for creating spreadsheets on the Internet.

<table border = "1" cellpadding = "5" cellspacing = "0">
    <tr style="text-align: left;">
        <th style="width : 150px;">pmID</th>
        <th style="width : 150px;">pubYear</th>
        <th style="width : 150px;">pubMonth</th>
        <th style="width : 150px;">pubDay</th>
        <th style="width : 150px;">pubTitle</th>
        <th style="width : 150px;">articleTitle</th>
        <th style="width : 300px;">abstract</th>
    </tr>
    
    
    <?php
    while($row = $result -> fetch_object()){
        $pmID = htmlentities($row->pmID, ENT_QUOTES, "UTF-8");
        $pubYear = htmlentities($row->pubYear, ENT_QUOTES, "UTF-8");
        $pubMonth = htmlentities($row->pubMonth, ENT_QUOTES, "UTF-8");
        $pubDay = htmlentities($row->pubDay, ENT_QUOTES, "UTF-8");
        $pubTitle = htmlentities($row->pubTitle, ENT_QUOTES, "UTF-8");
        $articleTitle = htmlentities($row->articleTitle, ENT_QUOTES, "UTF-8");
        $abstract = htmlentities($row->abstract, ENT_QUOTES, "UTF-8");
        
    ?>
    
        <tr>
            <td><?php echo $pmI;?></td>
            <td><?php echo $pubYear;?></td>
            <td><?php echo $pubMonth;?></td>
            <td><?php echo $pubDay;?></td>
            <td><?php echo $pubTitle;?></td>
            <td><?php echo $articleTitle;?></td>
            <td><?php echo $abstract;?></td>    
        </tr>
    
    <?php
    }
    ?>
Run codeHide result

And the result: Result table

It is noted that some columns are empty. I do not know how to fix this.

+4
source share
4 answers

Perhaps a special character in db calls it. My suggestion, try to avoid using any special characters and replace it with regular characters. Hope this helps you.

0
source

Use foreach to process data

<?php
    foreach ($result as $row) {
?>
      <tr>
        <td><?php echo $row->pmI;?></td>
        <td><?php echo $row->pubYear;?></td>
        <td><?php echo $row->pubMonth;?></td>
        <td><?php echo $row->pubDay;?></td>
        <td><?php echo $row->pubTitle;?></td>
        <td><?php echo $row->articleTitle;?></td>
        <td><?php echo $row->abstract;?></td>    
      </tr>
<?php
    }
?>

Hope this helps

0
source

, htmlentities UTF-8.

0
source

You can solve it in different ways, I think you should read When to use HTML objects . now your possible solution

  • save source file as utf-8
  • The string passes it as UTF-8.

You can also print variables using echo and print. Also, do not save the special character in the database.

If you want to delete a special character, try this function $string = preg_replace('/[\x00-\x1F\x7F]/u', '', $string);

0
source

Source: https://habr.com/ru/post/1676345/


All Articles