0

Hello :) I have a system to add friends, i would like to make it as i want, but something does not deal...

This is a SQL now:

CREATE TABLE `friends` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `f_id` int(11) NOT NULL,
  `us_id` int(11) NOT NULL,
  `active` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=cp1251 AUTO_INCREMENT=30 ;

PHP code of Index.php:

$qfr = mysql_query("SELECT * FROM friends");
	while($rfr = mysql_fetch_array($qfr)){
	
		if($rfr['f_id'] == $userdata['id'] && $rfr['us_id'] == $r['id']){
			$qfr_f = mysql_query("SELECT * FROM friends WHERE f_id = '".$userdata['id']."' AND us_id = '".$r['id']."'");
			$rfr_f = mysql_fetch_array($qfr_f);
				if(mysql_num_rows($qfr_f) < 1){
					$fr_st = "user_add";
					$fr_st_m = "<a href=\"index.php?p=friends&type=add_fr&f_id=$r[id]\" title=\"Изпратете покана за приятелство на $r[username]\">Add friend</a>";
						
				} elseif($rfr_f['active'] == 0){
					$fr_st = "wait";
					$fr_st_m = "<b title=\"Вашата покана за приятелство чака да бъде одобрена от $r[username]\">Send invite</b>";
				} else {
					$fr_st = "user_block";
					$fr_st_m = "<a href=\"index.php?p=friends&type=del_fr&id=$rfr_f[id]\" title=\"Премахнете $r[username] от приятели\">Remove friend</a>";
				}
		} elseif($rfr['f_id'] == $r['id'] && $rfr['us_id'] == $userdata['id']){
			$qfr_f = mysql_query("SELECT * FROM friends WHERE f_id = '".$r['id']."' AND us_id = '".$userdata['id']."'");
			$rfr_f = mysql_fetch_array($qfr_f);
				if(mysql_num_rows($qfr_f) < 1){
					$fr_st = "user_add";
					$fr_st_m = "<a href=\"index.php?p=friends&type=add_fr&f_id=$r[id]\" title=\"Изпратете покана за приятелство на $r[username]\">Add friend</a>";
						
				} elseif($rfr_f['active'] == 0){
					$fr_st = "wait";
					$fr_st_m = "<b title=\"Вашата покана за приятелство чака да бъде одобрена от $r[username]\">Send invite</b>";
				} else {
					$fr_st = "user_block";
					$fr_st_m = "<a href=\"index.php?p=friends&type=del_fr&id=$rfr_f[id]\" title=\"Премахнете $r[username] от приятели\">Remove friend</a>";
				}
		} 
	}
if($_GET['p'] == "friends"){
	if(!$_SESSION['login']){
		header("Location: index.php");
	} else {
		if($_GET['type'] == "add_fr"){
			$qfrd = mysql_query("SELECT * FROM friends WHERE f_id = '".$_GET['f_id']."' AND us_id = '".$userdata['id']."'");
			$rfrd = mysql_fetch_array($qfrd);
			if($_GET['f_id'] && mysql_num_rows($qfrd) < 1){
				$sql = mysql_query("INSERT INTO friends (`f_id`, `us_id`) VALUES ('".$_GET['f_id']."', '".$userdata['id']."')");
					if($sql == TRUE){
						header("Location: ".$_SERVER['HTTP_REFERER']."");
					}
			} else {
				header("Location: ".$_SERVER['HTTP_REFERER']."");
			}
		} elseif($_GET['type'] == "del_fr"){
			if($_GET['id']){
				$delf = mysql_query("DELETE FROM friends WHERE id = '".$_GET['id']."' AND active = '1'");
					if($delf == TRUE){
						header("Location: ".$_SERVER['HTTP_REFERER']."");
					}
			} else {
				header("Location: index.php");
			}
		} elseif($_GET['type'] == "accept"){
			$qfn = mysql_query("SELECT * FROM friends WHERE id = '".$_GET['id']."'");
			$rfn = mysql_fetch_array($qfn);
			
			$updf = mysql_query("UPDATE friends SET active = '1' WHERE id = '".$_GET['id']."'");
					if($updf == TRUE){
						$sqln = mysql_query("INSERT INTO notifications (`type`, `f_id`, `t_id`, `date`) VALUES ('f_accept', '".$userdata['id']."', '".$rfn['us_id']."', '".time()."')");
							if($sqln == TRUE){
								header("Location: ".$_SERVER['HTTP_REFERER']."");
							}
					}
		} elseif($_GET['type'] == "ignore_fr"){
			$delf = mysql_query("DELETE FROM friends WHERE f_id = '".$_GET['f_id']."' AND us_id = '".$userdata['id']."'");
				if($delf == TRUE){
					header("Location: ".$_SERVER['HTTP_REFERER']."");
				}
		} else {
			//header("Location: index.php");
		}
	}
}

