Forum Moderators: coopster
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #17' at line 1
In this code
$i = 1;
$aresult = mysql_query("SELECT * FROM mmh_pageviews where img = '$file'", $link) or die ("query 1: " . mysql_error());
$num_rows = mysql_num_rows($aresult) or die ("query 1: " . mysql_error());
echo $num_rows;
if ($num_rows == '0')
{
$bresult = mysql_query("SELECT user_id FROM mmh_file_storage where file_name = '$file'", $link) or die ("query 1: " . mysql_error());
$row1 = mysql_query($bresult);
if ($row1['userid']!= 0)
{
$insert = mysql_query("INSERT INTO mmh_pageviews (img, userid, pageviews) VALUES ('$file', '$row1[user_id]', '$i'", $link) or die ("query 1: " . mysql_error());
}
}
else
{
$cresult = mysql_query("SELECT pageviews FROM mmh_pageviews where img = '$file'", $link) or die ("query 1c: " . mysql_error());
$row2 = mysql_query($cresult) or die(mysql_error());
$views = $row2['pageviews'] + $i;
$result = mysql_query("UPDATE mmh_pageviews set pageviews = '$views' where img = '$file'", $link) or die ("query 1d: " . mysql_error());
echo 'Updated';
}
Cant seem to figure out why, this is how I am tracking pageviews, does anyone know a better way?
$aresult = mysql_query("SELECT * FROM mmh_pageviews where img = '$file'", $link) or die ("query 1: " . mysql_error());
$num_rows = mysql_num_rows($aresult) or die ("query 1: " . mysql_error());
echo "SELECT * FROM mmh_pageviews where img = '$file'";
Hab
if(@ mysql_num_rows($result) == 0) {
echo 'boo';
} else {
echo 'YAY';
}
thats the code I have now, it should return yay because xv82jx9pkuao2shheh6v.jpg is in the database, not sure why its not.
$q = mysql_query("SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'", $link);
$result = mysql_query($q);
Should be
$result = mysql_query("SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'", $link);
Thats my fault, I should have written the code following your conventions :)
This is the code
$q = mysql_query("SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'", $link);
$result = mysql_query($q);
if(@ mysql_num_rows($result) == 0) {
echo 'boo';
} else {
echo 'YAY';
}
With the same result, boo.
Any Ideas?
Thanks for all the help btw, I really appreciate it.
Dylan
$q = "SELECT * FROM mmh_pageviews where img = '$file'";
$result = mysql_query($q, $link);
if(@ mysql_num_rows($result) == 0) {
echo 'boo';
} else {
$row = mysql_query($q, $link);
echo 'a'.$row['pageviews'].'b';
$views = $row['pageviews'] + 1;
$result = mysql_query("UPDATE mmh_pageviews set pageviews = '$views' where img = '$file'", $link);
echo $result;
$row['pageviews'] returns nothing but does have a value in the database.
Anyhow, try this
mysql_connect(connection params);
mysql_select_db('db name');
$q = "SELECT * FROM mmh_pageviews where img = '$file'";
$result = mysql_query($q);
//.....etc
if that doesnt work, Im not really sure what to suggest...
Ifs this why my script wont connect?
Still havent gotten it.
The following is my current script, it displays absolutely nothing.
$q = "SELECT * FROM mmh_pageviews where img = '$file'";
$result = mysql_query($q);
if(@ mysql_num_rows($result) == 0) {
$bresult = "SELECT * FROM `mmh_file_storage` WHERE `file_name` = '$file'" or die ("query 1: " . mysql_error());
$row1 = mysql_fetch_array($bresult);
echo $row1['userid'];
if ($row1['userid']!= 0)
{
$insert = mysql_query("INSERT INTO mmh_pageviews (img, userid, pageviews) VALUES ('$file', '$row1[user_id]', '$i'", $link);
Echo 'Worked';
}
} else {
$bresult = "SELECT * FROM mmh_file_storage where file_name = '$file'";
$row = mysql_fetch_array($bresult);
echo $row['file_name'];
$result = mysql_query("UPDATE mmh_pageviews set pageviews = '$views' where img = '$file'");
}
<?php
$q = "SELECT * FROM mmh_pageviews WHERE img = '". $file ."'";
if(@ mysql_num_rows($q) == 0) {
$bresult = "SELECT * FROM mmh_file_storage WHERE file_name = '". $file ."'" or die ("query 1: " . mysql_error());
while ($row1 = mysql_fetch_array($bresult)) {
if ($row1['userid']!= 0)
{
$insert_data = mysql_query("INSERT INTO mmh_pageviews (img, userid, pageviews) VALUES ('". $file ."', '". $row1[user_id] ."', '". $i ."'");
echo 'Worked';
} else {
$bresult2 = "SELECT * FROM mmh_file_storage WHERE file_name = '$file'";
$row2 = mysql_fetch_array($bresult2);
echo $row2['file_name'];
$result_u = mysql_query("UPDATE mmh_pageviews SET pageviews = '". $views ."' WHERE img = '". $file ."'");
}
}
}
?>
[edited by: Habtom at 10:59 am (utc) on July 17, 2007]