Jump to content


Photo

MySql - listing?


  • Please log in to reply
30 replies to this topic

#21 Korndawg

Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 27 August 2006 - 11:41 PM

require 'config.php';

	require 'inc/global.php';

	

	$db = db_connect();

	$link_id = mysql_real_escape_string($_GET['id'],$db);

	$query = "SELECT hits_in FROM ndlinks_affiliates WHERE link_id='$link_id' LIMIT 1";

	$hits = mysql_fetch_array(mysql_query($query, $db));

	$hits = $hits['hits_in'] + 1;

	$query = "UPDATE ndlinks_affiliates SET hits_in='$hits' WHERE link_id='$link_id' LIMIT 1";

	mysql_query($query, $db);

	

	 $ip = $_SERVER['REMOTE_ADDR'];

	 $query = mysql_query("SELECT ip FROM ndlinks_affiliates WHERE link_id='$link_id' AND ip = '$ip'")or die(mysql_error());



	if(!mysql_num_rows($query))

	{

		mysql_query("UPDATE ndlinks_affiliates SET ip='$ip' WHERE link_id='$link_id'") or die(mysql_error());

	}else{

		$ip_data = mysql_fetch_array($query);

		$ips = $ip_data['ip'].$ip;

		mysql_query("UPDATE ndlinks_affiliates SET ip='$ips' WHERE link_id='$link_id'") or die(mysql_error());

	}

	

	header("Location: {$conf['site']['url']}Merch/");


#22 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 August 2006 - 10:28 PM

Sorry for the late catch, but i haven't been thinking straight lately. Please stick to one topic (even if somebody gets mad).

#23 Korndawg

Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 29 August 2006 - 03:24 AM

ok my bad... DemonSlay any new ideas? I cant even get it to record more than one IP now

#24 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 29 August 2006 - 05:27 AM

Ok, this is how i would do it, just throwing some ideas into the park.

<?php
$$id = $_GET['id'];
$i = 0;
 	
$query = @mysql_query("SELECT * FROM `table` WHERE id = '$id' LIMIT 0,1") or die(mysql_error());
	
while( $row = mysql_fetch_array( $query ) )
{
	$ips = $row['ip'];
	$ipArray = unserialize( $ips );
	
	foreach( $ipArray as $value ) { $i++; }
	
	if( $i > 0 )
	{
	 	$x = 0;
	 	foreach( $ipArray as $value )
	 	{
	 	 	$value[$x] = $value;
	 	 	$x++;
	 	}
	 	
	 	$value[$x++] = $_GET['ip'];
	 	
	 	$newArray = serialize( $value );
		$query = @mysql_query("UPDATE `table` SET ip = '$newArray' WHERE id = '$id'") or die(mysql_error());
		
		echo 'Ip added!';
	}
	
	else
	{
		$query = @mysql_query("INSERT INTO `table` (`id`, `ip`) VALUES ('', '$ip')") or die(mysql_error());	 
		echo 'Ip inserted!';
	}	
	 	
}

?>

I'm sure someone les slazy can modify that into ndlinks (or have it seperate to save messing about with ndlinks) but this is just me with an idea :) (not tested)

Edited by .Matt, 29 August 2006 - 05:28 AM.


#25 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 29 August 2006 - 03:36 PM

I was about to try that same method when I got back today, lol.
You had just one small error in adding two '$' for a variable, but I'll edit it a tad for his script I guess.
I'll also just add a small type change just to make sure the id is an integer.
<?php
$id = settype($_GET['id'], 'integer');
$i = 0;
$ip = $_SERVER['REMOTE_ADDR'];
	
$query = @mysql_query("SELECT * FROM `ndlinks_affiliates` WHERE id = '$id' LIMIT 0,1") or die(mysql_error());
	
while($row = mysql_fetch_array($query)){
	$ips = $row['ip'];
	$ipArray = unserialize($ips);
	
	foreach($ipArray as $value) $i++;
	
	if($i > 0){
		 $x = 0;
		 foreach($ipArray as $value){
			  $value[$x] = $value;
			  $x++;
		 }
		 if(!in_array($ip, $value) $value[$x++] = $ip;
		 
		$newArray = serialize($value);
		$query = @mysql_query("UPDATE `ndlinks_affiliates` SET ip = '$newArray' WHERE id = '$id'") or die(mysql_error());
		
		echo 'Ip added!';
	}
	
	else{
		$query = @mysql_query("INSERT INTO `ndlinks_affiliates` (`id`, `ip`) VALUES (NULL, '$ip')") or die(mysql_error());	
		echo 'Ip inserted!';
	}	
		 
}

?>

Actually yours is better than mine would have been. ;)

