PDA

View Full Version : PHP Widget and Database


Ghostsuit
16 Dec 2009, 22:29
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

$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
16 Dec 2009, 22:57
Instead of echo use a template or put it into the $output variable!
You could also work with the ouput buffer.

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

Ghostsuit
16 Dec 2009, 22:59
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
16 Dec 2009, 23:01
use vB::$db-> instead of $db

Ghostsuit
16 Dec 2009, 23:04
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
16 Dec 2009, 23:42
Sorry it should be vB::$db

Ghostsuit
17 Dec 2009, 00:21
That worked a peach, cheers. I wonder if I can pull anything from another database rather than the vbulletin one?