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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:23:21+00:00 2026-06-06T19:23:21+00:00

On my edit pages, how would I show the correct radio button if for

  • 0

On my edit pages, how would I show the correct radio button if for $subscribedrips is equal to Yes or No? Here is what I have and its not working:

 if ($row['subscribedrips'] == Yes) { 
  echo 
  '<input type="radio" name="subscribedrips" value="Yes" CHECKED /> Yes 
  <input type="radio" name="subscribedrips" value="No" /> No';
  }
  elseif ($row['subscribedrips'] == No) {
  echo 
  '<input type="radio" name="subscribedrips" value="Yes" /> Yes 
  <input type="radio" name="subscribedrips" value="No" CHECKED/> No';
  }
  elseif (empty($row['subscribedrips'])) {
  echo 
  '<input type="radio" name="subscribedrips" value="Yes" CHECKED/> Yes 
  <input type="radio" name="subscribedrips" value="No" /> No';
  }
  • 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-06T19:23:22+00:00Added an answer on June 6, 2026 at 7:23 pm

    Something like this

    printf('<input type="radio" name="subscribedrips" value="Yes" %s /> Yes'."\n", 
        ($subscribedrips == 'Yes' ? 'CHECKED' : ''));
    printf('<input type="radio" name="subscribedrips" value="No" %s /> No'."\n",   
        ($subscribedrips == 'No'  ? 'CHECKED' : ''));
    

    works. It uses the ternary operator to either insert 'CHECKED' or an empty string into the input tag, based on the value of $subscribedrips.

    You could also do in a more verbose manner, for example with switch:

    $sel_y = '';
    $sel_n = '';
    switch($subscribedrips)
    {
        case 'Yes':
            $sel_y = 'CHECKED';
            break;
        case 'No':
            $sel_n = 'CHECKED';
            break;
        default:
            // Neither need to be changed, so we dont even need this branch
            break;
    }
    
    printf('<input type="radio" name="subscribedrips" value="Yes" %s /> Yes'."\n", $sel_y);
    printf('<input type="radio" name="subscribedrips" value="No" %s /> No'."\n",   $sel_n); 
    

    Personal preference really.


    Updated Snippet 1

    printf('<input type="radio" name="subscribedrips" value="Yes" %s /> Yes'."\n", 
        ((array_key_exists('subscribedrips', $row) && $row['subscribedrips'] == 'Yes') ? 'CHECKED' : ''));
    printf('<input type="radio" name="subscribedrips" value="No" %s /> No'."\n",   
        ((array_key_exists('subscribedrips', $row) && $row['subscribedrips'] == 'No')  ? 'CHECKED' : ''));
    

    Updated Snippet 2

    $sel_y = '';
    $sel_n = '';
    if(array_key_exists('subscribedrips', $row))
    {
        switch($row['subscribedrips'])
        {
            case 'Yes':
                $sel_y = 'CHECKED';
                break;
            case 'No':
                $sel_n = 'CHECKED';
                break;
            default:
                // Neither need to be changed, so we dont even need this branch
                break;
        }
    }
    
    printf('<input type="radio" name="subscribedrips" value="Yes" %s /> Yes'."\n", $sel_y);
    printf('<input type="radio" name="subscribedrips" value="No" %s /> No'."\n",   $sel_n); 
    

    Regarding your last question, the difference between our approaches is pretty simple, but once again (ahh!) its a style choice, both accomplish the same goal, both methods are used in “production” PHP code.

    My example builds the entire input tag in PHP and prints it. Valentinas’ approach pulls the static text out of the PHP strings and puts it directly into HTML.

    For example, the following lines will all result in the same output:

    <?php printf("<strong>%s</strong>", $some_string); ?>
    
    <?php echo "<strong>$some_string</strong>"; ?>
    
    <?php echo "<strong>".$some_string."</strong>"; ?>
    
    <strong><?php echo $some_string; ?></strong>
    

    I’m doubtful there is any significant performance difference between the two methods, but there is one cosmetic differences that I’ll highlight.

    • Syntax highlighting – If you use an editor with syntax highlighting, valentinas’ approach will allow the syntax highlighter to appropriately highlight the input tag and its attributes. Using my approach, the entire string would be highlighted the same. Here is a screenshot showing how notepad++ highlights the two methods.

      As you can see valentinas’ approach results in a more colorful display, which could help identify and track down errors.

    There are some subtle differences when it comes to how your code has to be formatted if you want to conditionally print the entire tag, but they’re not really worth talking about — the biggest, in my opinion, is the syntax highlighting.

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

Sidebar

Related Questions

I have folders and pages /admin/add/index.php, /admin/edit/index.php & /admin/view/index.php which all are requiring page
What block visibility PHP snippet would show a block only on node pages that
I need a light CMS for .NET 3.5/C#/SQL Server with these features: Create/Edit Pages/Subpages
I am creating a tool with which to edit web pages within a CMS.
More often than I like when designers edit some of our sites' pages, they
I have an edit page with url example.com/product/edit/11 Now if the validation is false
i have a small problem, i am creating a edit page in my asp.net
In my ASP.NET MVC app, I have a fairly complex edit page which combines
I have a pagination script that displays a list of all pages like so:
In my system Users can add/edit/view Customers . I would like to add a

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.