Jump to content


Photo

Need help with arrays


  • Please log in to reply
2 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 19 April 2006 - 12:35 PM

while($row = mysql_fetch_assoc($result))
{
foreach($row as $field => $value)
{
if($field != "purchaseID")
{
$items[$n][$field]=$value;
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);
$items[$n]["name"]=$row[0]." ".$row[1];
}
}
}
$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.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 02:48 PM

[!--quoteo(post=366389:date=Apr 19 2006, 12:35 PM:name=OriginalSunny)--][div class=\'quotetop\']QUOTE(OriginalSunny @ Apr 19 2006, 12:35 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
while($row = mysql_fetch_assoc($result))
{
foreach($row as $field => $value)
{
if($field != "purchaseID")
{
$items[$n][$field]=$value;
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);
$items[$n]["name"]=$row[0]." ".$row[1];
}
}
}
$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:

$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'
   ),

...

~ D Kuang

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 19 April 2006 - 08:55 PM

this will show you what's in the items array

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


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users