MikeDXUNL Posted June 9, 2008 Share Posted June 9, 2008 http://phpfi.com/322985 Using that code ^^ my database ends up looking like below: can someone help figure out how to loop it correctly so achimg doesn't repeat? Quote Link to comment https://forums.phpfreaks.com/topic/109328-need-help-with-loop/ Share on other sites More sharing options...
.josh Posted June 9, 2008 Share Posted June 9, 2008 Didn't you already ask this in another thread? You are updating achimg with $img_link which is an iteration of $new_img_link which is supposed to be an array but here: $new_m = strrchr($m[0], '/'); $new_img_link[] = $new_m; strrchr starts at the last occurance of the needle in the haystack and returns from there until the end of the haystack; that is, a string is being returned, so your $new_img_link is not really an array. Well, it's an array with 1 position, which makes it a glorified variable. So your foreach loop isn't doing squat but iterating once. Quote Link to comment https://forums.phpfreaks.com/topic/109328-need-help-with-loop/#findComment-560806 Share on other sites More sharing options...
MikeDXUNL Posted June 9, 2008 Author Share Posted June 9, 2008 Nope, my other thread was about skipping every image I believe. But is there anyway of producing a correct result? I've been switching loops placement and where the mysql_query goes and where the $i++ goes... nothing has resolved me problem Quote Link to comment https://forums.phpfreaks.com/topic/109328-need-help-with-loop/#findComment-560815 Share on other sites More sharing options...
.josh Posted June 9, 2008 Share Posted June 9, 2008 Is $m supposed to be an array? Did you mean to put a loop around that 2 line code of yours I posted, iterating the position in $m? Because if so, that should probably solve your issues. Quote Link to comment https://forums.phpfreaks.com/topic/109328-need-help-with-loop/#findComment-560820 Share on other sites More sharing options...
MikeDXUNL Posted June 9, 2008 Author Share Posted June 9, 2008 i dont think so because if I do just <?php foreach ($new_img_link as $img_link) { echo $img_link; } ?> that outputs 50 different results of which I am looking for. i dont see what looping those to lines would do but repeat code that is already in an array. Quote Link to comment https://forums.phpfreaks.com/topic/109328-need-help-with-loop/#findComment-560822 Share on other sites More sharing options...
.josh Posted June 9, 2008 Share Posted June 9, 2008 umm..hmm. I don't really see how that loop could possibly be giving you 50 different results...I mean, the code you posted in that link clearly shows you making $new_img_link an array with only one position...have you changed your code somehow since then? But regardless, you have your query outside the foreach loop, so no matter how many positions are in that array, $img_link is going to be the last iteration of that loop, and your query is going to insert that last iteration value on every single iteration on your outer foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/109328-need-help-with-loop/#findComment-560829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.