Forum Moderators: coopster

Message Too Old, No Replies

pullout date from table

         

sqlnew

3:52 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



Hi,
I have a table with more than 50 columns. I named the column with order, for example, sub1, sub2, ....sub54. When extracting data from table, to save time, I wanted to use a while loop as following:

$i =1;
while($i<=54){
$qry = "select sub$i from table";
$result = mysql_query($result);
while($row = mysql_fetch_object($result)){
$sub = $row -> sub$i;//line 6
if($sub!=0){

.
.
}
}//end of inner while

$i++;
}//end of outer while

But I always get an error message on line 6 saying unexpected T_VARIABLE.

Can't I use variable $i as an index for sub in that line? I want to coculate the average for each column excluding the field of '0'. Any suggestions to efficiently extract data from such a table?

Thanks in advance.

sqlnew

3:54 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



Sorry, the topic should be pull out data from table. I apologize for the mistake.

fintan

4:19 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



Hi sqlnew why don't you select everything then run it. I mean

$qry = "select * from table";

sqlnew

4:40 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



Thank you. Yes, I thought about that. As I said in last post. I need calculate the average for each column ignoring the field with '0'. FOr example, if there are 3 entries and for sub1, the 3 entries are, 3, 3, 0. The average should be 3, not 2. So if I use "select * from table", when I calculate the average for each column, I still need extract data for each column one by one. For example:
while($row= mysql_fetch_object($result)){
$row -> sub1;
$row -> sub2;
.
.
.
$row -> sub54;
}

It is very tedious. I am wondering if I can use a while or for loop here, it'll save a lot pain. Do you know there is any way I can use a loop here?

Thanks again.