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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:26:26+00:00 2026-06-09T06:26:26+00:00

This is my first post so please bear with me with inputting the code

  • 0

This is my first post so please bear with me with inputting the code into here. Im trying to output some images to a PDF and need to create a if statement that looks for data with in a row.

$connection = mysql_connect("localhost", "testdb", "********")
    or die ("Unable to connect!");    

// select database  
mysql_select_db("testdb") or die ("Unable to select database!");      

// Select all the rows in the test table
$query = "SELECT * FROM test2 WHERE testid=89";
$result = mysql_query($query);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}

while ($row= mysql_fetch_array($result)) {
    $image = $row[1]; 
    $text = $row[2];
}

That’s what I have so far and basically I need something along the line of this:

If (data in row 1) {
    print $image;
} else {
    print $text;
}
  • 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-09T06:26:28+00:00Added an answer on June 9, 2026 at 6:26 am

    It’s hard to say exactly what you’re looking for since it isn’t very clear, but I think what you’re wanting to do is check to see if $image has a value, and if so, display it. If not, display $text instead.

    If this is the case use empty(). It will tell you if a variable is empty or not.

    if (!empty($image))
     {
       print $image;
     }
    else
     {
      print $text;
     }
    

    The following things are considered to be empty:

    • “” (an empty string)
    • 0 (0 as an integer)
    • 0.0 (0 as a float)
    • “0” (0 as a string)
    • NULL
    • FALSE
    • array() (an empty array)
    • $var; (a variable declared, but without a value)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

need some enlightment here, and this is my first post here. I would like
This is my first post so please bear with me. I'm trying to execute
This is my first post on Stack, so please bear with me if I
This is my first post here so go easy. I am trying to build
This is my first post here. I have a problem. I need to take
This is my first post in any forum so please bear with me. I
This is my first post on StackOverflow, so please bear with me. And I
First post here, so please bear with me if I get something wrong. I'm
This is my first post on StackOverflow, so please be gentle... I have some
This is my first post, so please bear with me. I'll try and be

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.