-1
$nestedData[] = '<select id=verify_('.$row['user_id'].')onchange="verifystatus(this.value)" style="width:80px;">
    <option value="reason.php?status=1&user='.$row['user_id'];if($status=='1'){ echo 'selected'; }'>Active</option>
    <option value="reason.php?status=2&user='.$row['user_id'];if($row['status']=='2'){ echo 'selected'; } '\'>Suspend</option>
    <option value="reason.php?status=3&user='. $row['user_id'];if($row['status']=='3'){ echo 'selected'; } '\'>Terminate</option>
</select>'; 

I have bit of confusion in this code that suppurating single and double quotations.

May i request please clarify

EddyTheDove
  • 12,979
  • 2
  • 37
  • 45
  • You may want to take a look at this question: http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – axiac Mar 18 '17 at 06:56
  • i tried it but confusion at where we close the double quotation in value.can u please modify this code – Ramesh vemula Mar 18 '17 at 07:06

3 Answers3

0

Your option tags have the (double) quotes for value opened but you try to close them with single quotes. Basically HTML always has double quotes. Also the quotes which you try to close are in the end after a possible selected. Also the status variable for the active option is not like the others ($row['status']). Another problem is you're echoing "selected" while putting the rest in a variable.

This would be the best output you'd be able to get if the variable $status does exist:

selected<select id=verify_(1)onchange="verifystatus(this.value)" style="width:80px;">
          <option value="reason.php?status=1&user=1

So to fix this, first the echo needs to go and be replaced with string concatenation. Then we need to check the double quotes for HTML, and then you'll probably get the desired result:

$nestedData[] = '<select id="verify_('.$row['user_id'].')" onchange="verifystatus(this.value)" style="width:80px;">
  <option value="reason.php?status=1&user='  .$row['user_id'] . '"' . ($row['status'] == '1' ? ' selected' : '') . '>Active</option>
  <option value="reason.php?status=2&user=' . $row['user_id'] . '"' . ($row['status'] == '2' ? ' selected' : '') . '>Suspend</option>
  <option value="reason.php?status=3&user=' . $row['user_id'] . '"' . ($row['status'] == '3' ? ' selected' : '') . '>Terminate</option>
</select>'; 

Which would output:

<select id="verify_(1)" onchange="verifystatus(this.value)" style="width:80px;">
  <option value="reason.php?status=1&user=1" selected>Active</option>
  <option value="reason.php?status=2&user=1">Suspend</option>
  <option value="reason.php?status=3&user=1">Terminate</option>
</select> 
Asperitas
  • 339
  • 6
  • 13
0

You may use this way to concatenate

<?php
$var  = "<select id='verify_".$row['user_id']." onchange='verifystatus(this.value)' style='width:80px;'>";
$var .= "<option value=reason.php?status=1&user=".$row['user_id'].">Active</option>";
$var .= "<option value='reason.php?status=2&user=".$row['user_id'].">Suspend</option>";
$var .= "<option value='reason.php?status=3&user=".$row['user_id'].">Terminate</option>";
$var .= "</select>";

//echo $var ; 

?>
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40
0

You were very close. For the most part you just had your single quotes and double quotes backwards with a few small tweaks. Like for example you can't do an if statement inside the string your are trying to define a variable with. You need to concatenate the results of the if statement onto the end of the variable.

        $nestedData[];

        $string = "<select id=verify_(" .$row["user_id"] . ")onchange='verifystatus(this.value);' style='width:80px;'> <option value=reason.php?status=1&user=" . $row["user_id"];

        $string .= ( $row["status"] == "1" ? " selected=selected" : "" );

        $string .= " >Active</option> <option value=reason.php?status=2&user=" .$row["user_id"];

        $string .= ( $row["status"] == "2" ? " selected=selected" : "" ); 

        $string .= " >Suspend</option> <option value=reason.php?status=3&user=" . $row["user_id"];

        $string .= ( $row["status"] == "3" ? " selected=selected" : "" );

        $string .= " >Terminate</option> </select>";

        $nestedData[] = $string;
Shane Henry
  • 308
  • 1
  • 7