lundi 26 décembre 2016

Include files using condition of session

I have 4 types of users in my system. So i have to include header files using conditions.

I tried below code.

if($this->session->userdata('email_admin')){
     include('header_admin');
}
if($this->session->userdata('email_zone_manager')){
     include('header_zone_manager');
}
if($this->session->userdata('email_state_manager')){
     include('header_state_manager');
}
if($this->session->userdata('email_user')){
    include('header_user');
}

When i tried with echo something and exit() its working means condition works file but header css and js etc. are not including.

   if($this->session->userdata('email_admin'))
   {    
        echo "Admin";
        include('header_admin');
   }

Above code echo "Admin" but header_admin's contents are not including.

dimanche 25 décembre 2016

how to atomically switch view controllers in a else if statement in swift 3

within the else part of a else if statement i would like the view controller to automatically switch to another view controller lets say "b". So this below is what I am looking for.

 if {

  stop.timer

 }
 else {
switch to b}

what is the code to switch to b? Thanks

Python how to convert the second value in a list to int

I am presently building a simple program that will determine a persons horoscope sign depending on the month and date they assign, I am running into issues checking the 2nd value in a list, I have to convert only the second value to an int, I'm sorry I know this is a pretty dumb question,

Here is what I have so far

user_day_month = input("Enter your birth month and day").lower().split(' ')
print(user_day_month)
    user_sign = ""

if (user_day_month[0]=="january" and user_day_month[1]>=20) or (user_day_month[0]=="february" and user_day_month[1]<=18):
    user_sign = "Aquarius"
    print(user_sign)

elif (user_day_month[0]=="february" and user_day_month[1]>=19) or (user_day_month[0]=="march" and user_day_month[1]<=20):
    user_sign = "Pisces"

Thank you for your patience, I look forward to hearing your recommendations

Elegant way for quick IF statement in blade

I´m new to Laravel and I know I can echo variables within double curly brackets like this:

<p></p>

Now in my case I have a form that sometimes contains the variable $posts (which is the table by the way) to update and sometimes doesn´t contain it to insert a row depending on the parameters in the URL.

Of course if there is no post then the part "->id" will fail. Is there an elegant way to make a quick IF statement here, like:

<?php if ($posts) echo $posts["id"]; ?>

but just using the blade engine.

I know I can use @if around the HTML-block but then I would have to write that block twice all the time.

else block does not work properly

I try to create a book list in python.

Here are the sample list:

The list contains book_id, bookName, writerName, writerSurname, cost objects.

  books = [
     [45623, 'Ptyhon', 'Mustafa', 'Basak', 23],
     [99878, 'Linux Networks', 'Mustafa', 'Basak', 26],
     [98938, 'Operating Systems', 'Ali', 'Akinci', 17],
     [98947, 'PHP and AJAX', 'Haydar', 'Baskan', 25]
     ]

I want to search the list according to writer surname.

 while 1:
     writerSurname = input('Pls enter the writer's surname.')
     if writerSurname not in ['exit', 'Exit']:
         for k in books:
             if str(writerSurname) == k[3]:
                 print(k[1],'writer', k[2],k[3], "cost is", k[4],"TL")

     else:
         print(writerSurname, 'there is no such a person.')
         break

But else block does not work properly. When I type a surname which is not in book list, it does not show print(writerSurname, 'there is no such a person.') line. Can someone advise where I do make a mistake ?

PHP Match Text from JSON

I have a JSON file with data in, I'm trying to do a live search box. I have the code below so far, there is a few problems I can't seem to get around!

If the field matches I would like to show the results, but if the field does not match it should just show no match, currently though it will show no match for each foreach. In the code below it will only every show no matches.

Is there something I'm not doing right?

$str_tenapp = file_get_contents('../site-wide/cron/cache/tenants-applicants.json'); 
$str_tenapp = str_replace("\xEF\xBB\xBF",'',$str_tenapp); 
$obj_tenapp = json_decode($str_tenapp); 

$searchterm = $_REQUEST['query'];
$onetitle = 0;
$matchnumber = 0;
foreach($obj_tenapp->response->entries as $value) 
{   
    $onetitle++;
    if ($onetitle==1){ echo '<p class="tiles-title" style="background:#f4f5f7; font-size:10.5px;font-family: Open Sans;letter-spacing: 0.5px;font-weight: 600; color:#56646e; border:none!important;">APPLICANTS & TENNATS</p>'; }

    if(strcasecmp($value->{2.3},$searchterm)==0){
    $matchnumber++;
    echo '<p>'. $value->{2.3} .' '. $value->{2.6} .'</p>';
    } else if ($matchnumber==0){ echo '<p>No applicants or tenants match <b>'. $searchterm .'</b></p>'; return; }
};

How to define condition based on get url value

When a user clicks on "List View" link then I want to show them the "List View" HTML and when they click on "Grid View" I want to show "Grid View" HTML. I've defined the following links to click-

<a href="?view=list">List View</a> <br>
<a href="?view=grid">Grid View</a>

Then I defined the following condition with PHP get method to show user the desired output-

<?php
if( isset( $_GET['view'] ) == 'list' ){
  echo "This is List view";
}else if( isset($_GET['view'] ) == 'grid' ){
  echo "This is Grid view";
}

This condition is not working. If I change "view" to "view_1" and "view_2" from URL then my condition is working as well.

<?php
if( isset( $_GET['view_1'] ) == 'list' ){
  echo "This is List view";
 }else if( isset($_GET['view_2'] ) == 'grid' ){
  echo "This is Grid view";
 }
?>
<br>
<a href="?view_1=list">List View</a> <br>
<a href="?view_2=grid">Grid View</a>

But I don't want to change the "view" key. I just want to keep the same key and different value for both URL to do the conditional statement.
Is it possible?