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

Reply
 
Thread Tools Display Modes
  #1  
Old 09-07-2002, 11:52 PM
Dragonspell's Avatar
Dragonspell Dragonspell is offline
 
Join Date: Jan 2002
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Need a specific Number of MySQL-Fields

OK, here's my problem.

I've got a MySQL-table with several fields (fake1,fake2,test1,test2,test3,fake3). Now, I do only want to get the fields test1,test2,test3, but I only know by an Integer, how may there are (because the number of fields increases from time to time, so there will be test4, test5,..., test100 in near future etc).

With Non-Arrays (integer for example, $Test1, $Test2, $Test3 etc), I normaly would use something like this:

PHP Code:
for ($i=1;i<=$number_of_testfields;i++){
print (
"${"test".$count}");

With arrays it should look somthing like this, but I can't get this example work (PHP doesn't like the 3rd line):

PHP Code:
$data=$DB_site->query_first("SELECT * FROM Testtable");
for (
$i=1;$i<=$number_of_testfields;$i++){
  print (
"$data[test".$i."]");

I hope you understood my problem. Thanx for your help.
Reply With Quote
  #2  
Old 09-08-2002, 07:58 AM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

maybe because you didn't identify the variable:

PHP Code:
$number_of_testfields 
so that would just give it no effect resulting in now results? regards...

g-force2k2
Reply With Quote
  #3  
Old 09-08-2002, 09:12 AM
Dragonspell's Avatar
Dragonspell Dragonspell is offline
 
Join Date: Jan 2002
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ehm... no.

I've declared it (=5).
Reply With Quote
  #4  
Old 09-10-2002, 09:56 AM
Dragomancer's Avatar
Dragomancer Dragomancer is offline
 
Join Date: Jan 2002
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The Problem is, that the code
PHP Code:
print ("$data[test".$i."]"); 
generates an "" output, but I know that there's data in $data[test1].
Here's the proof:
PHP Code:
print $data[test1]; 
I get an output with "5".

I really need to run the first one, so plzzzzz help me !
Reply With Quote
  #5  
Old 09-10-2002, 10:54 AM
Hoffi's Avatar
Hoffi Hoffi is offline
 
Join Date: Nov 2001
Location: Germany
Posts: 342
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try the following:
PHP Code:
eval ("\$output = \"\$data[test".$i."]\";");
print (
$output); 
Otherwise you can read the Rownames with the SQL Describe Tablename all Rownames out of the Database and use them is this way.
Reply With Quote
  #6  
Old 09-10-2002, 11:54 AM
Dragomancer's Avatar
Dragomancer Dragomancer is offline
 
Join Date: Jan 2002
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Hoffi
Try the following:
PHP Code:
eval ("\$output = \"\$data[test".$i."]\";");
print (
$output); 
:banana::banana:IT WORKS:banana::banana:

ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
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 06:26 AM.


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.03834 seconds
  • Memory Usage 2,220KB
  • 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
  • (7)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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