Click here to Skip to main content
15,392,679 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
QuestionSorting array and adding position numbers while/after sorting Pin
Member 131868238-May-17 4:15
MemberMember 131868238-May-17 4:15 
QuestionHelp Pin
Member 1302311826-Apr-17 3:40
MemberMember 1302311826-Apr-17 3:40 
AnswerRe: Help Pin
Jochen Arndt26-Apr-17 3:58
professionalJochen Arndt26-Apr-17 3:58 
GeneralRe: Help Pin
Member 1302311826-Apr-17 4:14
MemberMember 1302311826-Apr-17 4:14 
GeneralRe: Help Pin
Jochen Arndt26-Apr-17 4:43
professionalJochen Arndt26-Apr-17 4:43 
GeneralRe: Help Pin
Member 1302311826-Apr-17 4:55
MemberMember 1302311826-Apr-17 4:55 
GeneralRe: Help Pin
Jochen Arndt26-Apr-17 5:01
professionalJochen Arndt26-Apr-17 5:01 
QuestionHow To Add More Than One Entry On A Single Cell/Array ? Pin
Member 129567898-Apr-17 14:17
MemberMember 129567898-Apr-17 14:17 
Programming buddies,

I'm back online after nearly 2wks of offline. Gonna be harassing you guys again and more this time. Eeek!

Anyway, right now, I'm trying to build a script that adds multi entries into same single cell or mysql row.
The script tries monitoring what you are browsing via the:

<pre><input type="text" name="browse_url" size="120">


and then record your viewed urls into the same row (position: 0), column: browsings like so:

1.com,2.com and so on.
So, at first, the mysql array or cell is blank. When you view a url (eg.) 1.com then the array would show like this:

1.com

And then afterwards, if you view facebook.com then the cell should get updated by first grabbing the previously viewed urls and then adding the latest url onto the same cell/array like so (each url separated by comma):

1.com,facebook.com


Throw your precious eyes on line 79 onwards on both sample scripts. I reckon the 1st script is no good but the 2nd should work. Gave you both scripts to show the variety of ways I attempted.


Sample 1:

[php]

<?php 
session_start();
require "conn.php";
require "site_details.php";

/*Check if user is logged-in or not by checking if session is set or not. 
If user is not logged-in then redirect to login page. Else, show user's account homepage.php.*/

if(!isset($_SESSION["user"])) 
{
    header("location:login.php");
}
else 
{
	$user = $_SESSION["user"];
	?>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
	<html>
	<head>
	<title>Browse!</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	</head>
	<body>
	<p>
	<p>
	<p>	
	<?php 
	//Display 'Browser' ?>
	<iframe src='<?php echo $db_latest_view;?>'></iframe>
	<p>
	<p>
	<p>
    <form method="post" action="">
	<table border="1" width="50%">
	<tr>
	<td width="10">Url: </td>
	<td><input type="text" name="browse_url" size="120"></td>
	</tr>
	<tr>
	<td width="10">Browse: </td>
	<td>
	<select name="browsing_type">
	<OPTION>Anonymous Browsing</OPTION>
	<OPTION>Group Browsing</OPTION>
	</SELECT>
	</td>
	</tr>
	<td></td>
	<td><input type="submit" name="browse" size="50" value="Browse"><input type="submit" name="search_keywords" size="50" value="Search Keywords"></td>
	<tr>
	<td width="10">Message: </td><td><textarea name="message" cols="120" rows="10"></textarea></td>
	</tr>
	<tr>
	<td></td>
	<td width="50"><input type="submit" name="submit_message" size="50" value="Send Message!"></td>
	</tr>
	<p>
	<p>
	</table>
	</form>
	
	<?php 
	if(isset($_REQUEST['browse'])) 
	{
		$browse_url = trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["browse_url"]))));
		$browsing_type = trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["browsing_type"]))));
		
		//Grab User details from database.
		$sql = "SELECT * FROM users WHERE usernames = '".$user."'";	
		$result = mysqli_query($conn,$sql);
		$numrows = mysqli_num_rows($result);
		if($numrows) 
		{	
			while($row = mysqli_fetch_assoc($result))
			{
				$db_user_browsings = $row["browsings"];				
			}
			
			$sql = "INSERT INTO users(browsings) VALUES('".$browse_url."''".$db_user_browsings."')";
			$result = mysqli_query($conn,$sql);
			if($sql)
			{
				echo "true";			
			}
			
			$sql = "UPDATE users SET browsings_latest = '".$browse_url."' WHERE usernames = '".$user."'";
			$result = mysqli_query($conn,$sql);
			if($sql)
			{
				echo "true";			
			}				
		}
	}
}

?>


[/php]

Sample 2

[php]

<?php 
session_start();
require "conn.php";
require "site_details.php";

/*Check if user is logged-in or not by checking if session is set or not. 
If user is not logged-in then redirect to login page. Else, show user's account homepage.php.*/

