Michdd Posted October 26, 2008 Share Posted October 26, 2008 Inside of a while($row = mysql_fetch_array( $result )) { } I have this: foreach( $seperatedreply as $nbr => $reply){ foreach( $seperatedreplyurl as $nbr2 => $replyurl) { foreach( $seperatedreplyname as $nbr3 => $replyname) { $size2 = getimagesize($replyurl); list($width, $height) = $size2; if($width > "100") { $width = "100"; } if($height > "100") { $height = "100"; } echo ">>"; echo "<table>"; echo "<tr><td>"; echo "Posted by "; echo $replyname; echo "<br />"; if($replyurl != "") { echo "<a href=\"".$replyurl."\">"; echo "<img src=\"".$replyurl."\" width=\"".$width."\" hieght=\"".$hieght."\" >"; echo "</a>"; } echo $reply; echo "</td></tr>"; echo "</table>"; } } } It's the only way I could think of producing what I want, but the problem I having is that.. It's repeating that 6 times, in unwanted fashions, accept for the first time (which is right), the rest is repeating with some parts missing. I know why it's doing this, just I don't know how to fix it. Can anyone help me? Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/ Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 Can you show us some sample results of print_r($seperatedreply)? Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674785 Share on other sites More sharing options...
Michdd Posted October 26, 2008 Author Share Posted October 26, 2008 Can you show us some sample results of print_r($seperatedreply)? fyi, Seperatedreply is after it's taken from the database, then explode() was preformed on it. An example of it would be text that a user inputted for a reply. You can see the site here: http://www.theforbiddengates.net/project/r/ That's supposed to be 1 post/1reply, but as you can see, as I said before everything past the 1first line with the reply is incorrect, and shouldn't be there. Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674788 Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 Could you show us the code that prepares $seperatedreply? It's really hard (read: impossible) to write a script without knowing the input. Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674791 Share on other sites More sharing options...
Michdd Posted October 26, 2008 Author Share Posted October 26, 2008 $seperatedreply = explode("-seperate-", $getreply); $seperatedreplyurl = explode("-seperate-", $getreplyurl); $seperatedreplyname = explode("-seperate-", $replyname); Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674793 Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 At least what I understand from your code.... Why not do a for() loop the same length as one of the arrays? <?php $count = count($seperatedreply); for($i = 0; $i < $count; ++$i) { $size2 = getimagesize($seperatedreplyurl[$i]); list($width, $height) = $size2; if($width > 100) { $width = 100; } if($height > 100) { $height = 100; } echo ">>"; echo "<table>"; echo "<tr><td>"; echo "Posted by "; echo $seperatedreplyname[$i]; echo "<br />"; if($seperatedreplyurl[$i] != "") { echo "<a href=\"".$seperatedreplyurl[$i]."\">"; echo "<img src=\"".$seperatedreplyurl[$i]."\" width=\"".$width."\" height=\"".$height."\" >"; echo "</a>"; } echo $seperatedreply[$i]; echo "</td></tr>"; echo "</table>"; } ?> Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674795 Share on other sites More sharing options...
Michdd Posted October 26, 2008 Author Share Posted October 26, 2008 At least what I understand from your code.... Why not do a for() loop the same length as one of the arrays? <?php $count = count($seperatedreply); for($i = 0; $i < $count; ++$i) { $size2 = getimagesize($seperatedreplyurl[$i]); list($width, $height) = $size2; if($width > 100) { $width = 100; } if($height > 100) { $height = 100; } echo ">>"; echo "<table>"; echo "<tr><td>"; echo "Posted by "; echo $seperatedreplyname[$i]; echo "<br />"; if($seperatedreplyurl[$i] != "") { echo "<a href=\"".$seperatedreplyurl[$i]."\">"; echo "<img src=\"".$seperatedreplyurl[$i]."\" width=\"".$width."\" height=\"".$height."\" >"; echo "</a>"; } echo $seperatedreply[$i]; echo "</td></tr>"; echo "</table>"; } ?> Hm, that seems to almost make it work. See: http://theforbiddengates.net/project/r/ It doesn't repeat it all those times, accept it repeats it once with "Posted by" alone the second time. Any way to fix that? Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674798 Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 That means your database entry has a trailing -seperate-. eg "something-seperate-somethingelse-seperate-" so there's an extra array entry. (this is a total guess) just change $count = count($seperatedreply); to $count = count($seperatedreply)-1; if I am right it should work, if not... well I don't know, let's cross that bridge when we come to it. Either way, it will fix your problem, but I'd still like to know if my guess was right Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674801 Share on other sites More sharing options...
Michdd Posted October 26, 2008 Author Share Posted October 26, 2008 That means your database entry has a trailing -seperate-. eg "something-seperate-somethingelse-seperate-" so there's an extra array entry. (this is a total guess) just change $count = count($seperatedreply); to $count = count($seperatedreply)-1; if I am right it should work, if not... well I don't know, let's cross that bridge when we come to it. Either way, it will fix your problem, but I'd still like to know if my guess was right You guess it right. But, if there was a -seperate- at the start of the database field, would it cause the same problem, just as the front of it? Or would it work okay like that? Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674802 Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 Same problem, just the blank entry would be at the beginning. Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674803 Share on other sites More sharing options...
Michdd Posted October 26, 2008 Author Share Posted October 26, 2008 Oh, yea I figured that, and I'm really tired and I didn't notice your suggestion to change that one line. And yes, it does work, thanks a lot! Link to comment https://forums.phpfreaks.com/topic/130131-logic-help/#findComment-674806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.