1

I'm trying to pull information and display it in a table form on a php page i have a mysql DB i have something like below which list everything in the table but i would like to have it only show certain information if a certain data is present

Columns i would like to display on the page

object_id, Name and, wish.

but i only want rows from the DB to be displayed if a column

wishState is ("pending")

this is what i have scoured around to find so far wich brings everything in.

$query="SELECT * FROM MY_TABLE";
$results = mysql_query($query);

while ($row = mysql_fetch_array($results)) {
echo '<tr>';
    foreach($row as $field) {
        echo '<td>' . htmlspecialchars($field) . '</td>';
    }
    echo '</tr>';
}

Thanks Ryan

2
  • you should mysqli_* functions. Mysql is depracated and will no longer be supported in the future. Commented Aug 20, 2014 at 1:06
  • See my answer it solves your question using mysqli for added security Commented Aug 20, 2014 at 1:13

2 Answers 2

1

The entire ext/mysql PHP extension, which provides all functions named with the prefix mysql_, is officially deprecated as of PHP v5.5.0 and will be removed in the future. So please don't use mysql_* anymore.

//selects data where wish is pending 
$query="SELECT * FROM `MY_TABLE` WHERE `wish`='pending'";
$results = mysqli_query($your_db_connection, $query) or exit(mysqli_error());

while ($row = mysqli_fetch_array($results)) {

//show only object_id, name and wish
echo '<tr>';
    echo '<td>' . $row['object_id'] . '</td>';
    echo '<td>' . $row['name'] . '</td>';
    echo '<td>' . $row['wish']. '</td>';
echo '</tr>';
}
Sign up to request clarification or add additional context in comments.

Comments

0
$query="SELECT * FROM MY_TABLE WHERE `wish`='pending'";

That should work based on the information you gave us. WHERE tells the database to search for rows WHERE the column WISH is equal to "pending".

2 Comments

thank you so if the table actually shows ("pending") i could just put in '("pending")' ?
It should if its exactly the same

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.