首页 > 解决方案 > PHP showing someone's user profile by taking MYSQL infos in HTML

问题描述

        include_once 'info.php';  
    $query = $config -> prepare("SELECT `ID`, `Info1`, `Info2`, `Info3`, `Info4`,`Info5`,`Info6`, `Info7` FROM `users` ORDER BY `ID` DESC LIMIT 9999999999");  
    if($query -> execute())   
    {  
        $query_results = $query->fetchAll();

    }  foreach( $query_results as $query_result ) { 
    }
<html>
<tbody>
<?php foreach( $query_results as $query_result ) { 
                             ?>  
           <tr>
              <td><?php echo $query_result["ID"]; ?></td>
              <td><?php echo $query_result["Info1"]; ?></td>
              <td><?php echo $query_result["Info2"]; ?> <?php echo $query_result["Info3"];?> <?php echo $query_result["Info4"]; ?></td>
              <td><?php echo $query_result["Info5"]; ?> </td>
              <td><?php echo $query_result["Info6"];  ?></td>
              <td><?php echo $query_result["Info7"];  ?></td>
              <td>                                  <a class="btn btn-success" href="profiles/<?php echo $query_result["ID"]; ?>">
                                        <i class="halflings-icon white zoom-in"></i>  
</td>
            </tr>
    <?php } ?></html>

Hello. The code from above is my searchperson.php (not included database conf and so on, it just how I echo every user from "users" inside a table.) And inside my table, I have an eye (iclass) which I can click on it and redirect me to www.domain.com/users/ID

My question is, how can I make only ONE page, static page, which will show ID's infos?

Exemple: I click on ID1, a new page www.domain.com/user/1 will pop up. I don't have any folder named "1". And I don't want to create any folder for every user. I just want to show ID 1's informations on www.domain.com/user/1
And if I click on ID2, to show ID 2's information on www.domain.com/user/2. (Or, www.domain.com/user?2, it doesn't matter.)

标签: phphtmlmysql

解决方案


If you aren't using a framework or front controller pattern (single entrypoint for your app), then you can use an Apache rewrite, something like this:

RewriteEngine On
RewriteRule ^/user([^/]*)$ /user-info.php?id=$1 [L]

推荐阅读