1

When I tring to run this code any result not showing.Please help me

... some code is here...

$result = mysql_query("select  *  from dataform where  date between '" . $d1 . "' and '" . $d2 . "'");

if (!$result) {
    echo 'No result';
}
else{
    echo $d1;
    echo $d2;
    echo "<table class=\"hovertable\">";

    echo "
<tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\">";

    echo "<th>File No</th>";
    echo "<th>Manufactor</th>";
    echo "<th>Address</th>";
    echo "<th>Supplier</th>";
    echo "<th>Place Site</th>";
    echo "<th>Tender Ref</th>";
    echo "<th>Award No</th>";
    echo "</tr>";
    while ($row = mysql_fetch_array($result)) {
        echo "<tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\">";
        echo "<th>" . $row["fileno"] . "</th>";
        echo "<th>" . $row["manufacture"] . "</th>";
        echo "<th>" . $row["address"] . "</th>";
        echo "<th>" . $row["sup"] . "</th>";
        echo "<th>" . $row["placesite"] . "</th>";
        echo "<th>" . $row["tenderref"] . "</th>";
        echo "<th>" . $row["awardno"] . "</th>";
        echo "</tr>";
    }
2
  • 2
    Please stop writing new code with the ancient mysql_* functions. They are no longer maintained and community has begun the deprecation process. Instead you should learn about prepared statements and use either PDO or MySQLi. If you care to learn, here is a quite good PDO-related tutorial. Commented Aug 12, 2012 at 15:12
  • 1
    if(!$result){ echo mysql_error(); } Commented Aug 12, 2012 at 15:14

1 Answer 1

4

Try escaping your column DATE with backtick ` because it is a MySQL Data type. Another Suggestion is avoidusing string concatenation of your query because it is prone to mysql injection. Use PHP PDO or MYSQLi.

Example of using PDO:

<?php
$stmt = $dbh->prepare("SELECT * FROM dataform WHERE  `date` BETWEEN ? AND ?");

$stmt->bindParam(1, $d1);
$stmt->bindParam(2, $d2);

$stmt->execute();

$result = $stmt->fetchAll(PDO::FETCH_ASSOC); //Fetch all results in form of associative array.

?>

Remember to always sanitize your inputs.

UPDATE 1

You are not checking for condition in your WHILE loop. The way you are doing now is you are assign a value which is wrong. Try using ==

instead of

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

}

change it to this

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

}
Sign up to request clarification or add additional context in comments.

5 Comments

can you try running your query in management tool? eg mysql workbench or phpmyadmin and see if it return results.
one more thing, see my updated answer. instead of =, use == in your while loop.
@JohnTotetWoo: That's incorrect. The point is to check whether mysql_fetch_array() exists, and set it to $row at the same time. You aren't checking for equality.
@John Totet Woo, i tried to running my code in mysql workbench but the result is return.
please help me this is very important project,can you guess what is the fault?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.