close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

IF / ELSE statements & foreach loops using the MySQLi plugin?

Thread begun 5/19/2015 2:00 pm by Jason | Last modified 6/04/2015 3:01 pm by Ray Borduin | 4058 views | 8 replies |

Jason

IF / ELSE statements & foreach loops using the MySQLi plugin?

I was wondering if there is a way to do some of the functions using the plugin. I've hand written them into my code for now, and they are working, but I'd like to still be able to use my plugin. Currently it doesn't recognize the queries I've made changes to (understandably). This is the code I have working now.

php:
<?php

$_POST
['calendar_id'] = 1;

if ((((isset(
$_POST["Submit"]))?$_POST["Submit"]:"") != "")) {

        foreach(
$_POST['Room'] as $room)
        {
            
$InsertQuery = new WA_MySQLi_Query($local_i);
            
$InsertQuery->Action "insert";
            
$InsertQuery->Table "calendarevents";
            
$InsertQuery->bindColumn("calendar_events_name",       "s", ((isset($_POST["insert_id"]))?$_POST["insert_id"]:""), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_start_date""s", ((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d')), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_end_date",   "s", ((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d')), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_start_time""s", ((isset($_POST["start_time"]))?$_POST["start_time"]:""), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_end_time",   "s", ((isset($_POST["end_time"]))?$_POST["end_time"]:""), "WA_DEFAULT");
            if(isset(
$_POST['Recurring']))
            {
              
$InsertQuery->bindColumn("calendar_events_repeats",        "s", ((isset($_POST["RecurType"]))?$_POST["RecurType"]:""), "WA_DEFAULT");
              
$InsertQuery->bindColumn("calendar_events_repeat_every",   "i", ((isset($_POST["Frequency"]))?$_POST["Frequency"]:""), "WA_DEFAULT");
              
$InsertQuery->bindColumn("calendar_events_on_the",         "i", ((isset($_POST["dow"]))?$_POST["dow"]:""), "WA_DEFAULT");
              
$InsertQuery->bindColumn("calendar_events_repeat_on",      "i", ((isset($_POST["RecurOn"]))?$_POST["RecurOn"]:""), "WA_DEFAULT");
              
$InsertQuery->bindColumn("calendar_events_occurrence",     "s", ((isset($_POST["Occurrence"]))?$_POST["Occurrence"]:""), "WA_DEFAULT");
              
$Occurrence_End = ((isset($_POST["Occurrence"]) && $_POST['Occurrence'] == 'end-by-end-date')?$_POST["ends_on"]:$_POST['EndAfter']);
              
$InsertQuery->bindColumn("calendar_events_occurrence_end""s"$Occurrence_End"WA_DEFAULT");
              
$InsertQuery->bindColumn("calendar_events_occurrence_storage""s"$Occurrence_End"WA_DEFAULT");
            }
            
$InsertQuery->bindColumn("calendar_events_type",        "s", (isset($_GET['type']) ? $_GET['type'] : "person"), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_attribute",   "s"$room"WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_attribute_2""s", ((isset($_POST["Position"]))?$_POST["Position"]:""), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_event_list",  "i"$Parent_Event_List"WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_calendar_id""i", ((isset($_POST["calendar_id"]))?$_POST["calendar_id"]:"1"), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_attribute_3""s""".((isset($_POST["Category"]))?$_POST["Category"]:"")  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_shift_event_parent_id""i""".((isset($_GET["calendar_events_id"]))?$_GET["calendar_events_id"]:"")  ."""WA_DEFAULT");
            
            
$InsertQuery->execute();
    }
        if(
count($_POST['Room']) > 1)
        {
            
$InsertGoTo "event_schedule.php?day=".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))
                        .
"&calendar_events_id=".((isset($_GET["calendar_events_id"]))?$_GET["calendar_events_id"]:"1")
                        .
"&calendar_events_event_list=".($Parent_Event_List);
        }
        else
        {
            
$InsertGoTo "event_schedule.php?day=".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))
                    .
"&calendar_events_attribute=".((isset($_POST["Room"][0]))?$_POST["Room"][0]:"")
                    .
"&calendar_events_id=".((isset($_GET["calendar_events_id"]))?$_GET["calendar_events_id"]:"1")
                    .
"&calendar_events_event_list=".($Parent_Event_List);
        }
    if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
    
$InsertQuery->redirect($InsertGoTo);
}
?>



How can I make this work with the MySQLi plugin?
Is there a way to write loops and IF statements in the plugin?

Sign in to reply to this post

Ray BorduinWebAssist

You could probably do it using WA_IGNORE

So instead of:

php:
if(isset($_POST['Recurring']))

            {
              $InsertQuery->bindColumn("calendar_events_repeats", "s", ((isset($_POST["RecurType"]))?$_POST["RecurType"]:""), "WA_DEFAULT");
            }



you could use:

php:
$InsertQuery->bindColumn("calendar_events_repeats", "s", ((isset($_POST["Recurring"]))?$_POST["RecurType"]:""), "WA_IGNORE");



The final argument tells it what to do when the value is blank. If you use WA_IGNORE it will essentially ignore that line if a blank value is passed in. That should allow you to do conditional column settings without breaking inspection.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jason

Made those changes, and the code still seems to function correctly, but the plugin still doesn't recognize the insert query. Did I miss something?

php:
<?php

$_POST
['calendar_id'] = 1;

if ((((isset(
$_POST["Submit"]))?$_POST["Submit"]:"") != "")) {
        foreach(
$_POST['Room'] as $room)
        {
            
$InsertQuery = new WA_MySQLi_Query($local_i);
            
$InsertQuery->Action "insert";
            
$InsertQuery->Table "calendarevents";
            
$InsertQuery->bindColumn("calendar_events_name",       "s", ((isset($_POST["insert_id"]))?$_POST["insert_id"]:""), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_start_date""s", ((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d')), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_end_date",   "s", ((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d')), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_start_time""s", ((isset($_POST["start_time"]))?$_POST["start_time"]:""), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_end_time",   "s", ((isset($_POST["end_time"]))?$_POST["end_time"]:""), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_repeats",         "s", ((isset($_POST["Recurring"]))?$_POST["RecurType"]:""), "WA_IGNORE");
            
$InsertQuery->bindColumn("calendar_events_repeat_every",  "i", ((isset($_POST["Recurring"]))?$_POST["Frequency"]:""), "WA_IGNORE");
            
$InsertQuery->bindColumn("calendar_events_on_the",        "i", ((isset($_POST["Recurring"]))?$_POST["dow"]:""), "WA_IGNORE");
            
$InsertQuery->bindColumn("calendar_events_repeat_on",     "i", ((isset($_POST["Recurring"]))?$_POST["RecurOn"]:""), "WA_IGNORE");
            
$InsertQuery->bindColumn("calendar_events_occurrence",    "s", ((isset($_POST["Recurring"]))?$_POST["Occurrence"]:""), "WA_IGNORE");
            
$Occurrence_End = ((isset($_POST["Recurring"]) && $_POST['Occurrence'] == 'end-by-end-date')?$_POST["ends_on"]:$_POST['EndAfter']);
            
$InsertQuery->bindColumn("calendar_events_occurrence_end""s"$Occurrence_End"WA_IGNORE");
            
$InsertQuery->bindColumn("calendar_events_occurrence_storage""s"$Occurrence_End"WA_IGNORE");
            
$InsertQuery->bindColumn("calendar_events_type",        "s", (isset($_GET['type']) ? $_GET['type'] : "person"), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_attribute",   "s"$room"WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_attribute_2""s", ((isset($_POST["Position"]))?$_POST["Position"]:""), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_event_list",  "i"$Parent_Event_List"WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_calendar_id""i", ((isset($_POST["calendar_id"]))?$_POST["calendar_id"]:"1"), "WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_attribute_3""s""".((isset($_POST["Category"]))?$_POST["Category"]:"")  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("calendar_events_shift_event_parent_id""i""".((isset($_GET["calendar_events_id"]))?$_GET["calendar_events_id"]:"")  ."""WA_DEFAULT");
            
            
$InsertQuery->execute();
    }
        if(
count($_POST['Room']) > 1)
        {
            
$InsertGoTo "event_schedule.php?day=".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))
                        .
"&calendar_events_id=".((isset($_GET["calendar_events_id"]))?$_GET["calendar_events_id"]:"1")
                        .
"&calendar_events_event_list=".($Parent_Event_List);
        }
        else
        {
            
$InsertGoTo "event_schedule.php?day=".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))
                    .
"&calendar_events_attribute=".((isset($_POST["Room"][0]))?$_POST["Room"][0]:"")
                    .
"&calendar_events_id=".((isset($_GET["calendar_events_id"]))?$_GET["calendar_events_id"]:"1")
                    .
"&calendar_events_event_list=".($Parent_Event_List);
        }
    if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
    
$InsertQuery->redirect($InsertGoTo);
}
?>
Sign in to reply to this post

Ray BorduinWebAssist

Little things like extra line breaks, unexpected tabs, and quotes out of place could cause it to not be recognized.

This line looks right:

$InsertQuery->bindColumn("calendar_events_shift_event_parent_id", "i", "".((isset($_GET["calendar_events_id"]))?$_GET["calendar_events_id"]:"")  ."", "WA_DEFAULT");


This one doesn't:

$InsertQuery->bindColumn("calendar_events_end_time",   "s", ((isset($_POST["end_time"]))?$_POST["end_time"]:""), "WA_DEFAULT");


it would probably be recognized with:

$InsertQuery->bindColumn("calendar_events_end_time", "s", "".((isset($_POST["end_time"]))?$_POST["end_time"]:"")  ."", "WA_DEFAULT");


You would probably have to go through each line to match that syntax before it would be picked up by the UI.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jason

Ok, I'll give that a shot.

Is there a way to do an OR statement on the UPDATEQuery

For example

php:
$UpdateQuery->addFilter("calendar_events_id", "=","i", ((isset($_POST["ShiftID"]))?$_POST["ShiftID"]:"")) OR ("something_else", "=", "i", ((isset($_POST["ShiftID"]))?$_POST["ShiftID"]:"")) OR ("something_else_2", "=", "i", ((isset($_POST["ShiftID"]))?$_POST["ShiftID"]:""));
Sign in to reply to this post

Ray BorduinWebAssist

That isn't supported in the current version. We will be adding more advanced Searching functions in the next update.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jason

I made the changes you suggested (and a few others), but there's still something that the plugin doesn't recognize. Any ideas?

php:
<?php

$_POST
['calendar_id'] = 1;

if ((((isset(
$_POST["Submit"]))?$_POST["Submit"]:"") != "")) {
        foreach(
$_POST['room'] as $room)
        {
            
$InsertQuery = new WA_MySQLi_Query($local_i);
            
$InsertQuery->Action "insert";
            
$InsertQuery->Table "schedule";
            
$InsertQuery->bindColumn("schedule_name""s""".((isset($_POST["person_id"]))?$_POST["person_id"]:"")  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("start_date""s""".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("end_date""s""".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("start_time""s""".((isset($_POST["start_time"]))?$_POST["start_time"]:"")  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("end_time""s""".((isset($_POST["end_time"]))?$_POST["end_time"]:"")  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("repeats""s""".((isset($_POST["Recurring"]))?$_POST["RecurType"]:"")  ."""WA_IGNORE");
            
$InsertQuery->bindColumn("repeat_every""i""".((isset($_POST["Recurring"]))?$_POST["Frequency"]:"")  ."""WA_IGNORE");
            
$InsertQuery->bindColumn("on_the""i""".((isset($_POST["Recurring"]))?$_POST["dow"]:"")  ."""WA_IGNORE");
            
$InsertQuery->bindColumn("repeat_on""i""".((isset($_POST["Recurring"]))?$_POST["RecurOn"]:"")  ."""WA_IGNORE");
            
$InsertQuery->bindColumn("occurrence""s""".((isset($_POST["Recurring"]))?$_POST["Occurrence"]:"")  ."""WA_IGNORE");
            
$Occurrence_End = ((isset($_POST["Recurring"]) && $_POST['Occurrence'] == 'end-by-end-date')?$_POST["ends_on"]:$_POST['EndAfter']);
            
$InsertQuery->bindColumn("occurrence_end""s"$Occurrence_End"WA_IGNORE");
            
$InsertQuery->bindColumn("occurrence_storage""s"$Occurrence_End"WA_IGNORE");
            
$InsertQuery->bindColumn("type""s""".(isset($_GET['type']) ? $_GET['type'] : "person")  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("room""s"$room"WA_DEFAULT");
            
$InsertQuery->bindColumn("position""s""".((isset($_POST["Position"]))?$_POST["Position"]:"")  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("event""i"$Parent_Event_List"WA_DEFAULT");
            
$InsertQuery->bindColumn("schedule_attribute""s""".((isset($_POST["Category"]))?$_POST["Category"]:"")  ."""WA_DEFAULT");
            
$InsertQuery->bindColumn("parent_event_id""i""".((isset($_GET["schedule"]))?$_GET["schedule"]:"")  ."""WA_DEFAULT");
            
$InsertQuery->execute();
        
?>
        <?php
        
}
        if(
count($_POST['room']) > 1)
        {
        
?>
        <?php
            $InsertGoTo 
"""event_schedule.php?day=".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))
                    .
"&schedule=".((isset($_GET["schedule"]))?$_GET["schedule"]:"1")
                    .
"&room="
                    
."&event=".($Parent_Event_List)
                    .
"&calendar=".((isset($_GET["calendar"]))?$_GET["calendar"]:"0") ."";
            if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
            
$InsertQuery->redirect($InsertGoTo);
        
?>
        <?php
        
}
        else
        {
        
?>
        <?php
            $InsertGoTo 
"""event_schedule.php?day=".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))
                    .
"&schedule=".((isset($_GET["schedule"]))?$_GET["schedule"]:"1")
                    .
"&room=".((isset($_POST["Room"][0]))?$_POST["Room"][0]:"")
                    .
"&event=".($Parent_Event_List)
                    .
"&calendar=".((isset($_GET["calendar"]))?$_GET["calendar"]:"0") ."";
            if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
            
$InsertQuery->redirect($InsertGoTo);
        }
}
?>
Sign in to reply to this post

Ray BorduinWebAssist

You can't hand edit any code within the code chunk written by the server behavior. You should instead add any loops or if statements outside of the code chunk to achieve your results and allow further edits through the UI. Here is an example of rewriting your code so that it has all of your custom code but can still be recognized by Dreamweaver:

php:
<?php

$_POST
['calendar_id'] = 1;
if ((((isset(
$_POST["Submit"]))?$_POST["Submit"]:"") != "")) {
  foreach(
$_POST['room'] as $room) {
    
$Occurrence_End = ((isset($_POST["Recurring"]) && $_POST['Occurrence'] == 'end-by-end-date')?$_POST["ends_on"]:$_POST['EndAfter']);
?>
<?php
if ((((isset($_POST["Submit"]))?$_POST["Submit"]:"") != "")) {
  
$InsertQuery = new WA_MySQLi_Query($local_i);
  
$InsertQuery->Action "insert";
  
$InsertQuery->Table "schedule";
  
$InsertQuery->bindColumn("schedule_name""s""".((isset($_POST["person_id"]))?$_POST["person_id"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("start_date""s""".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("end_date""s""".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("start_time""s""".((isset($_POST["start_time"]))?$_POST["start_time"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("end_time""s""".((isset($_POST["end_time"]))?$_POST["end_time"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("repeats""s""".((isset($_POST["Recurring"]))?$_POST["RecurType"]:"")  ."""WA_IGNORE");
  
$InsertQuery->bindColumn("repeat_every""i""".((isset($_POST["Recurring"]))?$_POST["Frequency"]:"")  ."""WA_IGNORE");
  
$InsertQuery->bindColumn("on_the""i""".((isset($_POST["Recurring"]))?$_POST["dow"]:"")  ."""WA_IGNORE");
  
$InsertQuery->bindColumn("repeat_on""i""".((isset($_POST["Recurring"]))?$_POST["RecurOn"]:"")  ."""WA_IGNORE");
  
$InsertQuery->bindColumn("occurrence""s""".((isset($_POST["Recurring"]))?$_POST["Occurrence"]:"")  ."""WA_IGNORE");
  
$InsertQuery->bindColumn("occurrence_end""s""".$Occurrence_End  ."""WA_IGNORE");
  
$InsertQuery->bindColumn("occurrence_storage""s""".$Occurrence_End  ."""WA_IGNORE");
  
$InsertQuery->bindColumn("type""s""".(isset($_GET['type']) ? $_GET['type'] : "person")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("room""s""".$room  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("position""s""".((isset($_POST["Position"]))?$_POST["Position"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("event""i""".$Parent_Event_List  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("schedule_attribute""s""".((isset($_POST["Category"]))?$_POST["Category"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("parent_event_id""i""".((isset($_GET["schedule"]))?$_GET["schedule"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->saveInSession("");
  
$InsertQuery->execute();
  
$InsertGoTo "";
  if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
  
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
  
}
  if(
count($_POST['room']) > 1)
  {
      
$InsertGoTo """event_schedule.php?day=".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))
              .
"&schedule=".((isset($_GET["schedule"]))?$_GET["schedule"]:"1")
              .
"&room="
              
."&event=".($Parent_Event_List)
              .
"&calendar=".((isset($_GET["calendar"]))?$_GET["calendar"]:"0") ."";
      if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
      
$InsertQuery->redirect($InsertGoTo);
  }
  else
  {
      
$InsertGoTo """event_schedule.php?day=".((isset($_POST["start_date"]))?$_POST["start_date"]:date('Y-m-d'))
              .
"&schedule=".((isset($_GET["schedule"]))?$_GET["schedule"]:"1")
              .
"&room=".((isset($_POST["Room"][0]))?$_POST["Room"][0]:"")
              .
"&event=".($Parent_Event_List)
              .
"&calendar=".((isset($_GET["calendar"]))?$_GET["calendar"]:"0") ."";
      if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
      
$InsertQuery->redirect($InsertGoTo);
  }
}
?>



Notice that all of the hand code was added either before or after the chunk of code controlled and written by the server behavior so that it can continue to be in charge of that area.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jason

Perfect! Thanks again Ray! You are awesome as usual!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...