[SOLVED] from db into array
Moderator: General Moderators
[SOLVED] from db into array
I want to select a set of id's from a db with a query, which i have. Once selected i need them put into an array which can then be used to loop through. I can create an array to loop through myself, but can't seem to create one using a result set from the db. Any ideas?
Last edited by rsmarsha on Wed Dec 14, 2005 4:04 am, edited 1 time in total.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
$array=array();
then....
and that should make your populated array....then to loop through it immediatly afterwards
tada?:-D
then....
Code: Select all
$i=0;
while ($test=mysql_fetch_object($myqueryresult))
{
$array[i]=$test->id;
$i++;
}Code: Select all
for($L=0;$L<$i;$L++)
{
echo $array[L];
}Got this so far.
Doesn't seem to echo the id's.
Code: Select all
if ($_POST['type']=='pc')
{
$set = "SELECT cat_id FROM categories WHERE cat_type!='lp'";
$sq = mysql_query($set) or die("Query $set Failed".mysql_error());
}
else
{
$set = "SELECT cat_id FROM categories WHERE cat_type!='pc'";
$sq = mysql_query($set) or die("Query $set Failed".mysql_error());
}
$array=array();
$i=0;
while ($type_row=mysql_fetch_object($sq))
{
$array[i]=$type_row->cat_id;
$i++;
}
for($L=0;$L<$i;$L++)
{
echo 'test: '.$array[L].'';
}this line...
...should be...
and this line...
...should be...
Code: Select all
$array[i]=$type_row->cat_id;Code: Select all
$array[$i]=$type_row->cat_id;Code: Select all
echo 'test: '.$array[L].'';Code: Select all
echo 'test: '.$array[$L].'';-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm