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
chris12295
Forum Contributor
Posts: 113 Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:
Post
by chris12295 » Thu Feb 13, 2003 4:34 pm
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їid]") or die(mysql_error());
$results=mysql_num_rows($query);
//if the ad has pictures
if($results > 1) {
while($row3 = mysql_fetch_array($query, MYSQL_ASSOC)) {
$count += 1;
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";
}
}
}
//ad has no pictures
else {
$picYes = "<span class="midSecondaryHead">No Pictures</span><br><br><br>";
}
echo "</table>";
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Thu Feb 13, 2003 5:33 pm
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 » Fri Feb 14, 2003 12:02 am
bah, my bad sorry
Last edited by
aybra on Fri Feb 14, 2003 10:43 am, edited 1 time in total.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Fri Feb 14, 2003 2:33 am
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.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Fri Feb 14, 2003 2:43 am
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