if($_GET['p'] == "us_ac"){
	if(!$_SESSION['login']){
		header("Location: index.php");
	} else {
		if($_GET['type'] == "delete_photo" && $_GET['id']){
			$qpac = mysql_query("SELECT * FROM pictures WHERE id = '".$_GET['id']."' AND us_id = '".$userdata['id']."'");
			$rpac = mysql_fetch_array($qpac);
			
			$del = mysql_query("DELETE FROM pictures WHERE id = '".$rpac['id']."' AND us_id = '".$userdata['id']."'");
				if($del == TRUE){
					unlink("uploads/photos/".$rpac['picture']."");
					unlink("uploads/photos/small_".$rpac['picture']."");
					unlink("uploads/photos/small_thumb_".$rpac['picture']."");
					header("Location: ".$_SERVER['HTTP_REFERER']."");
				}
		} elseif($_GET['type'] == "delete_album" && $_GET['id']){
			$qpac = mysql_query("SELECT * FROM pictures WHERE a_id = '".$_GET['id']."' AND us_id = '".$userdata['id']."'");
			while($rpac = mysql_fetch_array($qpac)){
				$delp = mysql_query("DELETE FROM pictures WHERE id = '".$rpac['id']."' AND us_id = '".$userdata['id']."'");
					if($delp == TRUE){
						unlink("uploads/photos/".$rpac['picture']."");
						unlink("uploads/photos/small_".$rpac['picture']."");
						unlink("uploads/photos/small_thumb_".$rpac['picture']."");
					}
			}
			
			$del = mysql_query("DELETE FROM albums WHERE id = '".$_GET['id']."' AND us_id = '".$userdata['id']."'");
				if($del == TRUE){
					header("Location: ".$_SERVER['HTTP_REFERER']."");
				}
		} elseif($_GET['type'] == "profile_photo" && $_GET['id']){
			$upd_d = mysql_query("UPDATE pictures SET pind = '0' WHERE us_id = '".$userdata['id']."' AND pind = '1'");
			$upd = mysql_query("UPDATE pictures SET pind = '1' WHERE id = '".$_GET['id']."' AND us_id = '".$userdata['id']."' AND pind = '0'");
				if($upd == TRUE){
					header("Location: ".$_SERVER['HTTP_REFERER']."");
				}
		} elseif($_GET['type'] == "delete_mphoto" && $_GET['id']){
			$qpac = mysql_query("SELECT * FROM pictures WHERE id = '".$_GET['id']."'");
			$rpac = mysql_fetch_array($qpac);
			
			$del = mysql_query("DELETE FROM pictures WHERE id = '".$rpac['id']."'");
				if($del == TRUE){
					unlink("uploads/photos/".$rpac['picture']."");
					unlink("uploads/photos/small_".$rpac['picture']."");
					unlink("uploads/photos/small_thumb_".$rpac['picture']."");
					header("Location: ".$_SERVER['HTTP_REFERER']."");
				}
		} elseif($_GET['type'] == "delete_comment" && $_GET['id']){
			$qc = mysql_query("SELECT * FROM comments WHERE id = '".$_GET['id']."'");
			$rc = mysql_fetch_array($qc);
				
				if($_GET['us'] == $userdata['id'] || $rc['us_id'] == $userdata['id'] || level($userdata['id'], '3') > 2){
					$del = mysql_query("DELETE FROM comments WHERE id = '".$_GET['id']."'");
						if($del == TRUE){
							header("Location: ".$_SERVER['HTTP_REFERER']."");
						}
				} else {
					header("Location: index.php");
				}
		} elseif($_GET['type'] == "delete_message" && $_GET['id']){
			$del = mysql_query("DELETE FROM messages WHERE id = '".$_GET['id']."' AND f_id = '".$userdata['id']."' OR to_id = '".$userdata['id']."'");
				if($del == TRUE){
					$delm = mysql_query("DELETE FROM messages_sub WHERE m_id = '".$_GET['id']."'");
						if($delm == TRUE){
							header("Location: ".$_SERVER['HTTP_REFERER']."");
						}
				}
		} else {
			header("Location: index.php");
		}
	}
}

PHP code of Profile.php:

<?php
										if($userdata['id'] == $r['id']){
									?>
											<td width="45%"><div align="center" class="btb r" style="margin: 0 15px 5px 15px;"><a href="index.php?p=upload_photo"><img src="images/icons/upload_photos.png" align="absmiddle" /> <b>Add picture</b></a></div></td>
											<td width="55%"><div align="center" class="btb r" style="margin: 0 15px 5px 15px;"><a href="index.php?p=edit_profile"><img src="images/icons/user_edit.png" align="absmiddle" /> <b>Edit profile</b></a></div></td>
									<?php
										} else {
									?>
											<td width="50%">
												<?php
													if($fr_st != ""){
												?>
														<div align="center" class="btb r" style="margin: 0 10px 5px 10px;"><img src="images/icons/<?php echo $fr_st ?>.png" align="absmiddle" /> <b><?php echo $fr_st_m ?></b></div>
												<?php
													} else {
												?>
														<div align="center" class="btb r" style="margin: 0 10px 5px 10px;"><a href="index.php?p=friends&type=add_fr&f_id=<?php echo $r['id'] ?>"><img src="images/icons/user_add.png" align="absmiddle" /> <b>Add friend</b></a></div>
												<?php
													}
												?>
											</td>
											<td width="50%"><div align="center" class="btb r" style="margin: 0 10px 5px 10px;"><a href="index.php?p=messages&type=new_message&to=<?php echo $r['id'] ?>"><img src="images/icons/new_message.png" align="absmiddle" /> <b>Send message</b></a></div></td>
									<?php
										}
									?>

I want SQL is as follows:

CREATE TABLE `friends` ( 
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(20) collate latin1_general_ci NOT NULL,
  `friendname` varchar(20) collate latin1_general_ci NOT NULL,
  `friend` varchar(255) NOT NULL, 
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

and the code gets to 2 pages and a sample of only profile.php, my mind is how long these will become links on nekvi kasichki in something like http://sitename/invite/username, and not as now http://sitename/index.php?p=messages&type=new_message&to=21

Thank you in advance :)

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by diafol
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.