vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How to get info from database? (https://vborg.vbsupport.ru/showthread.php?t=157712)

T_Richardson 09-13-2007 05:23 AM

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.

Eikinskjaldi 09-13-2007 11:08 AM

Quote:

Originally Posted by T_Richardson (Post 1338115)
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.

T_Richardson 09-13-2007 05:26 PM

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'] . " ";
?>


Kirk Y 09-13-2007 05:50 PM

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.

T_Richardson 09-13-2007 05:56 PM

Quote:

Originally Posted by Kirk Y (Post 1338480)
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?

Kirk Y 09-13-2007 05:59 PM

Here's the article: https://vborg.vbsupport.ru/showthread.php?t=119350

T_Richardson 09-13-2007 06:10 PM

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?

Opserty 09-13-2007 07:23 PM

You need something like
PHP Code:

$newsq $db->query_read("SELECT * FROM `clan_news`");
while(
$row $db->fetch_array($newsq))
{
    
$news .= ' '$row['clan_news'] .' ';



T_Richardson 09-13-2007 07:40 PM

Thanks, it's working correctly now.


All times are GMT. The time now is 05:13 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.01195 seconds
  • Memory Usage 1,733KB
  • 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
  • (3)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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