brem13 Posted May 23, 2010 Share Posted May 23, 2010 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 More sharing options...
-Karl- Posted May 23, 2010 Share Posted May 23, 2010 Going to need more information than that. Link to comment https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062255 Share on other sites More sharing options...
brem13 Posted May 23, 2010 Author Share Posted May 23, 2010 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 More sharing options...
-Karl- Posted May 23, 2010 Share Posted May 23, 2010 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 More sharing options...
brem13 Posted May 23, 2010 Author Share Posted May 23, 2010 both, basically it starts and ends a new table every result Link to comment https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062259 Share on other sites More sharing options...
-Karl- Posted May 23, 2010 Share Posted May 23, 2010 Read my above edit Link to comment https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062260 Share on other sites More sharing options...
-Karl- Posted May 23, 2010 Share Posted May 23, 2010 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 More sharing options...
brem13 Posted May 23, 2010 Author Share Posted May 23, 2010 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 More sharing options...
-Karl- Posted May 23, 2010 Share Posted May 23, 2010 No worries man, glad it's sorted. Mark the topic as solved (button is at the bottom left) to keep the forums clean. Link to comment https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062264 Share on other sites More sharing options...
brem13 Posted May 23, 2010 Author Share Posted May 23, 2010 i kno, i was just waitin to see if u'd reply, lol Link to comment https://forums.phpfreaks.com/topic/202657-keeps-repeating/#findComment-1062265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.