How to make table row appear when the flag is yes only?

what is flag in sql database
how to set flag in sql
create a table in html with 3 rows and 4 columns
sql: selecting rows where column value changed from previous row
postgresql constraint only one true
advanced html tables examples
html table row group example
sql add column with default value in select

the data wont show up, and i am not sure if my if elase statement is correct a not .

<?php 
require_once ('database.php'); 




$result = mysql_query("SELECT * FROM courselist WHERE flag");


if ((mysql_num_rows($result) == 'yes'){

echo "<table border='1' align='center' >
<tr>
<td align=center> <b>Name</b></td>
 <td align=center><b>price</b></td>
<td align=center><b>day</b></td>
 <td align=center><b>slot</b></td></td>";

while($data = mysql_fetch_row($result))
{   
echo "<tr>";
echo "<td align=center>$data[0]</td>";
echo "<td align=center>$data[1]</td>";
echo "<td align=center>$data[2]</td>";
echo "<td align=center>$data[3]</td>";


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

 ?>

if flag is yes display the row of data, if flag is no do not display the row of data

SELECT * FROM courselist WHERE flag

I believe this returns more than just one column, so I would go for changes like below. Also I've tested Your WHERE statement on my database. It returns nothing even if I do have data in given colum. You got to compare column to some value.

SELECT * FROM courselist WHERE <columnName>="yes"

Besides

mysql_num_rows

mysql_num_rows — Get number of rows in result

So it will not work

mysql_query

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. A resource is a special variable, holding a reference to an external resource.

This will also not work since You are holding resource there not actually fetched data.

You would need to change rest of code to something like for example:

require_once ('database.php'); 
$result = mysql_query("SELECT * FROM courselist WHERE flag");

while($data = mysql_fetch_row($result))
{   
echo "<table border='1' align='center' >
<tr>
<td align=center> <b>Name</b></td>
<td align=center><b>price</b></td>
<td align=center><b>day</b></td>
<td align=center><b>slot</b></td></td>";

echo "<tr>";
echo "<td align=center>$data[0]</td>";
echo "<td align=center>$data[1]</td>";
echo "<td align=center>$data[2]</td>";
echo "<td align=center>$data[3]</td>";
echo "</tr>";
}
  echo "</table>";

You might not need if in that case since if there are no records with 'yes', then these won't be fetched and so $data in while won't have them.

How to implement a 'default' flag that can only be set on a single row , SQL Server 2008 - Filtered unique index. CREATE UNIQUE INDEX IX_Foo_chk ON dbo.Foo(chk) WHERE chk = 'Y'. Allow yes or no entry only with Data Validation. The built-in function -- Data Validation in Excel can do you a favor for this problem. 1. Select the whole column by clicking at the column header, for instance, column A, and then click Data > Data Validation > Data Validation.

Why dont you try to pick only those records where flag is yes. And After that, you just need to loop through to all records. Check below code:

$result = mysql_query("SELECT * FROM courselist WHERE flag = 'yes' ");


if (mysql_num_rows($result) > 0) {
    echo "<table border='1' align='center' >
        <tr>
            <td align=center> <b>Name</b></td>
            <td align=center><b>price</b></td>
            <td align=center><b>day</b></td>
            <td align=center><b>slot</b></td>
        </tr>";

    while ($data = mysql_fetch_row($result)) {
        echo "<tr>";
        echo "<td align=center>$data[0]</td>";
        echo "<td align=center>$data[1]</td>";
        echo "<td align=center>$data[2]</td>";
        echo "<td align=center>$data[3]</td>";
        echo "</tr>";
    }
    echo "</table>";
}

Hope it helps you. And please take a note that mysql is deprecated. So you should change your database connecting function to mysqli or pdo.

Basics of Table — Programming with TROIA documentation, TROIA Platform, uses database tables just for storing data, so when we discuss tables in this section we don't mean In TROIA there are multiple ways of adding rows to a table. Another method is setting active row value with ACTIVEROW flag of table. ACTIVECOL, INTEGER, YES, Active column index of ui table. Show Yes for any positive value, No for zero. Gotcha: This trick initially shows Yes for periods where there is a purchase, but leaves the other periods blank. The Yes values appear. To display the No values, you have to replace the blanks in the pivot table with a zero. See " Replace Blanks in a Pivot Table with Zeroes." Replace blanks with zero.

I would definitely use the mysqli_ function set over the mysql_ function set so that your code will work no matter what version of php maybe used all the way through php 7+

    <?php

    $link = mysqli_connect ( 'localhost', 'username", 'password', 'database' );

    /* now... check the connection */

    if ( mysqli_connect_errno () )
    {

    echo 'The MySQL(i) Connection call failed: ' . mysqli_connect_error ();

    exit ();

    }

    if ( $result = mysqli_query ( $link, 'SELECT * FROM courselist WHERE flag;' ) )
    {
        /* (?), do we have any resulting row set(s) */

        if ( mysqli_num_rows ( $result ) > 0 )
        {
            /* we have (1) or more resulting set(s), so do this */

    echo "<table border='1' align='center' >
        <tr>
            <td align='center'>
                <b>
                    Name
                </b>
            </td>
            <td align='center'>
                <b>
                    price
                </b>
            </td>
            <td align='center'>
                <b>
                    day
                </b>
            </td>
            <td align='center'>
                <b>
                    slot
                </b>
            </td>
        </tr>";

            /* now... process each resulting row set */

            while ( $data = mysqli_fetch_assoc ( $result ) )
            {   

    echo "  <tr>
            <td align='center'>
                $data[0]
            </td>
            <td align='center'>
                $data[1]
            </td>
            <td align='center'>
                $data[2]
            </td>
            <td align='center'>
                $data[3]
            </td>
        </tr>";

            } // end while ( _fetch_assoc () )

    echo "</table>";

    /* now... free the result set */

    mysqli_free_result ( $result );

        } // end if ( _num_rows () )
} // end if ( _query () )

    /* now... close the connection */

    mysqli_close ( $link );

    ?>

10 SQL tricks that you didn't think were possible, The following 10 tricks show amazing functionality written in only a few lines of Most people just happen to insert a single-row-table most of the time, and thus don't realize Yes, you've guessed right. We want “LO” and “HI” to appear in ALL rows, not just at the “lower” and “upper” bounds of a series. that's the perfect use case for the "Query Only" (in group Source) flag which can be set on the column level of an Interactive Grid. From the online help Specify whether to exclude the column from DML operations. If set to Yes, Application Express will not utilize the column when executing Interactive Grid - Automatic Row Processing (DML).

Tables in HTML documents, Table rows: The TR element; Table cells: The TH and TD elements they make it possible for multi-modal wireless browsers with limited display capabilities (e.g., Web-enabled pagers and The CAPTION element is only permitted immediately after the TABLE start tag. T. Sexton 10 Espresso No J. Dinnen 5 Decaf Yes� Sort the table in view mode. When viewing a table on a page, you can sort it by clicking the sort icons in the header row. Screenshot: A colorful, sortable table. The default sort order is the order the table rows are listed in the editor. You can use the Cut row and Paste row icons to move rows around in the editor. Sticky table headers in

Customizing your table, it comes to tables, since you can only allocate so many rows to a page, It appears on the top right corner of the table with arrows that allow Stripe table: Striping a table make every other row on the table light gray. Replace country codes with flags: This topic also has its own dedicated article here. PS: Yes, document.write is a bit wierd, but I need this to create a small list of links that is going to appear on every page, so this is just a solution to a lot of future copying and pasting (I run the document.write script from a .js file, so I'll only have to update that in the future).

Table, A table displays a collections of data grouped into rows. Jill, Denied, None. Selectable Row. A table can have its rows appear selectable. Name, Status, Notes� This simple procedure adds a new row to the table, just as it would if you were working with a Word table. To add a new row inside a table, use the special insert options that appear only when you

Comments
  • guessing "flag" is from courselist? ... ``` if ($data['flag'] == "yes") { ```?
  • if ((mysql_num_rows($result) == 'yes') will never execute. Some int is never going to equal a string. That line will need to be if ((mysql_num_rows($result) > 0). Also, you are missing a closing }, probably from that same if statement.