vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Need a specific Number of MySQL-Fields (https://vborg.vbsupport.ru/showthread.php?t=43290)

Dragonspell 09-07-2002 11:52 PM

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.

g-force2k2 09-08-2002 07:58 AM

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

Dragonspell 09-08-2002 09:12 AM

Ehm... no.

I've declared it (=5).

Dragomancer 09-10-2002 09:56 AM

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 !

Hoffi 09-10-2002 10:54 AM

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.

Dragomancer 09-10-2002 11:54 AM

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
:D


All times are GMT. The time now is 03:59 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.01073 seconds
  • Memory Usage 1,740KB
  • 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
  • (7)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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