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
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'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.