"Fill Array From MySQL" Shortcut

$Query = "SELECT T1, T2, T3, T4, T5, T6
      FROM tblBlah";
$Result = mysql_query ($Query) or die(mysql_error());
$Row = mysql_fetch_array($Result);

      $T1 = $Row['T1'];
      $T2 = $Row['T2'];
      $T3 = $Row['T3'];
      $T4 = $Row['T4'];
      $T5 = $Row['T5'];
      $T6 = $Row['T6'];

if there a way to bring in each field into an array
like $T[1] = ????


NeerDethAsked:
Who is Participating?
 
ldbkuttyCommented:
mysql_fetch_array() is a combination of numeric + associative array. It holds both the indexes 0,..till 5 and T1,..til T6.

Look at the manual for its typical usages: http://www.php.net/mysql_fetch_array

However my question is since $Row itself an array, why do you want it assign for another array!
0
 
ldbkuttyCommented:
Not quite sure what you want, $Row itself an array. print_r($Row); might help you to understand the result!

However make a while loop like while($Row = mysql_fetch_array($Result)) instead of the assignment line to avoid unncessary problems when there is no record in the table.
0
 
NeerDethAuthor Commented:

So
$i = 1
$T[$i] = $Row[$i]

would work?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
NeerDethAuthor Commented:
:) oh yeah

LOL

it just clicked

thanks
0
 
Marvin_CarredoCommented:
$rec = Array();
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
      for ($col = 1; $col <= 6; $col++)
      {
            $temp_col = "T".$col;
                $rec[$row][$col] = $row[$temp_col];
       
      }
}
0
 
donelCommented:
Hi friend!

This is what i got success with all my project
$Query = "SELECT T1, T2, T3, T4, T5, T6
     FROM tblBlah";
$Result = mysql_query ($Query) or die(mysql_error());
$Num=mysql_num_rows($Result);
for($i=0;$i<$Num;$i++)
 {
 $Row[$i] = mysql_fetch_array($Result);
 }

//this you will got all array in $Row

print_r($Row);

thanks & best regards,
donel
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.