0

hi there, i have a problem with this one, i want to input the data to an array, however, this doesn't work for me.

$resultSN = mysql_query("SELECT * FROM table ");	
	
$resultRowsSN_Count = mysql_query("SELECT COUNT(*) FROM table");
$count = mysql_result($resultRowsSN_Count,0,0);

while($row = mysql_fetch_array($resultSN))
{
   $machineName_O = $row['MachineName'];

     for ($i=0; $i<$count; $i++)
     {
	$machineName[$i] = $machineName_O;
	echo $i. " " . $machineName[$i] . "<br>";
    }
}

with the code above, it displays like this..example
$count = 3
$machineName = a, b, c

$i = 0 - 2

0 a
1 a
2 a
0 b
1 b
2 b
0 c
1 c
2 c

what i want to get is something like this:
$machineName[0] = a
$machineName[1] = b
$machineName[2] = c

could you help me please, i'm stock with this one..thanks in advance ^_^

Edited by xuexue: n/a

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by xuexue
0

Try the following.

<?php
$resultSN = mysql_query("SELECT * FROM table ") or die(mysql_error());
$count=mysql_num_rows($resultSN);
$machineName=array();
while($row = mysql_fetch_assoc($resultSN))
{
   $machineName_O = $row['MachineName'];

     for ($i=0; $i<$count; $i++)
     {
	$machineName[] = $machineName_O;
	echo $i. " " . $machineName_O . "<br>";
    }
}
?>
0

sir, the output is still the same..
0 a
1 a
2 a
0 b
1 b
2 b
0 c
1 c
2 c

0

U bothe are useing same technique. Don t use insertion and display in same loop

0

U bothe are useing same technique. Don t use insertion and display in same loop

I assumed the echo was being used as a test and that the insertation was the real deal. But yes recording mysql data into an array should be avoided whenever possible.

0

okei..sir's thanks for the advices..i already found a solution ^_^

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.