if(!isset($_SESSION["user"])) 
{
    header("location:login.php");
}
else 
{
	$user = $_SESSION["user"];
	?>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
	<html>
	<head>
	<title>Browse!</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	</head>
	<body>
	<p>
	<p>
	<p>	
	<?php 
	//Display 'Browser' ?>
	<iframe src='<?php echo $db_latest_view;?>'></iframe>
	<p>
	<p>
	<p>
    <form method="post" action="">
	<table border="1" width="50%">
	<tr>
	<td width="10">Url: </td>
	<td><input type="text" name="browse_url" size="120"></td>
	</tr>
	<tr>
	<td width="10">Browse: </td>
	<td>
	<select name="browsing_type">
	<OPTION>Anonymous Browsing</OPTION>
	<OPTION>Group Browsing</OPTION>
	</SELECT>
	</td>
	</tr>
	<td></td>
	<td><input type="submit" name="browse" size="50" value="Browse"><input type="submit" name="search_keywords" size="50" value="Search Keywords"></td>
	<tr>
	<td width="10">Message: </td><td><textarea name="message" cols="120" rows="10"></textarea></td>
	</tr>
	<tr>
	<td></td>
	<td width="50"><input type="submit" name="submit_message" size="50" value="Send Message!"></td>
	</tr>
	<p>
	<p>
	</table>
	</form>
	
	<?php 
	if(isset($_REQUEST['browse'])) 
	{
		$browse_url = trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["browse_url"]))));
		$browsing_type = trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["browsing_type"]))));
		
		//Grab User details from database.
		$sql = "SELECT * FROM users WHERE usernames = '".$user."'";	
		$result = mysqli_query($conn,$sql);
		$numrows = mysqli_num_rows($result);
		if($numrows) 
		{	
			while($row = mysqli_fetch_assoc($result))
			{
				$db_user_browsings = $row["browsings"];				
			}
			
			$sql = "UPDATE users SET browsings = '".$browse_url."''".$db_user_browsings."' WHERE usernames = '".$user."'";
			$result = mysqli_query($conn,$sql);
			if($sql)
			{
				echo "true";			
			}	
			
			$sql = "UPDATE users SET browsings_latest = '".$browse_url."' WHERE usernames = '".$user."'";
			$result = mysqli_query($conn,$sql);
			if($sql)
			{
				echo "true";			
			}				
		}
	}
}

?>


[/php]
AnswerRe: What is the difference between web development and Web designing? Pin
ZurdoDev21-Mar-17 1:48
professionalZurdoDev21-Mar-17 1:48 
QuestionWhere do I put my jquery and AngularJS libraries in wordpress? Pin
samflex17-Feb-17 8:14
Membersamflex17-Feb-17 8:14 
QuestionTrying to connect categories and users through pivot table i Laravel Pin
Duško Oljača3-Feb-17 1:21
MemberDuško Oljača3-Feb-17 1:21 
AnswerRe: Trying to connect categories and users through pivot table i Laravel Pin
Afzaal Ahmad Zeeshan3-Feb-17 2:10
mveAfzaal Ahmad Zeeshan3-Feb-17 2:10 
QuestionOutputting ROW QUERY result to main program Pin
ELMAGLAYA16-Jan-17 21:19
MemberELMAGLAYA16-Jan-17 21:19 
AnswerRe: Outputting ROW QUERY result to main program Pin
Richard MacCutchan16-Jan-17 21:53
mveRichard MacCutchan16-Jan-17 21:53 
QuestionHow to fix this error $_SESSION:Notice: Undefined offset: 0 Pin
ELMAGLAYA4-Jan-17 18:45
MemberELMAGLAYA4-Jan-17 18:45 
AnswerRe: How to fix this error $_SESSION:Notice: Undefined offset: 0 Pin
Jochen Arndt4-Jan-17 22:16
professionalJochen Arndt4-Jan-17 22:16 
GeneralRe: How to fix this error $_SESSION:Notice: Undefined offset: 0 Pin
ELMAGLAYA16-Jan-17 21:33
MemberELMAGLAYA16-Jan-17 21:33 
AnswerCentOS httpd can not access Symbolink Pin
njzt28-Dec-16 1:26
Membernjzt28-Dec-16 1:26 
QuestionOpen Suse Linux Pin
ForNow27-Dec-16 13:42
MemberForNow27-Dec-16 13:42 
AnswerRe: Open Suse Linux Pin
Richard MacCutchan27-Dec-16 21:00
mveRichard MacCutchan27-Dec-16 21:00 
GeneralRe: Open Suse Linux Pin
ForNow28-Dec-16 2:11
MemberForNow28-Dec-16 2:11 
GeneralRe: Open Suse Linux Pin
Richard MacCutchan28-Dec-16 5:45
mveRichard MacCutchan28-Dec-16 5:45 
AnswerRe: Open Suse Linux Pin
Albert Holguin9-Jan-17 7:52
professionalAlbert Holguin9-Jan-17 7:52 
QuestionWhich is the Best Laravel Admin Template with all the advanced functionalities? Pin
Rakeshroshans23-Dec-16 20:00
MemberRakeshroshans23-Dec-16 20:00 
AnswerRe: Which is the Best Laravel Admin Template with all the advanced functionalities? Pin
Richard MacCutchan23-Dec-16 21:55
mveRichard MacCutchan23-Dec-16 21:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.