×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

syntax error

syntax error

syntax error

(OP)
Hi,
Can somebody tell me where is the error in the below code (in the highlighted text).

I am trying to display option value using a sql query. If the value from the option list is same as brought in value ($VQdesc) then I want to display that value.

Showing the following error:
Parse error: syntax error, unexpected 'if' (T_IF) in your code

------------------------- code ------------------
<?php
$Vqry1 = "select DXCC_CC_QRY_DESC from T_DXCC_QUERY ORDER BY DXCC_CC_QRY_NO";

$VQdesc = oci_parse($cconnect, $Vqry1);
oci_define_by_name($VQdesc, 'DXCC_CC_QRY_DESC', $VCdesc);

oci_execute($VQdesc);
while(oci_fetch($VQdesc)) {

echo "<option value='".$VCdesc."' ".if($dxcc_log_qry == '".$VCdesc."') {."selected='selected'".}." >$VCdesc</option>";

}
?>
--------------------------------

TIA
Raj

RE: syntax error

Hi

In PHP the statements have no return values so they can not be used in expressions. Use the ternary operator instead :

CODE --> PHP ( fragment )

echo "<option value='$VCdesc'", $dxcc_log_qry == $VCdesc ? " selected='selected'" : "", ">$VCdesc</option>"; 
( Note that I also removed the pointless concatenations to avoid the need to use parenthesis around the conditional subexpression. )

Feherke.
feherke.ga

RE: syntax error

(OP)
It worked. Thanks Feherke.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close