SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: Columbo on September 24, 2013, 03:40:20 PM

Title: Starting Blocks
Post by: Columbo on September 24, 2013, 03:40:20 PM
Hi there,
I'd like to start using SP to display snippets of non forum information from my db,
eg.
In my smf database I have an additional table called "vehicles" with fields "name" & "car"
& the table will only ever have up to 20 lines

how would I display the table in a SP PHP block ?

Thanks
Columbo
Title: Re: Starting Blocks
Post by: [SiNaN] on September 25, 2013, 12:43:32 PM
Welcome to SimplePortal!

I don't know the database structure you have there but the code should look something similar to the following:

Code: [Select]
global $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT name, car
FROM {db_prefix}vehichles',
array(
)
);
$vehicles = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$vehicles[] = array(
'name' => $row['name'],
'car' => $row['car'],
);
}
$smcFunc['db_free_result']($request);

echo '
<table>
<tr>
<th>Name</th>
<th>Car</th>
</tr>';

foreach ($vehicles as $vehicle)
{
echo '
<tr>
<td>', $vehicle['name'], '</td>
<td>', $vehicle['car'], '</td>
</tr>';
}

echo '
</table>';
Title: Re: Starting Blocks
Post by: Columbo on September 25, 2013, 01:41:41 PM
Exactly what I need,
thank you very much SiNaN
 :thumbsup:
SimplePortal 2.3.8 © 2008-2024, SimplePortal