vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   PHP Widget and Database (https://vborg.vbsupport.ru/showthread.php?t=230342)

Ghostsuit 12-16-2009 08:29 PM

PHP Widget and Database
 
Hi,

I'm looking at the new PHP widget and trying to work out how to use it and if it's possible.

I'm wanting to connect to a database and then display rows from the database but I'm a little confused on how to use the $output part.

Can anyone enlighten me?

Here's a very rough of the idea

PHP Code:

$rows $db->query("
        SELECT *
        FROM gig
        "
);

echo 
'<table align="center" border="0" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%">';
echo 
'<tr class="tcat">';
echo 
'<td class="smallfont" align=center width="100"><b>Title</b></td>';
echo 
'<td class="smallfont" align=center><b>Date</b></td>';


while (
$row $db->fetch_array($rows))
{
echo 
'<tr class="alt2">';
echo 
'<td class="smallfont" align=center>' $row[gig_title] . '</td>';
echo 
'<td class="smallfont" align=center>' $row[date] . '</td>';
echo 
'</tr>';
}


echo 
'</tr>';
echo 
'</table>';
echo 
'<br />'


ragtek 12-16-2009 08:57 PM

Instead of echo use a template or put it into the $output variable!
You could also work with the ouput buffer.

PHP Code:

ob_start();
your code
$output 
.= ob_get_contents();
ob_end_clean(); 


Ghostsuit 12-16-2009 08:59 PM

Yeah I switched to output after reading a few threads but now getting this error message

Fatal error: Call to a member function fetch_array() on a non-object in /home/iycstaff/public_html/packages/vbcms/widget/execphp.php(171) : eval()'d code on line 17

Any ideas what's going wrong?

ragtek 12-16-2009 09:01 PM

use vB::$db-> instead of $db

Ghostsuit 12-16-2009 09:04 PM

Quote:

Originally Posted by ragtek (Post 1931872)
use vB:$db-> instead of $db

hmm throwing this up

Parse error: syntax error, unexpected ':' in /home/iycstaff/public_html/packages/vbcms/widget/execphp.php(171) : eval()'d code on line 19

ragtek 12-16-2009 09:42 PM

Sorry it should be vB::$db

Ghostsuit 12-16-2009 10:21 PM

That worked a peach, cheers. I wonder if I can pull anything from another database rather than the vbulletin one?


All times are GMT. The time now is 06:05 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.00994 seconds
  • Memory Usage 1,729KB
  • 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
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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