Foreach mindbender
Moderator: General Moderators
Foreach mindbender
I decided to remove this post as it potentially revealed coding i don't want in the public arena
Last edited by Auselan on Tue Dec 11, 2012 2:54 pm, edited 2 times in total.
Re: Foreach mindbender
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:
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
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?
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?
- Attachments
-
- Capture.JPG (38.86 KiB) Viewed 83 times
- turbolemon
- Forum Commoner
- Posts: 70
- Joined: Tue Jul 14, 2009 6:45 am
- Location: Preston, UK
Re: Foreach mindbender
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.