vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   [solved] php/mysql issue (https://vborg.vbsupport.ru/showthread.php?t=322216)

Dr.CustUmz 03-24-2016 06:29 PM

[solved] php/mysql issue
 
as my initial question in my previous issue was solved i decided to open a new thread to avoid hijacking my own thread.

this is only part of the code, but im having issues getting this to work with vbulletin
PHP 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 
"<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);
                if (
$hits 10){ 


Dave 03-24-2016 07:07 PM

Can't test it, but this should work:
PHP Code:

$query $db->query("SELECT * FROM redirect ORDER BY hits DESC");

if (
$db->num_rows($query) == 0) {
    print 
"Nothing here";
} else {
    while(
$row $db->fetch_array($query)){
        if(
$row['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=\"" $row['url'] . "\">" $row['url'] . "</a></b></td>";
        print 
"<td align=right WIDTH=\"60\"><b>" $row['hits'] . "</b></td>";
        print 
"<td align=left WIDTH=\"" $row['hits'] . "\" BGCOLOR=\"" $color "\">&nbsp;</td></tr>";
        print 
"</table>\n";
    }


Some tips:
- Look at the functions of the vB_Database class in /includes/class_core.php, you will see what all the functions do and what parameters they require.
- query_first only returns the first row of the query, so it can not be used in this case since you want to loop through all of the results.
- Always escape PHP variables outside of the quotes, makes it easier to debug and to overview code.
- Write SQL syntax with uppercase characters.
- Only set new variables if you absolutely have to, makes code cleaner. :)

Dr.CustUmz 03-24-2016 07:39 PM

PERFECT!! and thanks for the tips, still learning so it all helps =)


All times are GMT. The time now is 03:52 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.01638 seconds
  • Memory Usage 1,727KB
  • 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
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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