Jump to content

Help with UPDATE mysql.


thme01

Recommended Posts

 <?php
	$querySelect = mysql_query("SELECT * FROM `G4V_Videos` WHERE `counter`");
	$row = mysql_fetch_assoc($querySelect);
	$counter = $row['counter'];

	if (empty($counter)) {

		$counter = 1;
		$insert = mysql_query ("INSERT INTO counter VALUES ('counter')");
		$printid = (print $data['id']);
		$printlink = (print $data['link']);
	}

		$add = $counter+1;
		$insertNew = mysql_query("UPDATE G4V_Videos SET counter=('$add') WHERE id = ('$printid') AND link = ('$printlink')") or die (mysql_error());
			echo "Video Views";
			echo ":";
			echo" ";
			echo"<br />";
			echo "$counter";
	?>

 

It shows the same amount of hits on everyvideo instead of just the one video with the id

www.game4vids.com

Link to comment
https://forums.phpfreaks.com/topic/250050-help-with-update-mysql/
Share on other sites

If I'm correct about what you're trying to do here, assuming you have the default value of counter set to zero, and the field is an INT() data type, all you really need to do is execute one query to increment the counter. This won't likely be plug-n-play, but it should give you an idea of how to better handle it.

 

UPDATE G4V_Videos SET counter = counter + 1 WHERE id = '$printid'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.