PHP MySQL The Where Clause

Posted by tutor | Posted in PHP Tutorial | Posted on 18-12-2009-05-2008

0

WHERE clause is used to filter records, on the basis of some conditions.

Syntax

    SELECT column_name(s)
    FROM table_name
    WHERE column_name operator value

The following example selects all rows from the “Country” table where Country=’Poland’.

    For eg:

    <?php
    $conn = mysql_connect(“localhost”,”tutor”,”tutor123″);
    if (!$conn)
    {
    die(‘Could not connect: ‘ . mysql_error());
    }
    mysql_select_db(“my_db”, $conn);
    $result = mysql_query(“SELECT * FROM Country
    WHERE Country=’Poland’”);
    while($row = mysql_fetch_array($result))
    {
    echo $row['Country'] . ” ” . $row['Capital'];
    echo “<br />”;
    }
    ?>

    Output:

    Poland Warsaw

Write a comment

Twitter Users
Enter your personal information in the form or sign in with your Twitter account by clicking the button below.