Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-13-2007, 05:23 AM
T_Richardson T_Richardson is offline
 
Join Date: Jul 2006
Location: Canada
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to get info from database?

First let me explain, I have my main home page as a non-vbulletin, though I create those pages based vb templates with a guide posted here somewhere.

Now, I gave one of my members a Journalist job and he needs to be able to edit some news on that main page. I don't want to give him admincp access.

What I have done is made him a page to insert news in a form that inserts into the database.

Now, I would like to know how I can retrieve that data for it to show on the main page. I tried a database query, but get errors for a bad template. I tried to create a plugin (first time), but was unsuccessful.

Can someone guide me to how to do this?

Thanks,
T.
Reply With Quote
  #2  
Old 09-13-2007, 11:08 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by T_Richardson View Post
Now, I would like to know how I can retrieve that data for it to show on the main page. I tried a database query, but get errors for a bad template.
This makes no sense. Please explain. How does retrieving data cause a template error...what is a template error...and what error is it you are getting.
Reply With Quote
  #3  
Old 09-13-2007, 05:26 PM
T_Richardson T_Richardson is offline
 
Join Date: Jul 2006
Location: Canada
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

When I put the code to query info in the database in a template I get this template error:
Quote:
The following error occurred when attempting to evaluate this template:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/alliedte/public_html/includes/adminfunctions_template.php(3596) : eval()'d code on line 190

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
The code works fine on a stand alone php page.

And here's part of the query code:
PHP Code:
<?
$data=mysql_query("SELECT * FROM clan_news") or die(mysql_error());

$info=mysql_fetch_array( $data );

Print "".$info['clan_news'] . " ";
?>
Reply With Quote
  #4  
Old 09-13-2007, 05:50 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Because you can't place PHP code in a template. It must be executed in a plugin or in the file itself. You should also use the vB $db class for all your queries -- there's an article in the Articles forum that describes the process.
Reply With Quote
  #5  
Old 09-13-2007, 05:56 PM
T_Richardson T_Richardson is offline
 
Join Date: Jul 2006
Location: Canada
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Kirk Y View Post
Because you can't place PHP code in a template. It must be executed in a plugin or in the file itself. You should also use the vB $db class for all your queries -- there's an article in the Articles forum that describes the process.
Where is this articles forum?
Reply With Quote
  #6  
Old 09-13-2007, 05:59 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's the article: https://vborg.vbsupport.ru/showthread.php?t=119350
Reply With Quote
  #7  
Old 09-13-2007, 06:10 PM
T_Richardson T_Richardson is offline
 
Join Date: Jul 2006
Location: Canada
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice thank you.

Is there an article on how to create plugins for retrieving data?

I managed to create a plugin with this code:

PHP Code:
$news $vbulletin->db->query_read("SELECT * FROM clan_news") or die(mysql_error()); 
and the result when I put $news in the template is:
Quote:
Resource id #15
What code is missing?
Reply With Quote
  #8  
Old 09-13-2007, 07:23 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need something like
PHP Code:
$newsq $db->query_read("SELECT * FROM `clan_news`");
while(
$row $db->fetch_array($newsq))
{
    
$news .= ' '$row['clan_news'] .' ';

Reply With Quote
  #9  
Old 09-13-2007, 07:40 PM
T_Richardson T_Richardson is offline
 
Join Date: Jul 2006
Location: Canada
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, it's working correctly now.
Reply With Quote
Reply


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 04:28 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04387 seconds
  • Memory Usage 2,245KB
  • Queries Executed 11 (?)
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
  • (3)bbcode_php
  • (4)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_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