foreachloop going 8 times expected
edited to stop horizontal scroll
from the mysql cli (the cof was made as it is because i was having issues with the adding page trying to update when nothing was there)
Quote: mysql> select * from friends;
+-----+------+-----+-------------------+
| uid | fuid | fun | cof |
+-----+------+-----+-------------------+
| 1 | 1 | Neo | add damn you add! |
+-----+------+-----+-------------------+
1 row in set (0.99 sec)
mysql>
the section of code where i format this for display
<?php
foreach($desired as $friend){ # for each friend
$debug.='making desired'; // debug line
/* break up the info */
$fuid=$friend['fuid']; // friend's user id
$frnd=$friend['fun']; // friend's username
$cof=$friend['cof']; // user's comment on friend
$desires.=\" <tr><td><input type=\\"checkbox\\" name=\\"delf[]\\"
value=\\"$fuid\\"></td><td><a href=\\"profile.php?un=$frnd\\"
onClick=\\"alert('Your Comment on $frnd: $cof');\\"
target=\\"$frnd\\">$frnd</a></td></tr>\n\"; # make the display
}
}
?>
Quote: 1
1
1
1
N
N
a
a
the source of that
<tr><td><input type="checkbox" name="delf[]" value="1"></td><td>
<a href="profile.php?un=1" onClick="alert('Your Comment on 1: 1');" target="1">1
</td></tr>
<tr><td><input type="checkbox" name="delf[]" value="1"></td><td>
<a href="profile.php?un=1" onClick="alert('Your Comment on 1: 1');" target="1">1
</td></tr>
<tr><td><input type="checkbox" name="delf[]" value="1"></td><td>
<a href="profile.php?un=1" onClick="alert('Your Comment on 1: 1');" target="1">1
</td></tr>
<tr><td><input type="checkbox" name="delf[]" value="1"></td><td>
<a href="profile.php?un=1" onClick="alert('Your Comment on 1: 1');" target="1">1
</td></tr>
<tr><td><input type="checkbox" name="delf[]" value="N"></td><td>
<a href="profile.php?un=N" onClick="alert('Your Comment on N: N');" target="N">N
</td></tr>
<tr><td><input type="checkbox" name="delf[]" value="N"></td><td>
<a href="profile.php?un=N" onClick="alert('Your Comment on N: N');" target="N">N
</td></tr>
<tr><td><input type="checkbox" name="delf[]" value="a"></td><td>
<a href="profile.php?un=a" onClick="alert('Your Comment on a: a');" target="a">a
</td></tr>
<tr><td><input type="checkbox" name="delf[]" value="a"></td><td>
<a href="profile.php?un=a" onClick="alert('Your Comment on a: a');" target="a">a
</td></tr>
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 02:53 — 6th September 2003.
He has: 4,048 posts
Joined: Aug 2000
From the 2nd quote, I can tell that your foreach() looping through a single record within a recordset. How can I tell? mysql_fetch_array() returns an array with both numeric and associative keys. That's why everything is repeating itself twice.
Copy & Paste the code that populates $desired. $desired can't be an array of associative arrays. It's simply the first record of the recordset.
Mark Hensler
If there is no answer on Google, then there is no question.
m3rajk posted this at 16:20 — 6th September 2003.
They have: 461 posts
Joined: Jul 2003
<?php
$friendfind=mysql_query(\"SELECT * FROM friends WHERE uid='$uin'\", $db); # get friends
if(mysql_num_rows($friendfind)==0){
$ferr='<h1>No Desires/Lusts Found</h1>'; # error on getting friends
}else{ # get the desires
$ppl=mysql_num_rows($friendfind); # how many friends?
$debug.=\"ppl : $ppl\";
for($i=0;$i<$ppl;$i++){ # for each friend
$debug.='<br />fetching desire';
$desired=mysql_fetch_array($friendfind); # get the info
}
/* previously posted code */
}
?>
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 16:59 — 6th September 2003.
He has: 4,048 posts
Joined: Aug 2000
<?php
$friendfind = mysql_query(\"SELECT * FROM friends WHERE uid='$uin'\", $db); # get friends
if(mysql_num_rows($friendfind)==0) {
$ferr='<h1>No Desires/Lusts Found</h1>'; # error on getting friends
}
else { # get the desires
$ppl=mysql_num_rows($friendfind); # how many friends?
$debug.=\"ppl : $ppl\";
for ($i=0;$i<$ppl;$i++) { # for each friend
$debug .= '<br />fetching desire';
$desired[] = mysql_fetch_array($friendfind); # get the info
}
foreach($desired as $friend) { # for each friend
$debug .= 'making desired'; // debug line
/* break up the info */
$fuid=$friend['fuid']; // friend's user id
$frnd=$friend['fun']; // friend's username
$cof=$friend['cof']; // user's comment on friend
$desires.=\"<tr><td><input type=\\"checkbox\\" name=\\"delf[]\\"\"
.\"value=\\"$fuid\\"></td><td><a href=\\"profile.php?un=$frnd\\"\"
.\"onClick=\\"alert('Your Comment on $frnd: $cof');\\"\"
.\"target=\\"$frnd\\">$frnd</a></td></tr>\n\"; # make the display
}
}
?>
<?php
$friendfind = mysql_query(\"SELECT * FROM friends WHERE uid='$uin'\", $db); # get friends
if(mysql_num_rows($friendfind)==0) {
$ferr='<h1>No Desires/Lusts Found</h1>'; # error on getting friends
}
else { # get the desires
$ppl=mysql_num_rows($friendfind); # how many friends?
$debug.=\"ppl : $ppl\";
while ($friend=mysql_fetch_array($friendfind)) {
$debug .= 'making desired'; // debug line
/* break up the info */
$fuid=$friend['fuid']; // friend's user id
$frnd=$friend['fun']; // friend's username
$cof=$friend['cof']; // user's comment on friend
$desires.=\"<tr><td><input type=\\"checkbox\\" name=\\"delf[]\\"\"
.\"value=\\"$fuid\\"></td><td><a href=\\"profile.php?un=$frnd\\"\"
.\"onClick=\\"alert('Your Comment on $frnd: $cof');\\"\"
.\"target=\\"$frnd\\">$frnd</a></td></tr>\n\"; # make the display
}
}
?>
Mark Hensler
If there is no answer on Google, then there is no question.
m3rajk posted this at 22:10 — 6th September 2003.
They have: 461 posts
Joined: Jul 2003
i use * because i use each part of the feild. it works perfectly now. thanks.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.