在PHP中基于USER ID生成自己的页面

时间:2012-08-20 09:56:03

标签: php mysql

对于我的这个查询,我想不出更好的标题。我试图显示所有用户,然后在每一行中有一个VIEW链接(基于他们的用户ID)..例如:http://minquep.com/pages/23(其中23是一个用户的用户ID)...

这是我的带删除功能的显示功能。

我已经使用

在每行中显示了VIEW链接
<a href="<? echo $rows['user_id']?>VIEW</a>

我的问题是,在页面文件夹下尚未生成VIEW链接的每个网址。

如何根据user_ids

在每个用户中制作view.php

当我添加用户时,是否可以创建自动查看页面。如何在我的显示功能中调用它

<!-- ALL MEMBERS QUERY -->
        <div id="allmembers" class="content">
            <?php
                include("connection.php"); #DATABASE CONNECTION DO NOT EDIT

                #Moderators
                $sql="SELECT user_id, special_id, login, user_type, company FROM $tbl_name";
                $result=mysql_query($sql);

                #count all mods
                $count=mysql_num_rows($result);
            ?>

        <br style="clear:both;">

        <div style="float:left;margin-left:1%;">
            <?php echo "<font size='3px'>There are $count users:</font>"; #OUTPUT COUNT MODS ?>
        </div>
        <br/><br/>

        <table width="100%" border="0" cellspacing="1" cellpadding="0">
            <tr>
                <td>
                    <form name="form1" method="post" action="" onsubmit="return confirm('Click OK or Cancel to Continue');">
            <table width="100%" border="1%" cellpadding="3" cellspacing="1">
                <tr>
                    <td align="center">#</td>
                    <td align="center"><strong>Id</strong></td>
                    <td align="center"><strong>Name</strong></td>
                    <td align="center"><strong>User Type</strong></td>
                    <td align="center"><strong>Company</strong></td>
                </tr>

        <?php
            while($rows=mysql_fetch_array($result)){
        ?>

                <tr>
                    <td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['special_id']; ?>"></td>
                    <td width="10%"><? echo $rows['special_id']; ?></td>
                    <td width="25%"><? echo $rows['login']; ?></td>
                    <td width="20%"><? echo $rows['user_type']; ?></td>
                    <td><? echo $rows['company']; ?></td>
                    <td><a href="<?echo $rows['user_id']; ?>">View</a></td>
                </tr>

        <?php
        }
        ?>

                <tr>
                    <td width="10%" border="0"><input name="delete" type="submit" id="delete" value="Delete Selected User(s)"></td>
                </tr>



            </table>
                    </form>
                </td>
            </tr>

            <?php
                // Check if delete button active, start this 
                if($_POST['delete']){
                $checkbox=$_POST['checkbox'];
                for($i=0;$i<count($checkbox);$i++){
                $del_id = $checkbox[$i];
                $sql = "DELETE FROM $tbl_name WHERE special_id='$del_id'";
                $result = mysql_query($sql);}
                // if successful redirect back to manage_users.php
                if($result){
                echo "<meta http-equiv=\"refresh\" content=\"0;URL=manage_users.php\">"; #REDIRECTION ITSELF
                }
                }

            ?>
        </table>

1 个答案:

答案 0 :(得分:3)

你应该研究URL rewriting。为每个用户创建一个物理页面会很疯狂。

基本上,默认情况下,您有一个这样的网址: http://minquep.com/page.php?user_id=3323

使用网址重写,您可以允许用户通过以下网址访问profile.php页面: http://minquep.com/pages/3323

相关问题