PDA

View Full Version : trouble with echo


gavimobile
09-10-2007, 05:48 PM
hey folks,
my code which i recieved from a tutorial looks like this.

echo $row['Id'] . " " . $row['Type'];

it is following a while statement. what i wanted to do is simply be able to add echo tags where ever i want.
if you look in my code u will see the top part inside the php is all correct and working. it retrieved and displays the information my search has asked it to do. on the bottom i made an html table where i had echo tags inside which are NOT pulling any information from the db. so php on the top works, and the echo tags inside the table on the bottom are NOT working.

<?php require_once('Connections/connect.php'); ?>
<html>
<head></head>
<body>
<?php
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("baronre_baron", $con);
$result = mysql_query("SELECT * FROM propertyadd WHERE Type='$type' AND City='$city' AND Bed>='$beds' AND Neighborhood='$neighborhood' AND Price>='$minprice' AND Price<='$maxprice'");
while($row = @mysql_fetch_array($result))
{
echo $row['Id'] . " " . $row['Type'] . " " . $row['City'] . " " . $row['Bed'] . " " . $row['Neighborhood'] . " " . $row['Price'];
echo "<br />";
}
?>
<table width="748" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="93" height="100" rowspan="3"><?php echo $row['Picture1']; ?></td>
<td width="10" rowspan="3" valign="top">&nbsp;</td>
<td width="515" rowspan="3"><?php echo $row['Neighborhood']; ?>, <?php echo $row['City']; ?><br>
Beds: <?php echo $row['Bed']; ?> &nbsp;&nbsp;&nbsp;
Baths: <?php echo $row['Bath']; ?><br>
Living Space SQM: <?php echo $row['LivingSpace']; ?><br>
Outdoor Space SQM: <?php echo $row['OutdoorSpace']; ?><br>
Lot Size: <?php echo $row['LotSize']; ?><br>
Type: <?php echo $row['Type']; ?> &nbsp;&nbsp;
Status: <?php echo $row['Status']; ?></td>
<td width="117" align="right">
Price: $ <?php echo $row['Price']; ?><br>
Web ID #: <?php echo $row['Id']; ?></td>
</tr>
<tr>
<td width="117" align="right"><div align="right"><img src="Images/spots/view.gif" width="84" height="18"></div></td>
</tr>
<tr>
<td height="18">&nbsp;</td>
</tr>
<tr>
<td height="38" colspan="4"><hr></td>
</tr>
</table>
</body>
</html>

thanks folks

jjmackow
09-10-2007, 07:10 PM
Hi,
I noticed that you havea while loop in the main code and then following, you close the initial php script with '?>' and then proceed to make hte table markup outside of the php parser.

Could the issue be that you closed the 'while' loop which has '$row' as a variable within it, yet you are trying to refer to the $row variable i n the table but it is outside of the loop?

I haven't examined the entire code, but that's my first idea.

Hope it helps

davidj
09-10-2007, 07:48 PM
hi jjmackow

i tried to introduce gavimobile to handcoding PHP w while ago but its not a path he wanted to take. Your explanation maybe beyond gavimobiles understanding as he prefers using the wizards.

you are right of course

the code is outside the loop

gavimobile
09-10-2007, 08:50 PM
dj i was actually hopeing for u 2 reply.

this code was from a tutorial that i followed.
i got the search working on my own as u can see :-)
i gave up with dreamweaver u are right, but i stil have alot to learn