vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Newbie question.. (https://vborg.vbsupport.ru/showthread.php?t=65039)

Oblivion Knight 05-12-2004 06:45 PM

Newbie question..
 
I'm rather embarrased to post this, but hey - we all have to start somewhere..

I've tried to integrate some options in to the admincp, but in the code where I want them to take effect, it causes a MySQL error.. I dare say there are certain rules to comply with in SQL queries - I'm still learning things..

Anyway, one of the created variables are $vboptions['journals_recentdisplaylimit']


In this example, I wanted to apply it to this piece of code:
Code:

        $journal_recent_entries = $DB_site->query("SELECT j.enabled, u.username, e.journalid, e.title, e.entry, e.mood, e.np, e.timestamp, e.userid
                                FROM journal_entry e, journal j, user u
                                                                WHERE
                                                                e.userid = u.userid AND e.userid = j.userid
                                                                AND e.private = 0 AND j.enabled = 1
                                ORDER BY e.timestamp DESC
                                                                LIMIT 30");

And so, tried this:
Code:

        $journal_recent_entries = $DB_site->query("SELECT j.enabled, u.username, e.journalid, e.title, e.entry, e.mood, e.np, e.timestamp, e.userid
                                FROM journal_entry e, journal j, user u
                                                                WHERE
                                                                e.userid = u.userid AND e.userid = j.userid
                                                                AND e.private = 0 AND j.enabled = 1
                                ORDER BY e.timestamp DESC
                                                                LIMIT $vboptions['journals_recentdisplaylimit']");

But received a parse error:
Quote:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /var/www/html/getest/journal.php on line 818


I figured I'd try and get around this by applying it to a second variable, so tried this:
Code:

$recentdisplaylimit = $vboptions['journals_recentdisplaylimit'];
And then tried this code:
Code:

        $journal_recent_entries = $DB_site->query("SELECT j.enabled, u.username, e.journalid, e.title, e.entry, e.mood, e.np, e.timestamp, e.userid
                                FROM journal_entry e, journal j, user u
                                                                WHERE
                                                                e.userid = u.userid AND e.userid = j.userid
                                                                AND e.private = 0 AND j.enabled = 1
                                ORDER BY e.timestamp DESC
                                                                LIMIT $recentdisplaylimit");

But I received a MySQL error:
Quote:

Invalid SQL:
SELECT u.username, j.journalid, j.title, j.description, j.timestamp, j.userid, j.entries, j.views
FROM journal j
LEFT JOIN user u ON u.userid = j.userid
WHERE j.enabled = 1
ORDER BY j.views DESC
LIMIT
mysql error: You have an error in your SQL syntax near '' at line 7

mysql error number: 1064

Date: Wednesday 12th of May 2004 02:22:07 PM
Script: xxxx://xxx.xxxxxxxxxxxxxx.xx.xx/getest/journal.php?
Referer: xxxx://xxx.xxxxxxxxxxxxxx.xx.xx/getest/
Username: Oblivion Knight
Can anyone please tell me a way to get around these problems? :nervous:
Oh - and if the SQL query is messy, don't blame me.. I didn't write it.!

assassingod 05-12-2004 07:19 PM

$recentdisplaylimit isn't being set so that's why you are receiving a SQL error. You need to make sure that variable has a value.

Oblivion Knight 05-12-2004 07:55 PM

$recentdisplaylimit = $vboptions['journals_recentdisplaylimit'];

If $vboptions['journals_recentdisplaylimit'] is set as 10 in the admin cp, doesn't $recentdisplaylimit become 10?

assassingod 05-12-2004 07:59 PM

According to the query it's not. I'm not sure why it would do that.

Oblivion Knight 05-12-2004 08:11 PM

Bleh.. How annoying.. :tired:

assassingod 05-12-2004 08:21 PM

What do you get when you echo $vboptions['journals_recentdisplaylimit'] ?

Oblivion Knight 05-12-2004 08:53 PM

Sadly, nothing.. Nothing get's printed.
I used echo $vboptions['journals_recentdisplaylimit'];

sabret00the 05-12-2004 09:47 PM

the t-string error could've been fixed by doing this
PHP Code:

    $journal_recent_entries $DB_site->query("SELECT j.enabled, u.username, e.journalid, e.title, e.entry, e.mood, e.np, e.timestamp, e.userid
                                FROM journal_entry e, journal j, user u
                                WHERE
                                e.userid = u.userid AND e.userid = j.userid
                                AND e.private = 0 AND j.enabled = 1
                                ORDER BY e.timestamp DESC
                                LIMIT 
$vboptions[journals_recentdisplaylimit]"); 

:)

Oblivion Knight 05-12-2004 10:24 PM

Quote:

Originally Posted by sabret00the
the t-string error could've been fixed by doing this
PHP Code:

    $journal_recent_entries $DB_site->query("SELECT j.enabled, u.username, e.journalid, e.title, e.entry, e.mood, e.np, e.timestamp, e.userid
                                FROM journal_entry e, journal j, user u
                                WHERE
                                e.userid = u.userid AND e.userid = j.userid
                                AND e.private = 0 AND j.enabled = 1
                                ORDER BY e.timestamp DESC
                                LIMIT 
$vboptions[journals_recentdisplaylimit]"); 

:)

Yeah, I tried that originally and got the same MySQL error..
However, I wasn't sure if that would work in the first place or not. Now I know it would.. =)

$vboptions['journals_recentdisplaylimit'] doesn't seem to be pulling the value from the database when used in the journal.php file though.. Is there something else I need to add to get it to work?

Zachery 05-12-2004 10:31 PM

Quote:

Originally Posted by Oblivion Knight
Yeah, I tried that originally and got the same MySQL error..
However, I wasn't sure if that would work in the first place or not. Now I know it would.. =)

$vboptions['journals_recentdisplaylimit'] doesn't seem to be pulling the value from the database when used in the journal.php file though.. Is there something else I need to add to get it to work?

:P get on aim you mook

sabret00the 05-13-2004 12:36 PM

either that or try using normal brackets instead of square brackets for the .php files.

actually i think i'm talking ++++.

Oblivion Knight 05-14-2004 08:42 AM

1 Attachment(s)
Zachery gave me the attached file to try..
It appears that the variables aren't being parsed, instead of the values being echo'd, the variables themselves are.. It's a very strange problem, anyone know the fix? Also attached a screeny.

Yes, the variables exist and have been set in the admincp.. ;)

LeeCHeSSS 05-14-2004 03:30 PM

Regarding the test file you made in the above post, strings in single quotes do not get parsed, strings in double quotes do however

So
Code:

$moo = 'baa';
  echo '$moo<br />' . "$moo";

will result in
Code:

$moo
  baa

Anyway, are you by ANY chance doing this query INSIDE a function() declaration?

If so, make sure you add "global $vboptions;"
If not, add "var_dump($vboptions);" in front of the query and see what the output is.

Oblivion Knight 05-14-2004 05:06 PM

BINGO!

Thanks Danny, works a treat.! :glasses:


All times are GMT. The time now is 03:38 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.01424 seconds
  • Memory Usage 1,768KB
  • 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
  • (6)bbcode_code_printable
  • (2)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (14)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