Jump to content

<table> keeps repeating


brem13

Recommended Posts

i have a function going through a database searching for people and i only want it to start and end the table tags once but it does it everytime, any help?

echo "<table border=1>";
    		if($year_diff >= $age1 && $year_diff <= $age2)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px valign=top><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age1=='Any' && $age2!='Any' && $year_diff <= $age2)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age2=='Any' && $age1!='Any' && $year_diff >= $age1)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age1=='Any' && $age2=='Any')
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    			
    		echo "</table>";

and here is where the fucntion is called

$result = mysql_db_query($database, $query) or die (mysql_error());
while($qry = mysql_fetch_array($result)){ 
	$user = $qry['username'];
	$year = $qry['year'];
	$month = $qry['month'];
	$day = $qry['day'];
	$status = $qry['relStatus'];
	$shortDesc = $qry['shortDesc'];
	$profPic = $qry['mainPic'];
	$birthday = birthday($year."-".$month."-".$day, $user, $profPic, $status, $shortDesc);

}//end while

 

Link to comment
https://forums.phpfreaks.com/topic/202657-keeps-repeating/
Share on other sites

im having the results from a search show up on another page, each result i want in a table format, but its making a new table for every result, not just a new row, i think the problem lies where i put the table tags but im not sure where to put them

 

$result = mysql_db_query($database, $query) or die (mysql_error());
while($qry = mysql_fetch_array($result)){ 
	$user = $qry['username'];
	$year = $qry['year'];
	$month = $qry['month'];
	$day = $qry['day'];
	$status = $qry['relStatus'];
	$shortDesc = $qry['shortDesc'];
	$profPic = $qry['mainPic'];
	$birthday = birthday($year."-".$month."-".$day, $user, $profPic, $status, $shortDesc);

}//end while

function birthday($birthday, $user, $profPic, $status, $shortDesc)
	{
		$age1 = htmlspecialchars($_POST['age1']);
	$age2 = htmlspecialchars($_POST['age2']);
	$pic = htmlspecialchars($_POST['pic']);
	if(!empty($hasPic) && $pic=='Yes')
		$doesHavePic = "Yes";
	elseif(empty($hasPic) && $pic=='No')
		$doesHavePic = "No";
    		list($birth_year,$birth_month,$birth_day) = explode("-",$birthday);
    		$year_diff  = date("Y") - $birth_year;
    		$month_diff = date("m") - $birth_month;
    		$day_diff   = date("d") - $birth_day;
    		if ($month_diff < 0) 
    			$year_diff--;
    		elseif (($month_diff==0) && ($day_diff < 0)) 
    			$year_diff--;
    			
    		list($width, $height, $type, $attr) = getimagesize("userImages/thumbs/".$profPic);

		if($height>=101)
			$size = 'height=75px';

		else
			$size = 'width=75px';

	//echo "<table border=1>";
    		if($year_diff >= $age1 && $year_diff <= $age2)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px valign=top><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age1=='Any' && $age2!='Any' && $year_diff <= $age2)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age2=='Any' && $age1!='Any' && $year_diff >= $age1)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age1=='Any' && $age2=='Any')
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    			
    		//echo "</table>";
     	}//end birthday

Link to comment
https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062257
Share on other sites

Is the </table> being repeated too? Or just <table>?

 

It's definitely the placement which is causing this. Pretty sure it's not the function. I mean the table shouldn't be in the function. As it's called in a while, so anything in the function will obviously be repeated, for each instance. So I'd try the table outside of the while. It may not produce the same results, however.

Link to comment
https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062258
Share on other sites

Try something like:

 

	
echo '<table>';
while($qry = mysql_fetch_array($result)){ 
$user = $qry['username'];
$year = $qry['year'];
$month = $qry['month'];
$day = $qry['day'];
$status = $qry['relStatus'];
$shortDesc = $qry['shortDesc'];
$profPic = $qry['mainPic'];
$birthday = birthday($year."-".$month."-".$day, $user, $profPic, $status, $shortDesc);
}//end while
echo '</table>';

Link to comment
https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062261
Share on other sites

k, changed it, and it works, i had tried it before and after the function but not the while, thanks bud :)

revised code is

echo "<table border=1>";
while($qry = mysql_fetch_array($result)){ 
	$user = $qry['username'];
	$year = $qry['year'];
	$month = $qry['month'];
	$day = $qry['day'];
	$status = $qry['relStatus'];
	$shortDesc = $qry['shortDesc'];
	$profPic = $qry['mainPic'];
	$birthday = birthday($year."-".$month."-".$day, $user, $profPic, $status, $shortDesc);

}//end while
echo "</table>";
function birthday($birthday, $user, $profPic, $status, $shortDesc)
	{
		$age1 = htmlspecialchars($_POST['age1']);
	$age2 = htmlspecialchars($_POST['age2']);
	$pic = htmlspecialchars($_POST['pic']);
	if(!empty($hasPic) && $pic=='Yes')
		$doesHavePic = "Yes";
	elseif(empty($hasPic) && $pic=='No')
		$doesHavePic = "No";
    		list($birth_year,$birth_month,$birth_day) = explode("-",$birthday);
    		$year_diff  = date("Y") - $birth_year;
    		$month_diff = date("m") - $birth_month;
    		$day_diff   = date("d") - $birth_day;
    		if ($month_diff < 0) 
    			$year_diff--;
    		elseif (($month_diff==0) && ($day_diff < 0)) 
    			$year_diff--;
    			
    		list($width, $height, $type, $attr) = getimagesize("userImages/thumbs/".$profPic);

		if($height>=101)
			$size = 'height=75px';
		else
			$size = 'width=75px';

	if($year_diff >= $age1 && $year_diff <= $age2)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px valign=top><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age1=='Any' && $age2!='Any' && $year_diff <= $age2)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age2=='Any' && $age1!='Any' && $year_diff >= $age1)
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    		elseif($age1=='Any' && $age2=='Any')
    			echo "<tr><td width=125px><a href=viewProfile.php?user=$user><img src=/userImages/thumbs/$profPic $size></a></td><td width=350px><a href=viewProfile.php?user=$user><font face='Trebuchet MS' size=3><b>".$user."</b></font></a> - <font face=tahoma size=2><i>$status</i><br>$shortDesc</font></td><td><font face=tahoma size=2>".$year_diff."</font></td></tr>";
    			
     	}//end birthday

Link to comment
https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062263
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.