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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:19:38+00:00 2026-06-16T03:19:38+00:00

I have a variable called $position which has a value selected from a database.

  • 0

I have a variable called $position which has a value selected from a database.
I am having an issue displaying the $position value in my dropdown menu as the selected value on page load.
The $position variable does echo out the correct value outside of this code.

I read about the Ternary Operator method so I have used that here instead of normal IF statment but it still does not work. Is my code correct? Is there another method I should use?

Thanks

My Code

$number = $_GET['id'];
$number = mysqli_real_escape_string($connect,$number);

$stmt = $connect->prepare("SELECT s_code, s_type, s_position, s_idno, s_firstnames, s_email, s_cellno FROM smco WHERE s_ainumber = ?") or die(mysqli_error());

$stmt->bind_param('s', $number);

$stmt->execute();

$stmt->bind_result($code, $type, $position, $idno, $name, $email, $cell);

$stmt->fetch();

$stmt->close();

echo "<td width=\"62%\" align=\"left\">
<p><b>Position:</b></p>
<select name=\"position\">
<option value=\"AQ\" (($position == 'AQ') ? \"selected='selected'\")>Account Queries</option>
<option value=\"KM\" (($position == 'KM') ? \"selected='selected'\")>Key Account Manager</option>
<option value=\"MD\" (($position == 'MD') ? \"selected='selected'\")>Managing Director</option>
<option value=\"RB\" (($position == 'RB') ? \"selected='selected'\")>Rebates</option>
<option value=\"BY\" (($position == 'BY') ? \"selected='selected'\")>Store Buyer</option>
<option value=\"OW\" (($position == 'OW') ? \"selected='selected'\")>Store Owner</option>
</select>
</td>";
  • 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-16T03:19:40+00:00Added an answer on June 16, 2026 at 3:19 am
    echo '<option value="">' . (true ? 'true' : 'false') . '</option>';
    

    In you case:

    echo "<option value=\"AQ\"" . (($position == 'AQ') ? ' selected="selected"' : '') . ">Account Queries</option>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable called $tags , which just references from a database field.
Okay so i have a variable called search which holds the string Find this
I have a PHP-variable called $go_Adress which contains the adress I need to get
I have a dataTable which has a value of a bean class which looks
I have a short integer variable called s_int that holds value = 2 unsighed
I have a variable called current which holds the last clicked listview item data.
I have a file that has sequence on line 2 and variable called tokenizer,
Let's say I have a class called Unit (with a position variable x) and
I have a variable called posts_object[i].updated_time It's always an utf-timecode. It seems to always
I have a variable called $effectiveDate containing the date 2012-03-26 . I am trying

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.