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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

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

Post 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>";
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

a couple of problems

Post 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
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post by aybra »

bah, my bad sorry
Last edited by aybra on Fri Feb 14, 2003 10:43 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Last edited by twigletmac on Fri Feb 14, 2003 2:44 am, edited 2 times in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply