mercredi 1 août 2018

php else to open link

I need to open link instead of return $error; on bellow code:

else {
                    $error->add( 'sms_code_enter', sprintf( __( '<strong>Cont creat dar nevalidat. <a href="#" class="sms-code-field">Click Aici</a> pentru a introduce codul primit pe telefon.</strong>', 'wedevs' ) ) );

                    return $error;
                }

I tried with this code but it does nothing:

 else {
                    $error->add( 'sms_code_enter', sprintf( __( '<strong>Cont creat dar nevalidat. <a href="#" class="sms-code-field">Click Aici</a> pentru a introduce codul primit pe telefon.</strong>', 'wedevs' ) ) );

                   header('Location: http://destination.com');
                }

cant add Jason connection in if statement

i am working on website and i am want upload data to database i had made connection moving throw app.aspx.cs

but there's this below issue is keep showing very time i start the app

Severity    Code    Description Project File    Line    Suppression State
Error   CS0149  Method name expected    PoshaWeb    C:\Users\zatoo\Desktop\Pusha\workweb\PoshaWeb\App.aspx.cs   35  Active

this is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Configuration;

namespace PoshaWeb
{
    public partial class App : System.Web.UI.Page
    {   
        protected void Page_Load(object sender, EventArgs e)
        {

            Stream body = Context.Request.InputStream;
            System.Text.Encoding Encoding = Context.Request.ContentEncoding;
            StreamReader reader = new StreamReader(body, Encoding);
            String inJson = reader.ReadToEnd();
            var s = Newtonsoft.Json.JsonConvert.DeserializeObject(inJson);
            System.Data.SqlClient.SqlConnection Conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["MyPoshDB"].ConnectionString);
            Conn.Open();

            System.Data.SqlClient.SqlCommand Comm = new System.Data.SqlClient.SqlCommand
            {
                Connection = Conn
            };
            try
            {
                if (s("type").ToString = "addstudent")
                {
                    Comm.CommandText = "INSERT INTO Members (MemName, MemMobile, MemEmail, MemID, MemGovID, MemDocURL, MemPicURL) VALUES(N'" + s("name").ToString + "', N'"+ s("mobile").ToString + "', N'" + s("email").ToString + "', N'" + s("recordnumber").ToString + "', N'" + s("idnumber").ToString + "', N'" + s("picturepath").ToString + "', N'" + s("documentpath").ToString + "')";
                    Comm.ExecuteNonQuery();
                    Response.Write("{\"result\":\"success\"}");
                }
            }
            catch (Exception ex)
            {
                Page.Response.Write("{\"result\":\"fail\",\"desc\":" + Newtonsoft.Json.JsonConvert.SerializeObject(ex.Message) + "}");
            }
            Conn.Close();
        }

    }
}

i am still have problem that var S not working inside {if} please help

Transform if statement in SAS to R

I would like to change a IF statement in SAS to R but i have some problems. In SAS i have this code below :

data new_data;
set my_data;
format end_date date8.;
by my_id;
retain previous_end_date "01JAN1900"d ;
if first.my_id then previous_end_date = end_date ;
else if start_date <= previous_end_date and previous_end_date <= end_date then do; 
available = "NO"; previous_end_date = end_date; end;
else if start_date <= previous_end_date and previous_end_date > end_date then 
do; available ="NO"; end;
else previous_end_date = end_date;
run;

So in R i tried this :

my_data <- my_data %>% group_by(my_id) %>% mutate(rank = row_number()) %>% as.data.frame()

This is a part of my dataframe

           my_id       type start_date   end_date rank
