PDA

View Full Version : Need a specific Number of MySQL-Fields


Dragonspell
09-07-2002, 11:52 PM
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:

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


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

$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
print ("$data[test".$i."]");
generates an "" output, but I know that there's data in $data[test1].
Here's the proof:
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:

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
Originally posted by Hoffi
Try the following:

eval ("\$output = \"\$data[test".$i."]\";");
print ($output);


:banana::banana:IT WORKS:banana::banana:

ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
ThankyouThankyouThankyouThankyouThankyouThankyou
:D