Creating a table to showcase the outcomes of two different conditions

I am struggling to include two conditional result statements in a table, but I can't seem to make it work.

If the form input is empty, the result should not be shown.

In order to save space, I would like to organize the results in a table with either two or three columns.

if(!empty($lect))
   $result .= '<p>' . __('<table class="custom-data"><span id="si" >Name:</span> ') . '<span id="si1" >' . $lect . '</span></table></p>';

if(!empty($lect1))
   $result .= '<p>'. __('<table class="custom-data"><span id="si">Product :</span> ') . '<br><span id="si1" >' . $lect1 . '</span></table></p>';

Current output:

https://i.stack.imgur.com/Txvu1.png

Desired output:

https://i.stack.imgur.com/oHzyf.png

Answer №1

Kindly refer below to split into distinct columns:

$result .= '<table class="custom-data"><tr>';
if( ! empty( $lect ) )
   $result .= '<td><p>' . __('<span id="si" >Name:</span> ') . '<span id="si1" >' . $lect . '</span></p></td>';
if( ! empty( $lect1 ) )
   $result .= '<td><p>' . __('<span id="si">Product :</span> ') . '<br><span id="si1" >' . $lect1 . '</span></p></td>';
$result .= '</tr></table>';

In this case, the expected return value would be $result. The output will contain one row with conditional columns.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Elegant Modal Form Submission Using jQuery

Having trouble submitting a modal jQuery form? A code snippet was borrowed from a website with minor modifications and the JavaScript was moved to a separate file. The challenge lies in transmitting form data to a PHP script via AJAX. The serializedArray() ...

What is the process for creating a connection reset in a programmatic way?

Have you ever encountered the frustrating "the connection was reset" message while attempting to surf the web? (This specific text is from Firefox, other browsers may vary.) Occasionally, I find myself needing to intentionally trigger this error message i ...

Guide on showcasing the values from two text fields with autocomplete suggestions in a third text field

Hey there, I have a search form that takes values from two text fields and combines them to populate a third text field for querying. <form name="form1" method="post" action="" autocomplete="off" oninput="sea.value = password.value +''+ passw ...

Angular10 selection table - reveal expanded row when item is selected

I am currently working with an angular 10 table that includes a selection feature, but I am encountering issues trying to display an expandable row when the user selects a particular row. I have attempted to incorporate expandable tables in conjunction wit ...

"Ensuring the safety of your website with PHP

I am in the process of developing a website that generates a user's profile page based on their input. My main concern is whether this approach is secure. Below is how I currently sanitize the user input, but I would appreciate any additional advice. ...

The button will be visible on the page only if the provided zip code is within our service area

Scenario : Our online shopping platform allows customers to place orders and input their zip code in the address section.... All order information is stored in the do_order table, with supported zip codes listed in the shippment_details table.... https: ...

Using Angular, you can easily add a <div> dynamically to all elements that share a class

In order to implement a solution, I am tasked with adding a new div element with the class '.cart-list-value .delete-product', which will contain a background image, to all elements that have the class .cart-list-item. Although I successfully man ...

The Dilemma of jQuery Dragging and Resizing Clash

I have implemented the Gridster Plugin() in my project. I discovered an updated demo on Github which includes resizable functionality. To ensure compatibility with future items, I have also integrated the jQuery livequery plugin. However, I am facing an i ...

Boxes that expand to full width and appear to float on

I am dealing with a situation where I have a container that holds multiple child elements such as boxes or sections. <section> <div>Box 1</div> <div>Box 2</div> <div>Box 3</div> <div>Box 4< ...

Attempting to divide the main page into quadrants

I want to split my homepage into four equal images without any scrolling. When you click on the website, I want the four images to expand and cover the entire screen with no scrollbars. I've made some progress with my code, but it's not quite the ...

Creating a Search Functionality within a Tab Component in Ionic

I'm currently facing an issue with adding a search bar under the "Search" tab in my project. I've tried implementing similar logic to what's shown here, but it doesn't seem to function properly when using the ionic serve --lab live in-b ...

Deleting an element from HTML using jQuery

In the midst of creating a system that allows users to construct their own navigation structure, I have encountered a stumbling block. The idea is that when a user lands on the site, they are presented with a list of available topics from which they can ch ...

Using PHP script to retrieve MySQL table values and dynamically update a live graph in a Javascript function

I've been researching similar issues for quite some time now, but to no avail. Currently, I'm utilizing Highcharts to update a graph every 3 seconds with the latest entry from a specific MySQL table. I am referring to the example Javascript code ...

Make the background image come to life by animating it from the bottom to the top in

Upon landing on a page, I aim for the background image to initially focus on the bottom and then pan up to the top before returning back down in a continuous loop. The code I have set up is as follows: <body> <div id="container"></div&g ...

The right alignment with Flexbox's justify content property is not being implemented as expected

I'm having trouble aligning my footer using flexbox - no matter what I try, it won't move all the way to the right. When I use justify-content: center, the items are centered, but when I change it to justify-content: right, everything shifts bac ...

Encountering issue with Django locating static file (1.5) showing ERROR 404 code 1649

I'm facing some difficulties in setting up my local Django site. I've reviewed the previous questions and answers, but haven't been able to find a solution. [20/Oct/2013 03:56:33] "GET /rides/ HTTP/1.1" 200 230 [20/Oct/2013 03:56:33] "GET / ...

Upgrading outdated pagination mysql_query PHP code to PDO

Currently in the process of transitioning to PDO for database management, I have implemented a news section on my website. The database connection is located within the header of the site. While using the following code for pagination, I am struggling to ...

What is the best way to implement a JSON object within an <img> src attribute?

Currently, I am in the process of creating a dynamic Vuetify navigation drawer and I have the intention of storing images in a JSON array. My main inquiry revolves around figuring out if it's feasible to extract the image attribute and incorporate it ...

When adjusting the window size with the <ion-split-pane>, both the menu and router outlet disappear

When I have two ion menus and one main content (router outlet) and resize the page or switch to mobile view, the page appears blank as if the content is missing. Here is the code: <ion-app> <ion-split-pane> <ion-menu side="start" me ...

What is the most efficient method of organizing form components together?

After exploring numerous tutorials, I have yet to discover the ideal solution for properly marking up a form that contains logical groupings of elements such as labels, controls (input or select), and previous values - essentially single fields. My prefer ...