vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   changed order by, now this (https://vborg.vbsupport.ru/showthread.php?t=64081)

AN-net 04-19-2004 01:08 AM

changed order by, now this
 
ok i changed ORDER BY from DESC to ASC and now nothing shows up! why is it doing that! damn u php!!!!

assassingod 04-19-2004 01:10 AM

What's the exact code you're using?

filburt1 04-19-2004 01:20 AM

Quote:

Originally Posted by assassingod
What's the exact code you're using?

This is now the fourth time that we have had to ask the question. If you expect answers, YOU MUST ALWAYS POST THE CODE IN QUESTION AS WELL AS ANY ERRORS YOU GET.

AN-net 04-19-2004 01:27 AM

ok chill, i get no error messages just nothing shows

PHP Code:

        $fentries$DB_site->query("SELECT entry_id,entrytitle,entrytext,entrydate,entry_totalvotes,entry_totalrating,private,whocanview FROM ".TABLE_PREFIX."journal_entries WHERE journal_id='".$_REQUEST['j']."' AND entry_active='1' ORDER BY entrydate ASC");
                
$check$DB_site->num_rows($fentries);
                if(
$check=="0")
                {
                    
$entrybits$vbphrase['journalnoentries'];
                }
                else
                {
                    while(
$entry$DB_site->fetch_array($fentries))
                    {
                        
$count$DB_site->query_first("SELECT COUNT(*) AS comments FROM ".TABLE_PREFIX."journal_comments WHERE journal_id='".$_REQUEST['j']."' AND entry_id='".$entry['entry_id']."'");
                        
$entry['date']= vbdate($vboptions['dateformat'], $entry['entrydate'], 1);
                        
$entry['time']= vbdate($vboptions['timeformat'], $entry['entrydate']);
                        if(empty(
$entry['entry_totalrating']) OR empty($entry['entry_totalvotes']))
                        {
                            
$rating"0";
                        }
                        else
                        {
                            
$calcrating$entry['entry_totalrating']/$entry['entry_totalvotes'];
                            
$ratinground($calcrating);
                        }
                        
$textnl2br($entry['entrytext']);
                        
$wcv_entry$entry['whocanview'];
                        if(
$entry['private']=="1" AND in_array($bbuserinfo['userid'], explode(','$wcv_entry)))
                        {
                            eval(
'$entrybits .= "' fetch_template('journal_entrybits') . '";');
                        }
                        elseif(
$bbuserinfo['usergroupid']=="6")
                        {
                            eval(
'$entrybits .= "' fetch_template('journal_entrybits') . '";');
                        }
                        elseif(
$bbuserinfo['userid'] == $journalinfo['journalist_id'])
                        {
                            eval(
'$entrybits .= "' fetch_template('journal_entrybits') . '";');
                        }
                        elseif(
$entry['private']!="1")
                        {
                            eval(
'$entrybits .= "' fetch_template('journal_entrybits') . '";');
                        }
                        else
                        {
                            
$entrybits="";
                        }
                    }
                }
                eval(
'print_output("' fetch_template('journal_journalpage') . '");'); 


AN-net 04-19-2004 11:43 PM

anyone?

AN-net 04-21-2004 12:48 AM

please anyone?

AN-net 04-22-2004 09:12 PM

?????

Velocd 04-22-2004 10:40 PM

Do you mean the result is blank, or that it's not ordering the way you want it to?

Also never EVER place queries within a mysql_fetch_array loop, unless you want to call massive amounts of un-needed queries on your page. A simple LEFT JOIN in your first query can solve this.

Oh, if you had released this as a hack, people would get pissed to find out you left it easily open to MySQL injection. Never insert a direct $_REQUEST/$_GET/$_POST into a query, one could exit the query and call another statement to do malicious things, like drop your database. The vBulletin globalize() function is the first step to securing variables, and the second is to use addslashes() on ANY STRING VARIABLE inside a query.

Also, it's unnecessary to put single quotes around integer values in a SQL string. Reserve them for strings.

Bad:
PHP Code:

                    while($entry$DB_site->fetch_array($fentries))
                    {
                        
$count$DB_site->query_first("SELECT COUNT(*) AS comments FROM ".TABLE_PREFIX."journal_comments WHERE journal_id='".$_REQUEST['j']."' AND entry_id='".$entry['entry_id']."'"); 

Good
PHP Code:

// this will explicitly cast 'j' as an int, and you can now use it as $j
globalize($_REQUEST, array(
     
'j' => INT
));

$fentries $DB_site->query("
     SELECT journal_entries.entry_id, journal_entries.entrytitle, 
    journal_entries.entrytext, journal_entries.entrydate, 
     journal_entries.entry_totalvotes, journal_entries.entry_totalrating, 
    journal_entries.private, journal_entries.whocanview, 
    COUNT(journal_comments.*) AS comments 
    FROM "
.TABLE_PREFIX."journal_entries 
    LEFT JOIN journal_comments 
    USING (journal_id) 
    WHERE journal_id=
$j 
    AND entry_active=1     
     ORDER BY entrydate ASC
 "
);
 
 while (
$fentry $DB_site->fetch_array($fentries)
 {
     echo 
"Number of comments in this journal: $fentry[comments]";
 } 

This assumes your `journal_comments` has a `journal_id` field.

AN-net 04-22-2004 11:46 PM

oh didnt know i could do that with globalize, thanks;)

AN-net 04-24-2004 09:02 PM

im getting an mysql error using that code you gave me:)

Quote:

Originally Posted by mysql
Invalid SQL:
SELECT journal_entries.entry_id, journal_entries.entrytitle,
journal_entries.entrytext, journal_entries.entrydate,
journal_entries.entry_totalvotes, journal_entries.entry_totalrating,
journal_entries.private, journal_entries.whocanview,
COUNT(journal_comments.*) AS comments
FROM journal_entries
LEFT JOIN journal_comments
USING (journal_id)
WHERE journal_id='6'
AND entry_active='1'
ORDER BY entrydate ASC

mysql error: 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 '*) AS comments
FROM journal_entries
LEFT JOIN

you know wuts wrong?


All times are GMT. The time now is 02:09 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.02603 seconds
  • Memory Usage 1,779KB
  • 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
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete