Jump to content

Recommended Posts

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

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

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.