Oh wait a minute... you don't have squat about getting the IP. :P
I'll fix that up...
There, that work?

Just a thought, but you don't really need the incrementing $x variable do you? Just using '[]' will automatically stick it on the end of the array...

Edited by Demonslay, 29 August 2006 - 03:45 PM.


#26 Korndawg

Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 29 August 2006 - 11:29 PM

Ok, I did what you guys said... Here is what it looks like, now tell me if im completly wrong here.
$db = db_connect();
	$link_id = mysql_real_escape_string($_GET['id'],$db);
	$query = "SELECT hits_in FROM ndlinks_affiliates WHERE link_id='$link_id' LIMIT 1";
	$hits = mysql_fetch_array(mysql_query($query, $db));
	$hits = $hits['hits_in'] + 1;
	$query = "UPDATE ndlinks_affiliates SET hits_in='$hits' WHERE link_id='$link_id' LIMIT 1";
	mysql_query($query, $db);
	
	$id = settype($_GET['id'], 'integer');
	$i = 0;
	$ip = $_SERVER['REMOTE_ADDR'];
	
	$query = @mysql_query("SELECT * FROM `ndlinks_affiliates` WHERE link_id = '$id' LIMIT 0,1") or die(mysql_error());
	
	while($row = mysql_fetch_array($query)){
		$ips = $row['ip'];
		$ipArray = unserialize($ips);
	
	foreach($ipArray as $value) $i++;
	
		if($i > 0){
		 	$x = 0;
		 	foreach($ipArray as $value){
				  $value[$x] = $value;
				  $x++;
		 	}
Line 31:		 	if(!in_array($ip, $value) $value[$x++] = $ip;
		 
				$newArray = serialize($value);
				$query = @mysql_query("UPDATE `ndlinks_affiliates` SET ip = '$newArray' WHERE link_id = '$id'") or die(mysql_error());
		
				echo 'Ip added!';
			}
	
			else{
				$query = @mysql_query("INSERT INTO `ndlinks_affiliates` (`link_id`, `ip`) VALUES (NULL, '$ip')") or die(mysql_error());	
				echo 'Ip inserted!';
			}	
		 
		}
	
	header("Location: {$conf['site']['url']}Merch/");

By using the code I have above, I run the script and it gives me this in return.
Parse error: syntax error, unexpected T_VARIABLE in /home/faktionb/public_html/contest/in.php on line 31

I would fix it myself, however now you guys are talking about things I cant just bs my way out of.

Edited by Korndawg, 29 August 2006 - 11:30 PM.


#27 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 30 August 2006 - 04:44 AM

Replace it with this:

if(!in_array($ip, $value)) $value[$x++] = $ip;


#28 Korndawg

Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 30 August 2006 - 03:51 PM

Hmm now its back to not recording the IP at all....

Maybe I should just work with a .txt file? Would that be harder? have it record the id (if it isnt already present) and beyond the | have the IP's listed separated by spaces? Or would that just give the same amount of problems as this is now?

#29 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 30 August 2006 - 03:55 PM

Theres no difference tbh, just replacing the mysql part with flat files, (achually i would change it a bit more but meh).

What do you mean by not working? It inserts nothing?

Edited by .Matt, 30 August 2006 - 03:56 PM.


#30 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 30 August 2006 - 03:59 PM

Opps, forgot the ')', thanks for the catch Matt. We should be even now. ;)

Korn... you should really just sit down and examine the code and wrap your head around it. Trust me, this is easy crap... just some simple functions and variable assigning in logical order...

And a textfile would be just the same, only ANYONE could view it if they knew the filename, whereas a database no one without permission (and the password, etc.) can view it.
Also, usually a database search is considerably faster than a file search, especially if it has to split every single row of every single line. You'd also have to split it somehow to include an id, since you can't have columns like in a database.

I honestly think you are making this too hard on yourself. Just do like I said and study to code. Never just take code from someone and assume it's 100%. Analyze it and fix it for your own needs and crap, it's easy enough to figure out if you have the basic PHP understanding...

Edited by Demonslay, 30 August 2006 - 04:00 PM.


#31 Korndawg

Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 31 August 2006 - 03:06 PM

Ok well it's all taken care of. Thanks to everyone who helped me out, I apoligize for being a pain.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users