PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Thu Feb 27, 2003 7:21 am
Hi all,
I am trying to add elements to a multi dimensional array but get a syntax error on the line with array_push()... can anyone help?
John M
Here is the problem code:
Code: Select all
<?php
$x=0;
$gauge_array = array();
foreach($material_array as $target)
{
$sql="select gauge,mat_name
from gauge_info
where mat_name ='".$target."'
and loc_code='00'";
$qry=ifx_query($sql,$dbid);
while( $row=ifx_fetch_row($qry,"NEXT"))
{
array_push($gauge_array,$row['mat_name']=>$row['gauge']);
echo $gauge_array[$x]."<br>\n";
$x++;
}
ifx_free_result($qry);
}
?>
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Thu Feb 27, 2003 1:30 pm
I need to store the elements retirived in the query in one array.
So
$gauge_array[$row['mat_name']=$row['gauge']);
For each returned row from the querry.
John m
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Feb 27, 2003 2:01 pm
almost
Code: Select all
$gauge_array[$row['mat_name']]=$row['gauge'];is the value of each $row['mat_name'] unique for the whole select?
If not and you want to store all the
values (that would be a multidim-array) you can do something like
Code: Select all
if (isset($gauge_array[$row['mat_name']])
$gauge_array[$row['mat_name']][]=$row['gauge'];
else
$gauge_array[$row['mat_name']]= array($row['gauge']);Code: Select all
$gauge_array[$row['mat_name']][]=$row['gauge'];is equal to
Code: Select all
array_push($gauge_array[$row['mat_name']], $row['gauge']);so I guess you want the latter