Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax error 1

Status
Not open for further replies.

rk68

Programmer
Jul 15, 2003
171
IN
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)) {

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

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

TIA
Raj
 
Hi

In PHP the statements have no return values so they can not be used in expressions. Use the ternary operator instead :
Code:
[b]echo[/b] [i][green]"<option value='$VCdesc'"[/green][/i][teal],[/teal] [navy]$dxcc_log_qry[/navy] [teal]==[/teal] [navy]$VCdesc[/navy] [teal]?[/teal] [i][green]" selected='selected'"[/green][/i] [teal]:[/teal] [i][green]""[/green][/i][teal],[/teal] [i][green]">$VCdesc</option>"[/green][/i][teal];[/teal]
( Note that I also removed the pointless concatenations to avoid the need to use parenthesis around the conditional subexpression. )


Feherke.
feherke.ga
 
It worked. Thanks Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top