Is it possible to insert by checking the fields?

3

My problem is: "I have a array that stores data of duas combos . In a combo I add " P " and then the value typed Ex: In the other one I add at the start "S" and it gets S11111111 .But in my database table I have separate fields for P and S , so you would like to know if you have a insert to check if the first letter is P or S , so you can enter in your fields!

    
asked by anonymous 26.08.2014 / 14:24

2 answers

4

yes ... a way to do this in php:

$str = $_ POST ou GET['sua variavel']

$posição1 = str_split($str,1);

switch ($posição1) {
    case 'P': //Faz o que voce quer;
    break;
    case 'S': //Faz o que voce quer;
    break;
    default: break;
}
    
26.08.2014 / 14:30
2

Another way to extract the first character of a string is to use substr

$char = substr($str, 0, 1); //copia um caracter da posição zero

or pass the zero index of the variable

$char = $str[0];
    
26.08.2014 / 14:41