vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   [SOLVED] making this bit vbulletin friendly php mysql (https://vborg.vbsupport.ru/showthread.php?t=322208)

Dr.CustUmz 03-24-2016 05:26 AM

[SOLVED] making this bit vbulletin friendly php mysql
 
Code:

$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
Code:

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 =/

Dave 03-24-2016 09:17 AM

Well if I check your piece of code then you don't need those 3 lines at all:
PHP Code:

  $hitquery =  $db->query_first"select hits from redirect where url = '$drc_url'");
  
$result mysql_query($hitquery);
  
$hits mysql_result($result0,  "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

Quote:

Originally Posted by Dr.CustUmz (Post 2567941)
cant seem to get the else to function properly
Code:

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.

Quote:

Originally Posted by Dr.CustUmz (Post 2567941)
Code:

  $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
Code:

$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

PHP Code:

$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...
Code:

$hitquery['hits'];

Dave 03-24-2016 02:24 PM

Here's how I would do it:

PHP Code:

$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
Code:

$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\">&nbsp;</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

1 Attachment(s)
FYI the end result will be something like this:
https://vborg.vbsupport.ru/attachmen...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/attachmen...1&d=1458834699

Dr.CustUmz 03-24-2016 04:21 PM

this is the part i need help with =/

PHP Code:

$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); 



All times are GMT. The time now is 04:03 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03908 seconds
  • Memory Usage 1,757KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_code_printable
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete