Forums

How to ...parse an if() statement

santana 20 Sep, 2008
Hi Max!
first: thank's a lot for that unvaluable tool
now, the problem:
I need to parse some php code into the body of my query form, in the way
<?php if({fieldname} = 1) echo "SI"; else echoo "NO"; ?>
or so... (I'm far away of a php expert !)
maybe you post some code to help us in that case?
we thank's you a lot again,
Max_admin 20 Sep, 2008
Hi Santana,

if you want to use a field name in the PHP code then you should do it like this instead of the normal {field_name} formula :

<?php 
if($row->fieldname == 1) {
echo "SI";
}else{
echo "NO";
?>


P.S: I fixed some things in your code too!😉

Regards

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
santana 20 Sep, 2008
genial hombre !!! (sapnaglish is my natural language... you know!)
gracias !
Zero-one 27 May, 2009
Hi,
I have also a problem with if statements in Connectivity Body tag.

Head
<?php
$user = & JFactory::getUser();
$pva = "{pvangebot}";
If($user->gid <= 17)
{
    global $mainframe;
    $mainframe->redirect('index.php');
}?>

Body - This code works
<?php if($user->id == $row->cf_user_id){ ?> <td>{pvangebot}</td> <?php } ?>

Body - with else if it no longer works and I get a error message
(Parse error: parse error in C:\...\chronoconnectivity.html.php(176) : eval()'d code on line 6)

<?php if ($user->id == $row->cf_user_id) 
	{ 
   		else if ($pva == 20)
    		{ 
			echo '<td>Neues Angebot</td>';
    		}
		else ($pva == 0)
    		{
			echo '<td>Noch kein Angebot</td>';
    		}
	} 
?> 


Why this PHP Code does not work, is there any stupid mistakes in it?


Greetings,
Zero-one
GreyHead 27 May, 2009
Hi Zero-one,

You have else ($pva == 0) and 'else' doesn't take a condition - try elseif ($pva == 0) instead.

Bob
Zero-one 27 May, 2009
Hi Bob,

Thanks for the help, but it does not work yet.

Must i set the <?php tags placed differently?

<?php if ($user->id == $row->cf_user_id) { ?>
   	<?php else if ($pva == 20) { ?>
	<td>Neues Angebot</td>
    	<?php }  ?>
	<?php elseif ($pva == 0){ 
	<td>Noch kein Angebot</td>
       <?php }  ?>
<?php } ?>	

But this does also don't work.

Greetings,
Zero-one
nml375 27 May, 2009
You do not need to alter your <? and ?>. However, you need to get your {} nesting in order. That is, for each { there should be one, and only one, matching } to "close" this block of code. If I should try to parse your code, this might be the proper version:

<?php
  if ($user->id == $row->cf_user_id) {

  } elseif ($pva == 20) {
    echo "<td>Neues Angebot</td>";
  } elseif ($pva == 0) {
    echo "<td>Noch kein Angebot </td>";
  }
?>
Zero-one 29 May, 2009
Thanks for help, it works now.

But i have a other problem with if else in ChronoConnectivity Front Permissions.
If I add in a if else PHP Code a input field, the Front Permissions load a blank page.
I have search in chronoconnectivity.html.php, but my php skill is too bad.

Example:
<?php
$question = "{question01}";
if ($question == var10)
{
echo '<div class="form_item">
  <div class="form_element cf_radiobutton">
    <label class="cf_label" style="width: 150px;">Question?</label>
    <div class="float_left">
      <input value="radio 1" title="" class="radio" id="radio00" name="radio0" type="radio" />
      <label for="radio00" class="radio_label">Yes</label>
      <br />
	<input value="radio 2" title="" class="radio" id="radio01" name="radio0" type="radio" />
      <label for="radio01" class="radio_label">No</label>
      <br />
    </div>
  </div>
  <div class="cfclear"> </div>
</div>';
}
elseif ($question == var20)
{
    echo '<p>Answer 2</p>';
}
else
{
    echo '<p>Answer 5</p>';
}
?>

Has anyone a idea why it does not work?


Greetings,
Zero-one
GreyHead 29 May, 2009
Hi Zero-one,

I think you need some quotes in the 'if' clauses
if ($question == var10)
should probably be
if ($question == 'var10')
if 'var10' is a string value (and the same for the elseif line.

Bob
Zero-one 29 May, 2009
Hi Bob,

The if else works perfect with textbox, textarea.. but if I have a checkbox, dropdown, .. with an input tag in the if else Code.
Then the Front Permissions Page load a blank page.

Edit:
a select tag breaks also the page.

Greetings,
Zero-one
Zero-one 31 May, 2009
I have found the problem.
[startphp]
$question = "{question01}";
if ($question == var10)
{
echo '<div class="form_item">
  <div class="form_element cf_radiobutton">
    <label class="cf_label" style="width: 150px;">Question?</label>
    <div class="float_left">
      <input ccnamex="radio0" cctypex="radio" ccvaluex="radio 1" ccphpx="[startphp] if("{radio0}" == "radio 1")echo "checked='checked'";[endphp]ccphpx" value="" title="" class="radio" id="radio00">
      <label for="radio00" class="radio_label">Yes</label>
      <br>
   <input ccnamex="radio0" cctypex="radio" ccvaluex="radio 2" ccphpx="[startphp] if("{radio0}" == "radio 2")echo "checked='checked'";[endphp]ccphpx" value="" title="" class="radio" id="radio01">
      <label for="radio01" class="radio_label">No</label>
      <br>
    </div>
  </div>
  <div class="cfclear"> </div>
</div>';
}
elseif ($question == var20)
{
    echo '<p>Answer 2</p>';
}
else
{
    echo '<p>Answer 5</p>';
}
[endphp]


There is an if Statement in the checkbox.
Is there a solution that I can use a checkbox in my if else code?

Greetings,
Zero-one
Zero-one 02 Jun, 2009
Hi,

Now it works.
I have edit the Auto generated Code over phpmyadmin.


[startphp]
$question = "{question01}";
switch($question) {
    case var00:
        echo '<p>Answer 1</p>';
        break;
    case var10:
		echo '<div class="form_item"><div class="form_element cf_radiobutton"><label class="cf_label" style="width: 150px;">Question?</label><div class="float_left"><input ccnamex="radio0" cctypex="radio" ccvaluex="radio 1" ccphpx="';
		if ("{radio0}" == "radio 1")
    		echo "checked='checked'";

		echo 'ccphpx" value="" title="" class="radio" id="radio00"><label for="radio00" class="radio_label">Yes</label><br><input ccnamex="radio0" cctypex="radio" ccvaluex="radio 2" ccphpx="';

		if ("{radio0}" == "radio 2")
    		echo "checked='checked'";

		echo 'ccphpx" value="" title="" class="radio" id="radio01"><label for="radio01" class="radio_label">No</label><br></div></div><div class="cfclear"> </div></div>';
   		break;
	case var20:
    	echo '<p>Answer 3</p>';
    	break;
	default:
    	echo '<p>No Answer</p>';
		}
[endphp]


Greetings,
Zero-one
Max_admin 06 Jun, 2009
Hi, I also suggest you test with the new version, it deals much better with this!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
gugely36 29 Jun, 2009
Hi,

I have a similar question and soon I will rip out my hair because it is just frustrating.
I have and need the following:

I want CC to view a form with data out of one SQL Table, HOWEVER I need a few conditional statements. E.g.
If x1 (where x1 is a value from database) is present in the array(in row y from database) then Echo "blah blah blah" else echo blah blah blah.

If some one can just point me in a direction it would be greatly appreciated.

Michael
Max_admin 30 Jun, 2009
Hi Michael,

in the body tag use :


if($MyRow->field_name == 'ssss'){
echo 'first bla bla';
}else{
//2nd one
}


Cheers,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
gugely36 30 Jun, 2009
Hi Max,

Sorry but I am a bit slow......

let me refresh what i am trying to do.( my coding is bad and so are the terms in which I try to express)

I have 2 Zones which are categorized in different Field_names.(air_z1,air_z2)
The clinet fills out a registratraiton form first and has to select his airport of departure (aof).
So when the client pulls up a quote I want to do:

IF aod is present in the air_z1 array of airport

then show the part_z1 PRICE( have 2 different prices: part_z1,part_z2) ELSE show part_z2.

I was not sure how to structure my table so i put everything under different field_names.

is this possible or can I start rewriting everything?

Michael
GreyHead 08 Jul, 2009
Hi Michael,

I'm not quite clear what the problem is here. I think Max's code should do what you need with some small mods
<?php
if ( in_array($MyRow->aod, air_z1 ){
  echo 'first bla bla';
} else {
  //2nd one
}
?>
Assuming that air_z1 is an array.

Bob
gugely36 14 Jul, 2009
Hi Bob

This is what I need to do

The client fill’s out a form e.g. name, surname, airport of departure(drop down menu at present) and if he is traveling with a partner(yes/no). the info gets stored to db (table MainDB)

{name} = client name
{surname} = client surname
{aod} = airport of departure
{select2} = (YES or NO) Partner traveling with

Then I have a few admin forms with CC e.g. zone1 {air_z1}( list of airports of departure) zone2 {air_z2} (also a list of airports of departure) zone3 {air_z3} (also a list of airports of departure), client pricing for zone1{pat_z1}, zone2{pat_z2} and zone3 {pat_z3}as well as Partner pricing for zone1{part_z1}, zone 2{part_z2}, zone3{part_z3}. (all fields in MainDB as well)

Now when the client calls up a “quotation” from the User menu, I need the CC form to do the following:

IF “airport of departure “ {aof} of client is present in zone1 {air_z1} (List of Airports)?
then show “zone1” {pat_z1}Price

IfElse “airport of departure “ {aod} of client is present in zone2 {air_z2} (List of Airports)?
then show “zone2” {pat_z2}Price

else show “zone3” {pat_z3}Price

THEN

If client “traveling with partner” (client {select2}=yes) & client {aod} = to {air_z1} (list of airports)
VIEW {part_z1} partner tariff and ADD {part_z1} to calculation of {pat_z1}

IfElse client “traveling with partner” (client {select2} = YES) & client {aod} = to {air_z2} (list of airports)
“YES” VIEW {part_z2} partner tariff and ADD {part_z1} to calculation of {pat_z2}

Else VIEW {part_z3} partner tariff and ADD {part_z3} to calculation of {pat_z3}


I hope this makes sense. I simply have the problem I have no idea how to fraise the IF statement and where to put it in CC.
The basic display form with CC is done but leaves this problem with the IF’s

Please note that the // {*} // in Curly brackets are the PHISICAL field names from my MainDB where:

{aod} = client selects airport of Dep from a drop down menu and stores his choice to MainDB per user.
{air_z1}, {air_z2}, {air_z3} = unique list of Airports per ZONE.- ADMIN pre-entered
{pat_z1}, {pat_z2}, {pat_z3} = price for patient per ZONE .- ADMIN pre-entered (only one price per zone)
{part_z1}, {part_z2}, {part_z3} = price for Partner (IF) per ZONE.- ADMIN pre-entered (only one price per zone)

I hope this describes what I need to do very clearly.

AND THIS IS WHAT I HAVE DONE ALREADY:

What I have done already is the following:
Created Joomla registration form with CF – Works
Created Client Info form with CF – Works (the form where the client fills in info like Name, Surname, date of departure, airport of departure, etc and gets stored to MainDB Table)

Created Admin form With CC where Admin can change the Client Pricing per zone. - Works
Created Admin form With CC where Admin can change all client information. - Works
Created Admin form With CC where Admin can change/ enter the airports per zone. - Works

All this information is fed and read from ONE Table only( MainDB table).

YES Client has to be Logged in to be able to view his own data (Working). Normal view of info for logged in client -works.
So now I just need to finish the last CC form for “quotation” per client. The client MUST be logged in to be able to view the relevant information.

The basic “quotation” form is done with CC so now I just need to get the Conditions right as explained in the previous mail. E.g. If client from NY the charge price “Pat_z1” and so on.


Michael
gugely36 18 Jul, 2009
Hi there,

Is there nobody that can help me with this or guide me in a direction?

Michael
gugely36 18 Jul, 2009
Hi there,

Tried a different approach in CC. gives me this error:

Parse error: syntax error, unexpected '{' in ***/connection.php(267) : eval()'d code on line 6

this is my code:

<?php
$air_z1=array('Abu Dhabi', 'Ahmadabad', 'Amman', 'Amsterdam', 'Athens', 'Bahrain', 'Bangalore', 'Bangkok', 'Barcelona' ,'Beijing', 'Beirut', 'Berlin', 'Birmingham', 'Bombay', 'Brussels', 'Budapest', 'Copenhagen', 'Damascus', 'Delhi', 'Dhaka', 'Dhahran', 'Doha', 'Dublin', 'DĂźsseldorf', 'Edinburgh', 'Frankfurt', 'Geneva', 'Glasgow', 'Guangzhou', 'Hamburg', 'Helsinki', 'Hong Kong', 'Islamabad', 'Istanbul', 'Jakarta', 'Jeddah', 'Larnaca', 'Lisbon', 'London (Gatwick)', 'London (Heathrow)', 'Karachi', 'Kuala', 'Lumpur', 'Kuwait City', 'Lahore', 'Madrid', 'Malta', 'Manchester', 'Manila', 'Milan', 'Moscow', 'Mumbai', 'Munich', 'Muscat', 'Newcastle', 'Nice', 'Oslo', 'Paris', 'Prague', 'Riyadh', 'Rome', 'Sanaa', 'Shanghai', 'Singapore', 'Stockholm', 'St Petersburg', 'Venice', 'Vienna', 'Warsaw', 'Zurich');

$air_z2 = array('Atlanta', 'Auckland', 'Boston', 'Brisbane', 'Colombo', 'Chicago', 'Christchurch', 'Dallas', 'Detroit', 'Houston', 'Kansas City', 'Los Angeles', 'Melbourne', 'Memphis', 'Miami', 'Montreal', 'New Orleans', 'New York', 'Perth', 'Phoenix', 'San Francisco', 'Seattle', 'Seoul', 'Sydney', 'Tokyo', 'Toronto', 'Vancouver (BC)', 'Wellington');

if ( in_array($MyRow->aod, $air_z1 ){
echo 'ZONE 1'
} else {
echo 'ZONE 2'}
?>


any ideas?

michael
nml375 18 Jul, 2009
Hi Michael,
It would seem you missed one ) in your conditional:
if ( in_array($MyRow->aod, $air_z1 ){
echo 'ZONE 1'
} else {
echo 'ZONE 2'}

Try this instead:
if ( in_array($MyRow->aod, $air_z1) ) {
  echo 'ZONE 1'
} else {
  echo 'ZONE 2'
}


/Fredrik
gugely36 19 Jul, 2009
Thank you very much...... it worked.

many million thanks for your help

Michael
This topic is locked and no more replies can be posted.