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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:30:19+00:00 2026-05-23T06:30:19+00:00

<?php include ‘db.php’; $subassetcategory = $_GET[subassetcategory]; if ($subassetcategory == all) { $sql = SELECT

  • 0
<?php

include 'db.php';

$subassetcategory = $_GET["subassetcategory"];

if ($subassetcategory == "all") {
    $sql = "SELECT * FROM asset_subasset";
}
else {
    $sql = "SELECT * FROM asset_subasset WHERE subassetcategory = '" . $subassetcategory . "'";
}

$result = mysql_query($sql) or die(mysql_error());

if ($row = mysql_fetch_array($result)) {

    echo "<table border='1'>
            <tr>
            <th>Asset ID</th>
            <th>Subasset Category</th>
            <th>Subasset Name</th>
            </tr>";

    while ($row = mysql_fetch_array($result)) {
        $subassetid = $row['subassetid'];
        $assetid = $row['assetid'];
        $subassetname = $row['subassetname'];
        $subassetcategory = $row['subassetcategory'];

        echo "<tr>";
        echo "<td>" . $assetid . "</td>";
        echo "<td>" . $subassetcategory . "</td>";
        echo "<td>" . $subassetname . "</td>";
        echo "<td>" . "<a href='viewassetdetail.php?subassetid=$subassetid&assetid=$assetid'>View<a/>" . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}
else {
    echo "<br> No data found </br>";
}

mysql_close($connect);

?>

Please help me, I couldn’t figure out as to why this code cannot return the result properly. It returned less 1 row (if result suppose to have 2 rows it will only return 1) from the exact rows available in the database.

if ($row = mysql_fetch_array($result)) {

    echo "<table border='1'>
            <tr>
            <th>Asset ID</th>
            <th>Subasset Category</th>
            <th>Subasset Name</th>
            </tr>";

    while ($row = mysql_fetch_array($result)) {
        $subassetid = $row['subassetid'];
        $assetid = $row['assetid'];
        $subassetname = $row['subassetname'];
        $subassetcategory = $row['subassetcategory'];

        echo "<tr>";
        echo "<td>" . $assetid . "</td>";
        echo "<td>" . $subassetcategory . "</td>";
        echo "<td>" . $subassetname . "</td>";
        echo "<td>" . "<a href='viewassetdetail.php?subassetid=$subassetid&assetid=$assetid'>View<a/>" . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}
else {
    echo "<br> No data found </br>";
}

mysql_close($connect);

?>

if I just wrote this code, it works perfectly.

$result = mysql_query($sql) or die(mysql_error());

echo "<table border='1'>
    <tr>
    <th>Asset ID</th>
    <th>Subasset Category</th>
    <th>Subasset Name</th>
    </tr>";

while ($row = mysql_fetch_array($result)) {
    $subassetid = $row['subassetid'];
    $assetid = $row['assetid'];
    $subassetname = $row['subassetname'];
    $subassetcategory = $row['subassetcategory'];

    echo "<tr>";
    echo "<td>" . $assetid . "</td>";
    echo "<td>" . $subassetcategory . "</td>";
    echo "<td>" . $subassetname . "</td>";
    echo "<td>" . "<a href='viewassetdetail.php?subassetid=$subassetid&assetid=$assetid'>View<a/>" . "</td>";
    echo "</tr>";
}
echo "</table>";

mysql_close($connect);

?>

But I want it to show “No data found” if the result was empty. So, any help? I know it’s very simple but I couldn’t find the answer for days already. Thank you in advance!

  • 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-05-23T06:30:20+00:00Added an answer on May 23, 2026 at 6:30 am

    You are basically slicing off the first result in your if statement:

    if ($row = mysql_fetch_array($result))
    

    Just check for the number of rows returned to keep the resultset intact:

    if(mysql_num_rows($result) > 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php include_once('booter/login/includes/db.php'); $query=SELECT * FROM shells; $result=mysql_query($query); while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ $hash = @md5_file($row['url']); echo $hash
My PHP file: <?php include(ConnectDatabase.php); $Username = mysql_real_escape_string($_POST['Username']); $Password = mysql_real_escape_string($_POST['Password']); $q = mysql_query(SELECT
<?php include('includes/config.php'); $topi = $_GET['id']; //id of url mysql_select_db(ban, $con); $query = SELECT *
When i use php include to include a page in my website all the
This is user.php: include(databse.php);//retrieving successfully first name and lastname from databse file into user.php
The problem: I want to use PHP include to import file header_menu.html into all
I've seen recommendations to store some or all php include files some place other
I have header.php and footer.php files which I include in all of my pages.
here is my code for json php include(connect.php); $id = $_GET['lid']; function countRec($fname,$tname) {
index.php <?php include(header.php); ?> header.php <?php echo<a href='add.php'>Lägg Till</a>; ?> result L?gg Till The

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.