Page 1 of 1

what is wrong with my code? the HTML TABLE is all screwed up

Posted: Thu Feb 13, 2003 4:34 pm
by chris12295
When this code runs, it prints the </TABLE> before it prints the table data code right below the opening <TABLE> tag, it prints when run:

Code: Select all

<table>
<tr colspan=3><td>Pictures</td></tr></table>
<tr><td rowspan='2'><a href='showpic.php?src=image_3e46c625628a7.jpg'><img src="users/images/image_3e46c625628a7.jpg" height=200 width=200 border=0></a></td>
<td><a href='showpic.php?src=image_3e46c62563f01.jpg'><img src="users/images/image_3e46c62563f01.jpg" height=100 width=100 border=0></a></td>
<td><a href='showpic.php?src=image_3e46c6256f2e4.jpg'><img src="users/images/image_3e46c6256f2e4.jpg" height=100 width=100 border=0></a></td></tr><tr>
<td><a href='showpic.php?src=image_3e46c62570819.jpg'><img src="users/images/image_3e46c62570819.jpg" height=100 width=100 border=0></a></td>
<td><a href='showpic.php?src=image_3e46c625758f5.jpg'><img src="users/images/image_3e46c625758f5.jpg" height=100 width=100 border=0></a></td>
Here is the code, why is the table messing up?

Code: Select all

<?
echo "<table>\n<tr colspan=3><td>Pictures</td></tr>";
//Get the pictures
		$query = mysql_query("SELECT * from pictures where ad_id = $_GET&#1111;id]") or die(mysql_error());
		$results=mysql_num_rows($query);
		//if the ad has pictures
		if($results > 1) &#123;
			while($row3 = mysql_fetch_array($query, MYSQL_ASSOC)) &#123;
				$count += 1;
				if($count == '1') &#123;
					$picYes .= "\n<tr><td rowspan='2'><a href='showpic.php?src=$row3&#1111;src]'><img src="users/images/". $row3&#1111;src] . "" height=200 width=200 border=0></a></td>\n";
					&#125;
				elseif($count % 3 == 0) &#123;
					$picYes .= "<td><a href='showpic.php?src=$row3&#1111;src]'><img src="users/images/". $row3&#1111;src] . "" height=100 width=100 border=0></a></td></tr><tr>\n";
					&#125;
				else &#123;
					$picYes .= "<td><a href='showpic.php?src=$row3&#1111;src]'><img src="users/images/". $row3&#1111;src] . "" height=100 width=100 border=0></a></td>\n";
					&#125;
				&#125;
				
			&#125;
			//ad has no pictures
			else &#123;
				$picYes = "<span class="midSecondaryHead">No Pictures</span><br><br><br>";
				&#125;
echo "</table>";

a couple of problems

Posted: Thu Feb 13, 2003 5:33 pm
by phpScott
There are a couple of things wrong that I can see.

You keep adding your results onto $picYes which is fine but I don't see where you echo or print out that variable between your table tags.

You can either add the openeing and closing table tags to your $picYes variable or you have to print out the $picYes variable before your closing table tag.

Don't forget your closing </tr> tag as well.

You else statement might also mess up your table as it is not in a table row tag.

phpScott

Posted: Fri Feb 14, 2003 12:02 am
by aybra
bah, my bad sorry

Posted: Fri Feb 14, 2003 2:33 am
by twigletmac
aybra wrote:

Code: Select all

<?php
$horsgoweeehaaaa = "Mule Deer Soup";
echo '<table> <tr> <td> ',$horsgoweeehaaaa,'</td></tr></table>';
// and you will get a table that prints out Mule Deer Soup,

// However if you use this...
echo "<table> <tr> <td> $horsgoweeehaaaa </td></tr></table>";
// you get thise...
// <table> <tr> <td> Mule Deer Soup </td></tr></table>

// wich kinda sucks... and is the problem you have.

?>
Both code snippets above will produce exactly the same result - a one row, one cell table containing the words 'Mule Deer Soup'.

Have a look at:
http://www.php.net/manual/en/language.types.string.php

Mac

Posted: Fri Feb 14, 2003 2:43 am
by twigletmac
Try the code below, basically you need to stop echoing the closing table tag before you echo the table contents:

Code: Select all

<?php 
$picYes = '<table>'."\n".'<tr colspan="3"><th>Pictures</th></tr>'; 
//Get the pictures
$sql = "SELECT * from pictures where ad_id = $_GET[id]";
$query = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>'); 
$results = mysql_num_rows($query); 

//if the ad has pictures 
if ($results > 1) { 
	while ($row3 = mysql_fetch_assoc($query)) { 
		++$count; 
		if ($count == 1) { 
			$picYes .= "\n".'<tr><td rowspan="2"><a href="showpic.php?src='.$row3['src'].'"><img src="users/images/'. $row3['src'].'" height="200" width="200" border="0"></a></td>'."\n"; 
		} elseif ($count % 3 == 0) { 
			$picYes .= '<td><a href="showpic.php?src='.$row3['src'].'"><img src="users/images/'.$row3['src'].'" height="100" width="100" border="0"></a></td></tr><tr>'."\n"; 
		} else { 
			$picYes .= '<td><a href="showpic.php?src='.$row3['src'].'"><img src="users/images/'.$row3['src'].'" height="100" width="100" border="0"></a></td>'."\n"; 
		} 
	} 
} else { 
	//ad has no pictures 
	$picYes .= '<span class="midSecondaryHead">No Pictures</span><br /><br /><br />'; 
} 
$picYes .= '</table>'; 

echo $picYes;
?>
Mac