Jump to content

Need help with arrays


OriginalSunny

Recommended Posts

while($row = mysql_fetch_assoc($result))
{
foreach($row as $field => $value)
{
if($field != "purchaseID")
{
[b] $items[$n][$field]=$value;[/b]
if($field == "modelnum")
{
$sql_2 = "SELECT prodDesc FROM stock WHERE
modelnum = '$row[modelnum]'";
$result2 = mysql_query($sql_2,$cxn)
or die("sql_2: ".mysql_error($cxn));
$row = mysql_fetch_row($result2);
[b] $items[$n]["name"]=$row[0]." ".$row[1];[/b]
}
}
}
$n++;
}

From what i can understand it is going through the loop for the total number of rows(in the value $result) and then if the field is not equal to purchaseID it goes through to the next bit and so on... I dont understand what is being stores in the arrays which are in bold. Please could someone tell me.
Thanks.
Link to comment
https://forums.phpfreaks.com/topic/7836-need-help-with-arrays/
Share on other sites

[!--quoteo(post=366389:date=Apr 19 2006, 12:35 PM:name=OriginalSunny)--][div class=\'quotetop\']QUOTE(OriginalSunny @ Apr 19 2006, 12:35 PM) [snapback]366389[/snapback][/div][div class=\'quotemain\'][!--quotec--]
while($row = mysql_fetch_assoc($result))
{
foreach($row as $field => $value)
{
if($field != "purchaseID")
{
[b] $items[$n][$field]=$value;[/b]
if($field == "modelnum")
{
$sql_2 = "SELECT prodDesc FROM stock WHERE
modelnum = '$row[modelnum]'";
$result2 = mysql_query($sql_2,$cxn)
or die("sql_2: ".mysql_error($cxn));
$row = mysql_fetch_row($result2);
[b] $items[$n]["name"]=$row[0]." ".$row[1];[/b]
}
}
}
$n++;
}

From what i can understand it is going through the loop for the total number of rows(in the value $result) and then if the field is not equal to purchaseID it goes through to the next bit and so on... I dont understand what is being stores in the arrays which are in bold. Please could someone tell me.
Thanks.
[/quote]
Well, you would have an array named $items, something like this:

[code]$items = array (
   '0' => array (
      'field1' => 'value1',
      'field2' => 'value2',
      'field3' => 'value3',
      'name' => 'Some Thing'
   ),

   '1' => array (
      'field1' => 'value1 (for another row)',
      'field2' => 'value2',
      'field3' => 'value3',
      'name' => 'Some Thing Else'
   ),

...[/code]
Link to comment
https://forums.phpfreaks.com/topic/7836-need-help-with-arrays/#findComment-28598
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.