1

I am using mysql database and I am looking for a way to display particular rows for column B when the column A value meets a specific criteria.

For Example in TBL_NAME: ColumnA = Months ColumnB = Holidays

Veterans Day Thanksgiving etc...

I would like to display on a page all the Holidays occurring in the month of November. I do not want to display any holidays in other months. Here is the code I have which is returning the error "Unknown column 'ColumnA' in 'where clause'."

<?php
    error_reporting(0);
    require 'db/connect.php';
    $Month=November;
    $data = $conn->query("SELECT * FROM TBL_NAME WHERE ColumnA=$Month") or         die($conn->error);
    $numRows = $data->num_rows;
?>

<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8" />
    <title>Database Connect</title>
</head>
<body>

    <?php
    // Print results to the page
    while($row = $data->fetch_assoc()) { ?>

    <p><?php echo $row['LinkName']; ?></p>

    <?php   } ?>

</body>
</html>
RAUSHAN KUMAR
  • 5,846
  • 4
  • 34
  • 70
dfs6353
  • 11
  • 1
  • 2
    show your database table schema and code too. – Gaurang Sondagar Jun 10 '17 at 05:35
  • Use prepared statements for your queries –  Jun 10 '17 at 05:51
  • Before jumping ahead you have a few syntax error that need to be assest (ei November needs to be encapsulaated in quotes). Also, as @AnuragDaolagajao mentioned, you might want to look into prepared statement before letting any user input inside your query. https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php. Welcome aboard, for your error, ColumnA simply does not exist in your table but we would need the scheam to tell you what i would be. Probably something like 'month' – Louis Loudog Trottier Jun 10 '17 at 06:23

0 Answers0