vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   populating a table from a database (https://vborg.vbsupport.ru/showthread.php?t=93725)

Vitesse 08-06-2005 07:17 AM

populating a table from a database
 
K guys, i've managed some of my coding ok so far but now im seriously stuck and need lots of help :ermm:

I've got a separate page based on the forum style which is a quarter-mile timechart. I need to populate a table with the contents of a database and havnt a clue how to do it :o

basically the table in the template has 3 columns, Username, Car, Quarter-mile time. The database table (it's a separate mysql database) has one table "quartermile" which has 4 fields which are

1. "ID", Int, auto-incremented, primary field
2. "username", varchar,
3. "car", varchar
4. "qttime", Decimal

I just need to get the entire content of that DB table displayed on a table on my site (it's my test site so cock-ups/errors wont cause any harm).

Any assistance will be immensely appreciated as i've been working on this all day, every day for the last week and seem to be getting nowhere fast.

Many thanks

------------------------------- EDIT ------------------------------------
OK, worked out how to retrieve the data from the database just need some instruction on how to get the data into a table properly :)

Anyone????


all i want to do is retrieve all rows and put them in a table

Vitesse 08-07-2005 02:43 PM

^Bump

The only thing that's holding me back from going any further is not getting the data from the DB into the table. Surely someone must know how to do this?

Marco van Herwaarden 08-07-2005 07:26 PM

It will depend on if you will be using vB Templates or plain html from your php-script.

Marco van Herwaarden 08-07-2005 07:31 PM

Basic setup would be:
PHP Code:

$result $db->query_read("SELECT * FROM " TABLE_PREFIX "tablename");
while (
$myrow =$db->fetch_array($result))
{
.....
here either eval the template, or echo your fields



Vitesse 08-07-2005 08:23 PM

I'm going to use the template rather than just in HTML as it would look better that way (i hope) that's the bit i couldnt figure out, if i were doing it in just php and outputting as html i'd make a loop for the number for total rows in the DB but how would i do the equivalent and get it into the template?

Marco van Herwaarden 08-07-2005 08:34 PM

PHP Code:

$mydatabits '';
$result $db->query_read("SELECT * FROM " TABLE_PREFIX "tablename");
while (
$myrow =$db->fetch_array($result))
{
eval(
'$mydatabits .= "' fetch_template('mydatabit') . '";');
}
eval(
'print_output("' fetch_template('mypage') . '");'); 

Create 2 templates:
'mydatabit':
Holeding the detail lines, maybe something like:
Code:

<tr><td>Username: $myrow[username]</td><td>Car: $myrow[car]</td></tr>
And a second template to hold the rest of the page, including the <table> tags etc. In between the <table> and the </table> you will place the variable $mydatabits

Vitesse 08-07-2005 09:31 PM

Thankyou ever so much :) :) it worked like a charm, eternally grateful to you sir


All times are GMT. The time now is 01:33 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.01128 seconds
  • Memory Usage 1,727KB
  • 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
  • (1)bbcode_code_printable
  • (2)bbcode_php_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