Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2016, 05:26 AM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [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 =/
Reply With Quote
  #2  
Old 03-24-2016, 09:17 AM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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'].
Reply With Quote
Благодарность от:
Dr.CustUmz
  #3  
Old 03-24-2016, 10:54 AM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dr.CustUmz View Post
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 View Post
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.
Reply With Quote
  #4  
Old 03-24-2016, 12:54 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Reply With Quote
  #5  
Old 03-24-2016, 02:11 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That should work but this isn't needed, it doesn't do anything...
Code:
$hitquery['hits'];
Reply With Quote
Благодарность от:
Dr.CustUmz
  #6  
Old 03-24-2016, 02:24 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 "'");

Reply With Quote
  #7  
Old 03-24-2016, 02:33 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 03-24-2016, 02:52 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

FYI the end result will be something like this:


everything is ready database wise, just want to create an overall stats page and put the count next to links.
Attached Images
File Type: jpg 2016-03-24_11-48-02.jpg (56.3 KB, 0 views)
File Type: jpg 2016-03-24_11-50-27.jpg (73.6 KB, 0 views)
Reply With Quote
  #9  
Old 03-24-2016, 04:21 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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); 
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:49 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04383 seconds
  • Memory Usage 2,293KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_code
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (2)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (2)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete