[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

"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] = ????


0
NeerDeth
Asked:
NeerDeth
1 Solution
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now