Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 05-24-2006, 07:21 PM
thesatman thesatman is offline
 
Join Date: Aug 2002
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default db->query_read error

I'm going crazy trying to get a database query working-

I currently have the following in Hook Location : newpost_process working fine-

// Attachments credits
$attachs = $vbulletin->db->query_read("
SELECT dateline, thumbnail_dateline, filename, filesize, visible, attachmentid, counter,
IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail, thumbnail_filesize,
attachmenttype.thumbnail AS build_thumbnail, attachmenttype.newwindow
FROM " . TABLE_PREFIX . "attachment AS attachment
LEFT JOIN " . TABLE_PREFIX . "attachmenttype AS attachmenttype USING (extension)
WHERE posthash = '" . $post['posthash'] . "'
AND userid = " . $vbulletin->userinfo['userid'] . "
ORDER BY attachmentid
");

$attachcount11 = $vbulletin->db->num_rows($attachs);
$credits = $attachcount11 * 20 + 1;

-------------------------------
I now want to add the following WHERE-

AND extension = mid

So it only collects data in mid format but i just keep getting a database error all the time after adding that 1 line ??? Can anybody see a reason why ?

This is what i have when i get the database error-

// Attachments credits
$attachs = $vbulletin->db->query_read("
SELECT dateline, thumbnail_dateline, filename, filesize, visible, attachmentid, counter,
IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail, thumbnail_filesize,
attachmenttype.thumbnail AS build_thumbnail, attachmenttype.newwindow
FROM " . TABLE_PREFIX . "attachment AS attachment
LEFT JOIN " . TABLE_PREFIX . "attachmenttype AS attachmenttype USING (extension)
WHERE posthash = '" . $post['posthash'] . "'
AND userid = " . $vbulletin->userinfo['userid'] . "
AND extension = mid
ORDER BY attachmentid
");

$attachcount11 = $vbulletin->db->num_rows($attachs);
$credits = $attachcount11 * 20 + 1;

--------------------------------

Any help appreciated.
Reply With Quote
  #2  
Old 05-24-2006, 10:11 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

mid needs to be inside single quotes ;

AND extension = 'mid'
Reply With Quote
  #3  
Old 05-24-2006, 10:28 PM
thesatman thesatman is offline
 
Join Date: Aug 2002
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks for your help it was because the database as 2 tables caleed extension so i had to use-

WHERE attachment.extension = 'mid'

1 more small problem i need to use the following in the above-

$credit_filetypes = explode(',', $vbulletin->options['creditsys_filetypes']);

with-

WHERE attachment.extension = $credit_filetypes

But when i test it, i just get-

WHERE attachment.extension = array

so its not displaying what its taken from the explode ?? how would i do this ?

Thanks
Chris.
Reply With Quote
  #4  
Old 05-24-2006, 10:36 PM
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Location: Seattle
Posts: 1,719
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by thesatman
thanks for your help it was because the database as 2 tables caleed extension so i had to use-

WHERE attachment.extension = 'mid'

1 more small problem i need to use the following in the above-

$credit_filetypes = explode(',', $vbulletin->options['creditsys_filetypes']);

with-

WHERE attachment.extension = $credit_filetypes

But when i test it, i just get-

WHERE attachment.extension = array

so its not displaying what its taken from the explode ?? how would i do this ?

Thanks
Chris.
Explode turns a delimited string into an array. If $vbulletin->options['creditsys_filetypes'] is already a delimited string then you don't need to do anything but stick it in the query with an IN clause.

$sqlwhere = "WHERE attachment.extension IN(" . $vbulletin->options['creditsys_filetypes'] . ")";
Reply With Quote
  #5  
Old 05-25-2006, 04:52 AM
thesatman thesatman is offline
 
Join Date: Aug 2002
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your help the above outputs-

WHERE attachment.extension IN(jar,mid,mmf,mp3,mp4,wav,zip,3gp)

but i need it to output-

WHERE attachment.extension IN ('jar', 'mid' ,'mmf' ,'mp3' ,'mp4' ,'wav' ,'zip' ,'3gp')

chris
Reply With Quote
  #6  
Old 05-25-2006, 11:02 AM
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Location: Seattle
Posts: 1,719
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by thesatman
Thanks for your help the above outputs-

WHERE attachment.extension IN(jar,mid,mmf,mp3,mp4,wav,zip,3gp)

but i need it to output-

WHERE attachment.extension IN ('jar', 'mid' ,'mmf' ,'mp3' ,'mp4' ,'wav' ,'zip' ,'3gp')

chris
PHP Code:
$instr "'" str_replace(",""','"$vbulletin->options['creditsys_filetypes']) . "'";
$sqlwhere "WHERE attachment.extension IN(" $instr ")"
Reply With Quote
  #7  
Old 05-25-2006, 03:18 PM
thesatman thesatman is offline
 
Join Date: Aug 2002
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Many thanks, that did the trick. Dont think i'd have ever worked that one out without your help
Reply With Quote
  #8  
Old 05-25-2006, 03:21 PM
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Location: Seattle
Posts: 1,719
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by thesatman
Many thanks, that did the trick. Dont think i'd have ever worked that one out without your help
You're welcome. Glad it worked
Reply With Quote
  #9  
Old 05-26-2006, 06:04 PM
thesatman thesatman is offline
 
Join Date: Aug 2002
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi, Sorry got 1 more quick question. I'm using the following code to display the top 10 attachments-

$top_stats = array();
// TOP POSTERS
$top_posters = $db->query_read("SELECT * FROM ".TABLE_PREFIX."attachment ORDER BY counter DESC LIMIT 10");
while($top_poster = $db->fetch_array($top_posters))
{
eval('$top_stats[\'top_posters\'] .= "' . fetch_template('top_posters') . '";');
}
unset($top_poster);
$db->free_result($top_posters);
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_topposters') . '";');

And then i'm using the folling in the template-

$top_poster[filename]

the above is working and displays the attachment like-

filname.mp3

What i'd like to do is display the file name without the .mp3 extension, so like-

filename

What would i use to get rid of the .mp3

Thanks chris.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:17 AM.


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.04053 seconds
  • Memory Usage 2,240KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete