Jump to content

Archived

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

OriginalSunny

Need help with arrays

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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
this will show you what's in the items array

[code]echo '<pre>', print_r ($items, true), '</pre>';[/code]

Share this post


Link to post
Share on other sites

×

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.