Page 1 of 1
Foreach mindbender
Posted: Tue May 12, 2009 3:20 pm
by Auselan
I decided to remove this post as it potentially revealed coding i don't want in the public arena
Re: Foreach mindbender
Posted: Tue May 12, 2009 4:03 pm
by Reviresco
Not exactly sure what you're trying to do, but here is an example ---
Say you retrieve your two fields, id and contacts, as arrays, and you want to display them as links:
Code: Select all
$query1="SELECT id, contactname FROM contact WHERE practice='$practicename'";
$result1=mysql_query($query1);
while ($get_info = mysql_fetch_row($result1)){
$id[] = $get_info[0];
$contact[] = $get_info[1];
}
foreach($contact as $k=>$v) {
echo '<a href="example.php?id=' . $id[$k] . '">' . $v . '</a><br />';
}
Re: Foreach mindbender
Posted: Mon Jul 27, 2009 3:23 am
by Auselan
magnificent - thankyou so much dude. with that code it's working almost exactly as I had wanted it to, but still haven't got my brain around it.
The final stumbling block is that it is stacking all contacts now rather than ditching the previous practice contacts as it loops e.g. image where the two contacts for (Not a GP surgery) appear in 19 Beaumont Street's entry as well. Do you know how to do this?
Re: Foreach mindbender
Posted: Mon Jul 27, 2009 3:35 am
by turbolemon
You may need to unset the arrays ($id & $content) created with the while loop after each of the "surgeries", as assigning to array[] just adds an element to the end of the list.
Re: Foreach mindbender
Posted: Mon Jul 27, 2009 3:10 pm
by Auselan

thanks a bundle dude. might seem simple, but I'm a total beginner - muchos thankyous guys