Log in

View Full Version : Newbie question..


Oblivion Knight
05-12-2004, 06:45 PM
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:
$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:
$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:
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:
$recentdisplaylimit = $vboptions['journals_recentdisplaylimit'];And then 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 $recentdisplaylimit");

But I received a MySQL error:
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
$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
the t-string error could've been fixed by doing this
$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
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
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$moo = 'baa';
echo '$moo<br />' . "$moo";

will result in $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: