Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:06:55+00:00 2026-06-01T15:06:55+00:00

I need some help with some PHP and MySQL code. At the moment I

  • 0

I need some help with some PHP and MySQL code. At the moment I have a php file which displays the contents of a table in my database. I would like it to omit results that match “Not Booked”. So the file only shows me slots which are booked. Here is my code:

<link href="../css/pagestyle.css" rel="stylesheet" type="text/css" />
<?php 
include("../config.php");
include("functions.php");
if($logged["level"] == "HDJ" OR $logged["level"] == "SA") {

echo "<div class=\"head\">View Booked Slots</div>
<img src=\"../images/spacer.png\" width=\"5\" height=\"5\">
<div class=\"board\">Here you can view booked slots.</div>
<img src=\"../images/spacer.png\" width=\"5\" height=\"5\">
<table width=\"580px\" class=\"board\" border=\>";
      $order = "SELECT * FROM timetable";
      $result = mysql_query($order);
      while ($row=mysql_fetch_array($result)){
        echo ("<tr><td>$row[username]</td>");

        </tr>");
      }
      echo "
      </table>
"; 


    } else {
echo ("<div class=\"caution\">Access is denied.</div>");
}
?> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:06:57+00:00Added an answer on June 1, 2026 at 3:06 pm

    Modify the query not to pull them in the first place.

    $order = "SELECT * FROM timetable WHERE <the column> <> 'Not Booked';
    

    Replace <the column> with the correct column name in your table where Not Booked appears.

    It is often not advisable to intermix database logic and display logic as you have done here. Instead, you ought to do the query before outputting your table, and store its results in an array. Then loop over the array to display your table.

    $order = "SELECT * FROM timetable WHERE somecolumn <> 'Not Booked'";
    $result = mysql_query($order);
    
    // Error checking
    if (!$result) {
      // output error, take other action
    }
    else {
      while ($row=mysql_fetch_array($result)){
         // Append all results onto an array
         $rowset[] = $row;
      }
    }
    

    Later, loop over the array to output your values. Dont’ forget to escape it for HTML output with htmlspecialchars().

    foreach ($rowset as $row) {
      echo "<tr><td>" . htmlspecialchars($row['username']) . "</td></tr>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a noob with mysql and php, and need some help :) I have
I need help with some PHP code. I am retrieving data from a MySQL
Hi I need some help with the following scenario in php. I have a
Need your help with my PHP/MYSQL array. I have a php script that selects
I need some help please, I have a PHP page with a drop down
We have a loop in our PHP code which inserts rows into a table.
Need some help about with Memcache. I have created a class and want to
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.