0
因此,我設法讓我的註冊用戶的信息顯示給已登錄的成員,但我現在想要實現的是在每個用戶名旁邊添加一個鏈接,在數據庫檢索到的信息旁添加不同的鏈接
USER_NAME < - 「加爲好友」
USER_NAME < - 「加爲好友」
USER_NAME < - 「加爲好友」
給其他用戶添加爲好友。
現在我不完全確定如何做到這一點...我必須使用某種循環或什麼?
我有一個members.php和database.sql文件
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>
和我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)
);
必由之路我也添加一個朋友表我希望用戶添加其他用戶作爲朋友?
好吧,我知道了,但我如何使鏈接獨特的方式?因爲在此階段,user_name 1旁邊的鏈接與user_name 3旁邊的鏈接相同... –
http://stackoverflow.com/questions/635937/how-do-i-specify-unique-constraint-for-多列,在MySQL的 – JNDPNT