Title: tables in PHP
257335 - December 30, 2006 11:30 PM (GMT)
ok need some more help
<html>
<head>
<title>Retail</title>
<link rel="stylesheet" href="CSS.css" type="text/css" />
</head>
<body>
<div id="sidebar">
<img src="images/bigdoglogo.gif" width="215"height="75">
<div id="menu">
<a href="Home.html">Home</a>
<a href="Apartments.html">Apartments</a>
<a href="Industrial.html">Industrial</a>
<a href="Land.html">Land</a>
<a class="active" href="Retail.html">Retail</a>
<a href="OfficeSpace.html">Office Space</a>
<a href="AboutUs.html">About Us</a>
</div>
</div>
<div id="content">
<h1>RETAIL! </h1>
<br>
<br>
<?php
$con = mysql_connect("localhost","root","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("realestate", $con);
$result = mysql_query("SELECT * FROM estate
WHERE type='retail'");
echo "<table border='1'>
<tr>
<th>Address</th>
<th>Price</th>
<th>Baths</th>
<th>Bedrooms</th>
<th>State</th>
<th>City</th>
<th>Square Feet</th>
<th>County</th>
<th>Year Built</th>
<th>Description</th>
<th>Buy or Lease</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "<td>" . $row['Baths'] . "</td>";
echo "<td>" . $row['Bedrooms'] . "</td>";
echo "<td>" . $row['State'] . "</td>";
echo "<td>" . $row['City'] . "</td>";
echo "<td>" . $row['Squareft'] . "</td>";
echo "<td>" . $row['County'] . "</td>";
echo "<td>" . $row['YearBuilt'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td>" . $row['BuyorLease'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>
[/CODE]
im trying to out put the result of my sql quiery in an table but im geting this
[QUOTE]
Address Price Baths Bedrooms State City Square Feet County Year Built Description Buy or Lease "; while($row = mysql_fetch_array($result)) { echo ""; echo "" . $row['Address'] . ""; echo "" . $row['Price'] . ""; echo "" . $row['Baths'] . ""; echo "" . $row['Bedrooms'] . ""; echo "" . $row['State'] . ""; echo "" . $row['City'] . ""; echo "" . $row['Squareft'] . ""; echo "" . $row['County'] . ""; echo "" . $row['YearBuilt'] . ""; echo "" . $row['Description'] . ""; echo "" . $row['BuyorLease'] . ""; echo ""; } echo ""; mysql_close($con); ?>[CODE][/CODE]
patheticcockroach - December 31, 2006 06:54 PM (GMT)
Are you sure this is the exact source you use ? From the output you get I'd say there is an error around
| CODE |
";
while($row = mysql_fetch_array($result)) |
... but your code looks ok here... :blink:
257335 - January 1, 2007 04:38 AM (GMT)
| CODE |
<html> <head> <title>Retail</title> <link rel="stylesheet" href="CSS.css" type="text/css" /> </head> <body>
<div id="sidebar"> <img src="images/bigdoglogo.gif" width="215"height="75"> <div id="menu"> <a href="Home.html">Home</a> <a href="Apartments.html">Apartments</a> <a href="Industrial.html">Industrial</a>
<a href="Land.html">Land</a> <a class="active" href="Retail.html">Retail</a> <a href="OfficeSpace.html">Office Space</a> <a href="AboutUs.html">About Us</a> </div> </div>
<div id="content"> <h1>RETAIL! </h1> <br> <br> <?php
$con = mysql_connect("localhost","root","52al73"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("realestate", $con);
$result = mysql_query("SELECT * FROM estate WHERE type='retail'");
while($row = mysql_fetch_array($result)) { echo "<table border='1'>
<tr> <th>Address</th> <th>Price</th> <th>Baths</th> <th>Bedrooms</th> <th>State</th>
<th>City</th> <th>Square Feet</th> <th>County</th> <th>Year Built</th> <th>Buy or Lease</th> </tr>"; echo "<tr>"; echo "<td>" . $row['Address'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Baths'] . "</td>"; echo "<td>" . $row['Bedrooms'] . "</td>"; echo "<td>" . $row['State'] . "</td>"; echo "<td>" . $row['City'] . "</td>"; echo "<td>" . $row['Squareft'] . "</td>"; echo "<td>" . $row['County'] . "</td>"; echo "<td>" . $row['YearBuilt'] . "</td>"; echo "<td>" . $row['BuyorLease'] . "</td>"; echo "</tr>"; echo "</table>"; }
mysql_close($con);
?>
</body> </html> |
at the time yes it was the code i was useing i changed it a little.(i moved the table headed part in the while loop) from what i can tell it stops reading is as php here
| CODE |
echo "<table border='1'>
|
thats the last line of whats being read as php. im not sure if that help anything.
if not do you have any other way of how i should output the info?
patheticcockroach - January 1, 2007 07:36 AM (GMT)
Well, this code still looks ok (except that it should display column headers before each entry, and make one table per entry)... I really don't understand... :wacko: What's the output of this in your browser ? Don't you get any error message ?
When I do scripts like this, I use the same method to output my info...
257335 - January 1, 2007 08:09 AM (GMT)
yes i wanted to make one table per entry. this is so wierd it just randomly stops reading it as php code no there are not any error messages. oh well il come back to it after a couple days and try to get it to work again.
257335 - January 1, 2007 08:37 AM (GMT)
ok now we are getting somewhere. after yalls tip on the fact that php code is not read if the file is not .php made me realize why it was outputing what is was. after fixing it i get this
| CODE |
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Marquis Taliaferro\Desktop\web page\Retail.php on line 42 |
patheticcockroach - January 1, 2007 08:54 AM (GMT)
This error means that your SQL query fails
| CODE |
$result = mysql_query("SELECT * FROM estate WHERE type='retail'"); |
Try to run it in phpMyAdmin to figure out what's wrong (open your database and click on the "SQL" tab at the top, then enter a query to test it, for instance SELECT * FROM estate WHERE type='retail')
257335 - January 1, 2007 09:24 AM (GMT)
ok thanks
that fixed it. after i fixed the quiery it was not out puting any of the values that were supost to be filling the table but i fixed that by changing this
| CODE |
echo "<tr>"; echo "<td>" . $row['Address'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Baths'] . "</td>"; echo "<td>" . $row['Bedrooms'] . "</td>"; echo "<td>" . $row['State'] . "</td>"; echo "<td>" . $row['City'] . "</td>"; echo "<td>" . $row['Squareft'] . "</td>"; echo "<td>" . $row['County'] . "</td>"; echo "<td>" . $row['YearBuilt'] . "</td>"; echo "<td>" . $row['BuyorLease'] . "</td>"; echo "</tr>"; echo "</table>"; |
to this
| CODE |
echo "<tr>"; echo "<td>" . $row['address'] . "</td>"; echo "<td>" . $row['price'] . "</td>"; echo "<td>" . $row['baths'] . "</td>"; echo "<td>" . $row['bedrooms'] . "</td>"; echo "<td>" . $row['state'] . "</td>"; echo "<td>" . $row['city'] . "</td>"; echo "<td>" . $row['squarefeet'] . "</td>"; echo "<td>" . $row['county'] . "</td>"; echo "<td>" . $row['yearbuilt'] . "</td>"; echo "<td>" . $row['buyorlease'] . "</td>"; echo "</tr>"; echo "</table>"; |
when righting it at first i though it didn't matter since Mysql isn't case sensitive
patheticcockroach - January 1, 2007 04:57 PM (GMT)
Things like $row['buyorlease'] went through the PHP functions mysql_query and mysql_fetch_array so became case-sensitive here ;)