News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Query no worky

Started by Krashsite, February 08, 2015, 12:22:56 AM

Previous topic - Next topic

Sir Osis of Liver

Trying to add a query to function setupMenuContext()
in Subs.php, but any query I use, including legit queries copied from earlier in the file, cause white screen.  What am I missing?
Even if the whole world has forgotten,
The song remembers when.

                              - H. Prestwood

live627

QuoteWhat am I missing?
the code :P

Arantor

Do you really need to run the query every single page, even for guests?
Holder of controversial views, all of which my own.


Sir Osis of Liver

I want to light up the 'Gallery' menu button on main menu when a new image has been posted within the past 24 hours, using something like this -



SELECT MAX(last_pic_date) FROM {db_prefix}gallery_cat



... and then this -



'title' => '<span style="color: '.$color.';"> Gallery </span>',



Overhead is not a concern, this is my family board and not very busy.  I've done something similar in the gallery source code to light up the gallery names and comment totals when new items are posted, but that only affects the gallery template.

Even if the whole world has forgotten,
The song remembers when.

                              - H. Prestwood

Arantor

So you have a query that you haven't provided, being spliced into some part of a file, which we don't know how you're trying to do it...?

Having established the viability of premise, if you could provide the code that isn't working, maybe we'll be able to help you?
Holder of controversial views, all of which my own.


Sir Osis of Liver

Didn't save the code, no time to redo it now, but the basic problem is that any query I insert here -



/// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.

>>>>>>>>>

if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated'])



causes a blank screen.  Will put something more intelligible together if I have time tonight.

Even if the whole world has forgotten,
The song remembers when.

                              - H. Prestwood

NanoSector

White screens can occur if you have a parse error and do not have display_errors enabled in php.ini, check that first.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Sir Osis of Liver

Not a parse error, they give me internal server errors.  Copied a query from further up in Subs.php and got same result.  Have to toddle off, will tinker with it tonight.
Even if the whole world has forgotten,
The song remembers when.

                              - H. Prestwood

Arantor

You realise that if you post the *actual* code you're trying to use, you might get somewhere.
Holder of controversial views, all of which my own.


Sir Osis of Liver

This works -



/// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.

$result = mysql_query("SELECT MAX(poster_time) FROM smf_messages");
$row = mysql_fetch_array($result);
$last_post = $row['MAX(poster_time)'];

echo '<br />$last_post = ' . $last_post;
exit;

if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated'])



... but anything I do with $smcFunc['db_query'] causes white screen.
Even if the whole world has forgotten,
The song remembers when.

                              - H. Prestwood

vbgamer45

Is $smcFunc in the globals of the function?
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Sir Osis of Liver

No, it's not.  Knew I was missing something obvious.  Will give it a try soon as I figure out why my math function is working backwards.  Thx.
Even if the whole world has forgotten,
The song remembers when.

                              - H. Prestwood

Sir Osis of Liver

Ok, this works -



/// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.

$result = $smcFunc['db_query']('','
SELECT MAX(last_pic_date)
FROM {db_prefix}gallery_cat');

$row = mysql_fetch_array($result);
$last_pic_date = $row['MAX(last_pic_date)'];

if ($last_pic_date > (time() - 86400))
$color = '#FF8300';



It lights up the menu button with this -



// [SMF Gallery] button
'gallery' => array(

'title' => '<span style="color: '.$color.';">'. $txt['smfgallery_menu'] . '</span>',
'href' => $scripturl . '?action=gallery',
'show' => $context['allow_smfgallery_view'],
'icon' => '',
),



What's the difference between using $smcFunc['db_query'] and mysql_query?
Even if the whole world has forgotten,
The song remembers when.

                              - H. Prestwood

Arantor

$smcFunc contains proper methods for safe querying  unlike mysql_query. Also, when PHP removes the mysql_query function (scheduled after 5.5), it is possible to cleanly replace everything in $smcFunc.
Holder of controversial views, all of which my own.


NanoSector

mysql_fetch_array

You should probably be using the functions inside $smcfunc here too.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Advertisement: