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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.