开发者

Adding different links next to info retrieved from the database

开发者 https://www.devze.com 2023-04-12 22:45 出处:网络
So I managed to get my registered user\'s info to display for a logged in member but what I want to achieve now is to add a link next to each user\'s name for e.g.

So I managed to get my registered user's info to display for a logged in member but what I want to achieve now is to add a link next to each user's name for e.g.

user_name <- "ADD AS FRIEND"

user_name <- "ADD AS FRIEND"

user_name <- "ADD AS FRIEND"

to add another user as your friend.

Now I'm not entirely sure how to do this... Must I use some sort of for loop or what?

I have a members.php and a database.sql file

members.php

<!DOCTYPE HTML>
<head>
    <title> ShareLink </title>
    <link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
    <div id="wrapper">
    <?php

    //create_cat.php
    include 'connect.php';
    include 'header.php';

    if(isset($_SESSION['signed_in']) == false || isset($_SESSION['user_level']) != 1 )
        {
            //the user is not an admin
            echo '<br/>';
            echo 'Sorry! You have to be <a href="/signin.php"><b>logged in</b></a> to view all the <a href="signup.php" title="Become a registered user!"><b>registered</b></a> members.';
            echo '<br/><br/>';
        }
        else
        {
            echo '<h2>Registered users:</h2>';

            $sql    = "SELECT `user_name` FROM `users` ORDER BY `user_name` ASC";
            $result = mysql_query($sql);

            while($user = mysql_fetch_array($result))

            echo $user['user_name']. '<a href="#"><b> Add as friend </b></a><br/><br/>';  //14 spaces

            //NOW I WANT TO MAKE A SPECIFIC "ADD AS FRIEND" LINK NEXT TO EACH USER


        }
        include 'footer.php';
    ?>
</div>

and my database.sql

CREATE TABLE users (  
user_id     INT(8) NOT NULL AUTO_INCREMENT,  
user_name   VARCHAR(30) NOT NULL,  
user_pass   VARCHAR(255) NOT NULL,  
user_email  VARCHAR(255) NOT NULL,  
user_date   DATETIME NOT NULL,  
user_level  INT(8) NOT NULL,  
UNIQUE INDEX user_name_unique (user_name),  
PRIMARY KEY (user_id)  
);

CREATE TABLE categories (  
cat_id          INT(8) NOT NULL AUTO_INCREMENT,  
cat_name        VARCHAR(255) NOT NULL,  
cat_description     VARCHAR(255) NOT NULL,  
UNIQUE INDEX cat_name_unique (cat_name),  
PRIMARY KEY (cat_id)  
);

CREATE TABLE topics (  
topic_id        INT(8) NOT NULL AUTO_INCREMENT,  
topic_subject       VARCHAR(255) NOT NULL,  
topic_date      DATETIME NOT NULL,  
topic_cat       INT(8) NOT NULL,  
topic_by        INT(8) NOT NULL,  
PRIMARY KEY (topic_id)  
); 

CREATE TABLE posts (  
post_id         INT(8) NOT NULL AUTO_INCREMENT,  
post_content        TEXT NOT NULL,  
post_date       DATETIME NOT NULL,  
post_topic      INT(8) NOT NULL,  
post_by     INT(8) NOT NULL,  
PRIMARY KEY (post_id)  
);

Must I add a friend table as well I want users to add other users开发者_运维技巧 as friends?


Yup, you have to keep track of who is friend of who... it's doesn't happen by itself ;-). The friend table than will contain a user_id and a friend_id (foreign key to other user_id). That combination is unique.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号