English 中文(简体)
• 如何在“加拿大”网站之后创建用户?
原标题:How to create a user following php script?
  • 时间:2012-05-10 22:12:31
  •  标签:
  • php

我试图做的是,在我的文字上添加一个用户(如前线)。

This is how the db structure looks like:

CREATE TABLE IF NOT EXISTS `user_follow` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `follower` int(11) NOT NULL,
  `following` int(11) NOT NULL,
  `subscribed` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `follow_unique` (`follower`,`following`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

如果想建立,应当使用该守则:

mysql_query(" INSERT INTO `user_follow` (`follower`, `following`, `subscribed`) VALUES ( $follower ,  $following , CURRENT_TIMESTAMP); ");

无须说明:

mysql_query(" DELETE FROM `user_follow` WHERE `follower` =  $follower  AND `following` =  $following ; ");

$follower = $_SESSION[user_id]; // the user_id for the one who is currently logged id 
$following = $user_id; // the user_id for the user profile where the script will be on

在简介页上,我有这样的表格:

<?php if (isset($_SESSION[user_id]) && $_SESSION[user_id] != $user_id) { ?>
<form action="" method="post">
<input name="action" type="hidden" value="<?php echo $subscribe_status; ?>"/>
<button name="subject" type="submit" value="<?php echo $subscribe_text。   。$username; ?>"><?php echo $subscribe_text。   。$username; ?></button>
</form>
<?php } ?>

What i don t know is how to link all of those codes。。。

EDIT:

$subscribe_status should change to follow or unfollow depending if the user is already following that user or not (by checking with a query i think)。

Also $subscribe_text should be Follow or Unfollow depending if the currently logged in user ($follower) is already following that user or not。

谁能帮助我?

EDIT 2(基于Mihir Singh的答复)

$user_follow = dbquery(" SELECT * FROM `user_follow` WHERE `follower` =  $follower  AND `following` =  $following ; ");
$check_status = dbrows($user_follow);

$sub = false; //Boolean var which states if subscribed or not

if ( $check_status !== 0 ){ //Pseudo code
    $sub = true; //If row is found, they are subscribed, so set $sub to true
}

if($sub){
     $subscribe_status = "follow";
     $subscribe_text = "Follow";
}

else{
     $subscribe_status = "unfollow";
     $subscribe_text = "Unfollow";
}
最佳回答

这里有一些法典:

$sub = false; //Boolean var which states if subscribed or not

if (row in table exists --> subscribed ){ //Pseudo code
    $sub = true; //If row is found, they are subscribed, so set $sub to true

if($sub){
     $subscribe_status = "Follow";
     $subscribe_text = "Unfollow";
}

else{
     $subscribe_status = "Unfollow";
     $subscribe_text = "Follow";
}

EDIT:

因此,这是你重新使用的形式法:

<?php if (isset($_SESSION[user_id]) && $_SESSION[user_id] != $user_id) { ?>
<form action="" method="post">
<input name="action" type="hidden" value="<?php echo $subscribe_status; ?>"/>
<button name="subject" type="submit" value="<?php echo $subscribe_text.   .$username; ?>">       
<?php echo $subscribe_text.   .$username; ?></button>
</form>
<?php } ?>

Based on that, I would change

<form action="" method="post">

to

<form action="handler.php" method="post">

并由此创建手提文件:

<?
    if ($_POST[ action ] == "Follow")
        //Perform Unfollow Query to Database
    else
        //Perform Follow Query to Database
?>

这 bare了......但应当努力。 如何?

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签