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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:35:34+00:00 2026-05-11T17:35:34+00:00

I am retrieving 3 fields from a database, and by default, only the username

  • 0

I am retrieving 3 fields from a database, and by default, only the username field will have content. The other information will be added in from a user application. I want to show the field as “No Info” if there is no entry in the field. I am trying to use both empty() and is_null() to no avail. A var_dump of $row[‘firstname’] and $row[‘lastname’] returns NULL in both cases.

<?php
  if (isset($_GET["subcat"]))
  $subcat = $_GET["subcat"];
if (isset($_GET["searchstring"])) {
    $searchstring = $_GET["searchstring"];
}
$con = mysqli_connect("localhost","user","password", "database");
if (!$con) {
    echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error();
    exit;
}
$table = 'USERS';
$brand = '%' . $searchstring . '%';
$rows = getRowsByArticleSearch($brand, $table);
echo "<table border='0' width='100%'><tr>" . "\n";
echo "<td width='15%'>Username</td>" . "\n";
echo "<td width='15%'>Firstname</td>" . "\n";
echo "<td width='15%'>Surname</td>" . "\n";
echo "</tr>\n";
foreach ($rows as $row) {
    if (is_null($row['firstname']) || $row['firstname'] == "") {
        $row['firstname'] == "No Info";
    }
    if ($row['lastname'] == null || $row['lastname'] == "") {
        $row['firstname'] == "No Info";
    }
    var_dump($row['firstname']);
    var_dump($row['lastname']);
    echo '<tr>' . "\n";
    echo '<td><a href="#" onclick="updateByUser(\''. $row['username'] .'\',\''.$subcat.'\')">'.$row['username'].'</a></td>' . "\n";
    echo '<td><a href="#" onclick="updateByUser(\''. $row['username'] .'\', \''.$subcat.'\')">'.$row['firstname'].'</a></td>' . "\n";
    echo '<td><a href="#" onclick="updateByUser(\''. $row['username'] .'\', \''.$subcat.'\')">'.$row['lastname'].'</a></td>' . "\n";
    echo '</tr>' . "\n";
}
echo "</table>\n";
function getRowsByArticleSearch($searchString, $table) {
    $con = mysqli_connect("localhost","user","password", "database");
    $recordsQuery = "SELECT username, firstname, lastname FROM $table WHERE lower(username) LIKE ? ";
    if ($getRecords = $con->prepare($recordsQuery)) {
        $getRecords->bind_param("s", $searchString);
        $getRecords->execute();
        $getRecords->bind_result($username, $firstname, $lastname);
        $rows = array();
        while ($getRecords->fetch()) {
            $row = array(
                            'username' => $username,
                            'firstname' => $firstname,
                            'lastname' => $lastname,
                        );
            $rows[] = $row;
        }
        return $rows;
    } else {
        print_r($con->error);
    }
}
  • 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-11T17:35:34+00:00Added an answer on May 11, 2026 at 5:35 pm

    Turn on display_errors and set error_reporting to E_ALL (either in php.ini or in a htaccess). This should reveal any non-obvious mistakes.

    Try the following for checking if something is empty:

    <?php
    if(!isset($row['...']) || empty($row['...']))
    {
        $row['firstname'] = 'No Info';
    }
    ?>
    

    Also, please note you’re using ‘==’ to set the $row things to ‘No Info’. Al this does is return ‘true’ (or 1). Use a single ‘=’ to set variables.

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

Sidebar

Ask A Question

Stats

  • Questions 172k
  • Answers 172k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Should be just a matter of creating a PdfPTable object… May 12, 2026 at 2:29 pm
  • Editorial Team
    Editorial Team added an answer You are going to get crashing (or disappearing VB6) if… May 12, 2026 at 2:29 pm
  • Editorial Team
    Editorial Team added an answer Here is the solution for my question My Solution May 12, 2026 at 2:29 pm

Related Questions

I am retrieving data from an Oracle database and binding the same to a
I have been dancing around this issue for awhile but it keeps coming up.
I understand that, in the interest of efficiency, when you query the database you
I have this scenario, can anybody fill the gaps for me? Its like this:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.