|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
UPDATE $variable OnClick?
Being my second day programming in over three years, I'm a little lost at this point.
I'm starting on my first function and I know this code is just HORRIBLY written up to this point, to which I am sorry. My main concern is the function 'clickcount' and how it would interact with the link at the lower end of the code. I can't get the click value to increment and I'm not sure if the link doesn't recognize the call or if the function is written incorrectly. I'm still a little shady on the syntax of things, so I expect plenty of nodding heads when people look at this code. Code:
<?php require_once('Connections/senior.php'); ?>
<?php
function clickcount($x, $y, $z)
{
mysql_query("UPDATE $x SET $y = $y + 1 WHERE linkName= '$z'");
}
?>
<?
/* declare some relevant variables */
$hostname = "localhost";
$username = "root";
$password = "********";
$userstable = "names";
$tableLinks = "links";
$dbName = "senior";
/* make connection to database */
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
$query = "SELECT views FROM $tableLinks WHERE linkType = 'main'";
$result = MYSQL_QUERY($query);
$views = mysql_result($result,$i,"views");
$views=$views+1;
mysql_query("UPDATE $tableLinks SET views = '$views' WHERE linkType = 'main'");
PRINT "This form of navigation has been viewed ";
PRINT "$views";
PRINT " times";
PRINT "<BR><BR>";
$queryV = "SELECT views FROM $userstable WHERE linkName = 'cats'";
$queryC = "SELECT clicks FROM $userstable WHERE linkName = 'cats'";
$resultV = MYSQL_QUERY($queryV);
$resultC = MYSQL_QUERY($queryC);
$views = mysql_result($resultV,$i,"views");
$clicks = mysql_result($resultC,$i,"clicks");
$views=$views+1;
mysql_query("UPDATE $userstable SET views = '$views' WHERE linkName = 'cats'");
PRINT "This page has been accessed or reloaded ";
PRINT "$views";
PRINT " times";
PRINT "<BR><BR>";
PRINT "This system won't work however since the counter is not tracking from what link this page was accessed from";
PRINT "<BR><BR>";
PRINT "However, this could be a rudamentry system for setting a heirarchy within each separate type of navigation.";
PRINT "<BR><BR>";
PRINT "Clicks = $clicks";
PRINT "<BR><BR>";
?>
<a href="cats.php" OnClick="clickcount($usertable, $clicks, cats)";>clik me</a>
</html>
<?php
?>
Thank you to anyone willing to help any little bit at all. |
|
#2
|
|||
|
|||
|
Freddy,
I've been looking at the code... Can't seem to find anything wrong with the PHP side of things.. But I'm wondering if this line has something to do with it: Code:
?> <a href="cats.php" OnClick="clickcount($usertable, $clicks, cats)";>clik me</a> </html> You're referring to PHP variables ($usertable, $clicks, and cats)... But cats is missing the $ and you're also referencing the variables OUTSIDE of the PHP code... Try something like this: Code:
?> <a href="cats.php" OnClick="clickcount(<?php echo($usertable, $clicks, $cats ?>)";>clik me</a> [/code] If that doesn't work, revert to your original code, but use the $ for the "cats" variables. Hope that helps.
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
Oh man, thank you so much.
![]() I'll give that a shot tonight and see how that goes. Really, MUCH appreciated. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > UPDATE $variable OnClick? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|