1      02000lfo0   10_Illim 2018-05-15 2018-05-25    1
2      02001zjtu   15_Class 2018-05-08 2018-06-02    1
3      02002akb5   25_Class 2018-05-07 2018-07-06    1
4      02002akdy   05_Illim 2018-05-06 2018-05-13    1
5      02002akdy   05_Illim 2018-05-16 2018-05-23    2
6      02002akdy   20_Illim 2018-05-24 2018-06-23    3
7      02002cz12    25_Data 2018-05-07 2018-06-06    1
8      02002db80    10_EUMG 2018-05-17 2018-05-31    1
9      02002de79   25_Class 2018-05-01 2018-06-30    1
10     02002dlmi    10_Data 2018-05-02 2018-05-10    1
11     02002dlmi   10_Class 2018-05-02 2018-05-15    2
12     02002dlmi   10_Class 2018-05-03 2018-05-16    3
13     02002dlmi    10_Data 2018-05-05 2018-05-13    4
14     02002dlmi    10_Data 2018-05-06 2018-05-14    5
15     02002dlmi    10_Data 2018-05-07 2018-05-15    6
16     02002dlmi    10_Data 2018-05-08 2018-05-16    7
17     02002dlmi    10_Data 2018-05-09 2018-05-17    8
18     02002dlmi   10_Class 2018-05-09 2018-05-22    9
19     02002dlmi   10_Class 2018-05-11 2018-05-24   10
20     02002dlmi    10_Data 2018-05-12 2018-05-20   11
21     02002dlmi    10_Data 2018-05-15 2018-05-23   12
22     02002dlmi    10_Data 2018-05-16 2018-05-24   13
23     02002dlmi   10_Illim 2018-05-17 2018-05-27   14




if (my_data$rank== 1){
  my_data$previous_end_date == my_data$end_date
} else if (my_data$start_date <= my_data$previous_end_date & my_data$previous_end_date <= my_data$end_date) {
  my_data$available== "NON"
} else if (my_data$start_date <= my_data$previous_end_date & my_data$previous_end_date > my_data$end_date) {
  my_data$available="NO"
} else { my_data$previous_end_date == my_data$end_date}

But this returns an error :

Warning messages:

1: In if (my_data$rank == 1) { : the condition has length > 1 and only the first element will be used

2: Unknown or uninitialised column: 'previous_end_date'.

Do you have an idea to rewrite this SAS code in R ?

Undestanding A While Loop With Conditionals

I am just beginning with python and need some help understanding the logic. The micro programm am writing will ask the user to enter name and verify if the name has spaces, returning error and asking the user to reenter. ( I know I can use the isalpha() function to make it happen), but I want to know what I am doing wrong here, that the program runs for first time and the after I re-enter the name even with spaces, the execution will happen. Thanks in advance

s = input("Please enter your name: ")
def has_space(item):
    for i in item:
        if i.isspace():
            print('Cannot contain spaces.')
            s = input("Please enter your name: ")
while 1:
    if has_space(s):
        print('0')
    else:
        break


print('Welcome ' + s)

How to eliminate redundant if statement in set label text function?

I have Python functions that is used to set labels based on input parameters. There is a parameter called reset which resets all labels. How can I get rid of redundant if not reset? There should be a smarter approach...

def set_labels_text(fn, ft, t=None, a=None, i=None, reset=False):
    tt = ''
    at = ''
    it = ''

    if ft == 1
        if not reset:
            tt = 'bla bla 1 %s' % t
            at = 'bla bla 2 %s' % a
        get_component('template' + ft).get_component(fn + 'Label1').text = tt
        get_component('template' + ft).get_component(fn + 'Label2').text = at
    else:
        if not reset:
            it = 'bla bla 3 %s' % i
        get_component('template' + ft).get_component(fn + 'Label3').text = it

How to re-run code after invalid scanner input in JAVA

I just started learning JAVA and I can't find a way to re-run this code after a user enters a wrong data type. I've searched on stack overflow but I couldn't find a solution. Thanks.

int j = 0;
System.out.println("Hello, how many numbers would you like to save?");

boolean hasNextInt2 = scanner.hasNextInt();

if(hasNextInt2){
    j = scanner.nextInt();
} else {
    System.out.println("Please enter a valid number");

}

Python Syntax error in for loop

I am trying to extract some particular data from the JSON so i wrote the following code

echo "$Group_ID" | python -c 'import json,sys;obj=json.load(sys.stdin); for o in obj: if o[name] == "Admin_UserGroup": print o["id"]';

But its throwing error

Can someone please help and tell me what wrong with the code?

File "", line 1
import json,sys;obj=json.load(sys.stdin); for o in obj: if o[name] == "Admin_UserGroup": print o["id"]

Here is the version details

[root@mdfdevha1 ~]# python -V
Python 2.7.5

EDIT 1 : Attaching the image

enter image description here