View Full Version : [SOLVED] making this bit vbulletin friendly php mysql
Dr.CustUmz
03-24-2016, 05:26 AM
$query = $db->query_first( "select * from redirect where(url = '$drc_url')");
if ($query == false){
$hits = "1";
$query2 = $db->query_write( "INSERT INTO redirect (url,hits) VALUES('$drc_url','$hits')");
} else {
$hitquery = $db->query_first( "select hits from redirect where url = '$drc_url'");
$result = mysql_query($hitquery);
$hits = mysql_result($result, 0, "hits");
$query2 = $db->query_write( "update redirect set hits = hits+1 where url = '$drc_url'");
}
$db->query($query2);
cant seem to get the else to function properly
Call to undefined function mysql_query()
i know the result and hits variable need updated im just not sure how
mysql_ is depricated, and changing them to mysqli just breaks it worse =/
Well if I check your piece of code then you don't need those 3 lines at all:
$hitquery = $db->query_first( "select hits from redirect where url = '$drc_url'");
$result = mysql_query($hitquery);
$hits = mysql_result($result, 0, "hits");
They provide no functionality whatsoever.
query_first returns an array of the data from the first row by the way, so you can just use $hitquery['hits'].
nhawk
03-24-2016, 10:54 AM
cant seem to get the else to function properly
Call to undefined function mysql_query()
First problem, mysql isn't set up properly in PHP. Most likely you have mysqli active, not mysql.
OR, you haven't opened a mysql connection to the database.
$hitquery = $db->query_first( "select hits from redirect where url = '$drc_url'");
$result = mysql_query($hitquery);
$hits = mysql_result($result, 0, "hits");
$query2 = $db->query_write( "update redirect set hits = hits+1 where url = '$drc_url'");
Second problem, you already have the result in $hitquery and you're trying to query that result in
$result = mysql_query($hitquery);
$hitquery is not a valid mysql query. It is the value of hits from the database.
Dr.CustUmz
03-24-2016, 12:54 PM
$query = $db->query_first( "select * from redirect where(url = '$drc_url')");
if ($query == false){
$hits = "1";
$query2 = "INSERT INTO redirect (url,hits) VALUES('$drc_url','$hits')";
} else {
$hitquery['hits'];
$query2 = "update redirect set hits = hits+1 where url = '$drc_url'";
}
$db->query_write($query2);
seems to work ok just want to make sure it looks ok, still learning =)
(got to run to the DMV to renew tags and lic almost my birthday, be back shortly)
nhawk
03-24-2016, 02:11 PM
That should work but this isn't needed, it doesn't do anything...
$hitquery['hits'];
Here's how I would do it:
$query = $db->query_first("SELECT * FROM redirect WHERE url = '" . $drc_url . "'");
if (!$query){
$db->query_write("INSERT INTO redirect (url, hits) VALUES ('" . $drc_url . "', 1)");
} else {
$db->query_write("UPDATE redirect SET hits = hits + 1 WHERE url = '" . $drc_url . "'");
}
Dr.CustUmz
03-24-2016, 02:33 PM
ok now I want to relay those results back in an ordered manor
I have
$query = $db->query_first( "select * from redirect order by hits desc");
$result = MYSQL_QUERY($query);
$number = MYSQL_NUMROWS($result) or die (mysql_error());
$i = 0;
if ($number == 0) {
print "Nothing here";
}
elseif ($number >= 1) {
while ($i < $number){
$hits = mysql_result($result,$i,hits);
$url = mysql_result($result,$i,url);
if ($hits < 100){
$color = "$color100";
}
print "<div align=\"left\">";
print "<table COLS=3 border=\"0\" width=\"100%\"><tr><td ALIGN=LEFT with=\"400\"><b><a
href=\"$url\">$url</a></b></td>";
print "<td ALIGN=right WIDTH=\"60\"><b>$hits</b></td>";
print "<td align=left WIDTH=\"$hits\" BGCOLOR=\"$color\"> </td></tr>";
$i++;
print "</table>\n";
}
}
but again im having issues vbulletin(ifying) this, in red is the code i believe needs to be changed to work.
Dr.CustUmz
03-24-2016, 02:52 PM
FYI the end result will be something like this:
https://vborg.vbsupport.ru/attachment.php?attachmentid=154574&stc=1&d=1458834691
everything is ready database wise, just want to create an overall stats page and put the count next to links.
https://vborg.vbsupport.ru/attachment.php?attachmentid=154575&stc=1&d=1458834699
Dr.CustUmz
03-24-2016, 04:21 PM
this is the part i need help with =/
$query = "select * from redirect order by hits desc";
$result = MYSQL_QUERY($query);
$number = MYSQL_NUMROWS($result) or die (mysql_error());
$i = 0;
IF ($number == 0) {
PRINT "<CENTER><P><b>No Links tracked yet!</b></CENTER>";
}
ELSEIF ($number >= 1) {
WHILE ($i < $number){
$hits = mysql_result($result,$i,hits);
$url = mysql_result($result,$i,url);
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.