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 8891305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:42:29+00:00 2026-06-14T22:42:29+00:00

I have a table in PHP which displays the result of the MySQL query.

  • 0

I have a table in PHP which displays the result of the MySQL query.

The database table item_em has the price details of the items that are available in hypermarkets available in the database table hypermarket_em.There are some items that aren’t available in the hypermarket. Hence when i display the prices in the table I want those cells with no price as N/A.

So my problem is I tried a code myself to display message when database table field has no value.But it doesn’t work and I don’t get any error as well. Any ideas much appreciated. Thank you.

Here is my code

$res = mysql_query("SELECT h_id FROM hypermarket_em") or die(mysql_error());
echo"<tbody><tr>";
while($row = mysql_fetch_array( $res ))
{   
    $result = mysql_query("SELECT item_name FROM items_em WHERE h_id=".$row['h_id'])or die(mysql_error());
    while($drop_4 = mysql_fetch_array( $result ))
    {
         echo"<th scope=row>".$drop_4['item_name']."</th>";
         $rslt = mysql_query("SELECT price FROM items_em WHERE item_name='".$drop_4['item_name']."' and h_id=".$row['h_id'])or die(mysql_error());
         if (mysql_num_rows($rslt) == 0)
             echo"<td>N/A</td>";
         while($drop = mysql_fetch_array( $rslt ))
         {
             echo"<td>".$drop['price']."</td>";
         }
    }
}
echo"</tr></tbody>";
  • 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-14T22:42:30+00:00Added an answer on June 14, 2026 at 10:42 pm

    So here is my answer.

    $res = mysql_query("SELECT DISTINCT h_id FROM hypermarket_em") or die(mysql_error());
    echo"<tbody><tr>";
    while($row = mysql_fetch_array( $res ))
    {   
        $result = mysql_query("SELECT item_name FROM items_em WHERE h_id=".$row['h_id'])or die(mysql_error());
        while($drop_4 = mysql_fetch_array( $result ))
        {
                echo"<th scope=row>".$drop_4['item_name']."</th>";
                $rslt = mysql_query("SELECT price FROM items_em WHERE item_name='".$drop_4['item_name']."' and h_id=".$row['h_id'])or die(mysql_error());
            while($drop = mysql_fetch_array( $rslt ))
            {
                echo"<td>".$drop['price']."</td>";
            }
        }
    }
    $res = mysql_query("SELECT DISTINCT h_id FROM hypermarket_em") or die(mysql_error());
    while($row = mysql_fetch_array( $res ))
    {
        $result = mysql_query("SELECT item_name FROM items_em WHERE h_id=".$row['h_id'])or die(mysql_error());
        if(mysql_num_rows($result)<=0)
            echo"<td>N/A</td>";
    }
    echo"</tr></tbody>";
    

    I had to execute the same query twice as i want the item names and the price values in the order. So I first print the item names and then only the prices or “N/A” message.

    Thank you all for your help..:)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table created with PHP from an Sql Database that successfully displays
I have web page in PHP which displays all records in a table. I
I have working website in PHP with a MySQL backend which has several tables
I have a PHP/MySQL based web application that has internationalization support by way of
so i have this table in mysql called colegue in database addressbook1. it has
I have some PHP code which: connects to mysql table retrieves results formats results
I have a small php file which just creates the tables in a database.
I have a table generated by PHP/mysql, I want a user to click the
i work with php/Mysql i have table with two cols (date , cash) with
I have a problem with sorting items in table in PHP. Here is what

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.