Page 1 of 1

PHP/SQL not returning any results

PostPosted: 08. March 2010 12:06
by t4newman
When I run my php file to pull some records out of the database, now rows show up?

Any ideas?

<?php
include("utils.php");

open_db();

$adate = $_POST["arrivedate"];
$sleepers = $_POST["sleepnum"];
// echo "Arrival Date from form ".$adate."<br>";
// echo "Property that sleeps from form ".$sleepers."<br>";

//if ($adate=="") {
//}
if ($sleepers=="") {
//if ($sleepers=="") {
$sql = "SELECT * FROM properties";

} else {

$sql = "SELECT * FROM properties WHERE sleeps >= '".$sleepers."'";
echo "Searching for: ".$sleepers."<br>";
}

//echo $sql."<br>";


?>
<table width="800" border="1">
<?php
$num_rows = 0;
$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
{

?>
<tr>
<td> <?= $row['name']; ?> </td>
<td> <?= $row['area']; ?>
<td> <?= $row['city'] ?> </td>
<td> <?= $row['county'] ?> </td>
<td> <?= $row['postcode'] ?> </td>
<td> <?= $row['sleeps'] ?> </td>
<td> <?= $row['bedrooms'] ?> </td>

</tr>
<?php
$num_rows++;
}

close_db();

?>

</table>
<?=$num_rows?> results found.

Re: PHP/SQL not returning any results

PostPosted: 08. March 2010 12:29
by Stepke-DSL
Any error-messages?

Re: PHP/SQL not returning any results

PostPosted: 08. March 2010 12:31
by t4newman
No, none.

Re: PHP/SQL not returning any results

PostPosted: 08. March 2010 12:37
by Stepke-DSL
Try a "normal" query like this:

Code: Select all
$db = mysql_connect("localhost", "user", "pass");
mysql_select_db("dbname");
$res = mysql_query("SELECT * FROM `table`;");
echo mysql_num_rows($res);
mysql_close($db);

Re: PHP/SQL not returning any results

PostPosted: 08. March 2010 12:59
by WilliL
perhaps short_tags are switched "off"
try insted of <td> <?= $row['name']; ?> </td>
<td> <?php echo $row['name']; ?> </td>

Re: PHP/SQL not returning any results

PostPosted: 09. March 2010 06:52
by MC10
If you want to turn on short tags, edit line 226:

Code: Select all
short_open_tag = Off


Turn it "On". However, it is recommended that you use <?php ?>.