Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-06-2005, 07:17 AM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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

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
Reply With Quote
  #2  
Old 08-07-2005, 02:43 PM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

^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?
Reply With Quote
  #3  
Old 08-07-2005, 07:26 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It will depend on if you will be using vB Templates or plain html from your php-script.
Reply With Quote
  #4  
Old 08-07-2005, 07:31 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Reply With Quote
  #5  
Old 08-07-2005, 08:23 PM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #6  
Old 08-07-2005, 08:34 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #7  
Old 08-07-2005, 09:31 PM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thankyou ever so much it worked like a charm, eternally grateful to you sir
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:40 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.04418 seconds
  • Memory Usage 2,224KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete