0

Url の最後の 2 文字をデータベースに挿入しようとしています。挿入するたびに「2147483647」のような数字が必要です。Url の正しい最後の 2 文字を挿入する方法。'$array = json_decode(stripslashes($_POST['data']));

for($i = 0, $l = sizeof($array); $i < $l; $i++){ $obj = $array[$i];

if($obj->{'leaf'} == true){
    $leaf = 1;
} else{
    $leaf = 0;
}

if($obj->{'parentId'} == null){
    $parentID = 'null'; 
} else{
    $parentID = $obj->{'parentId'};
}

if($obj->{'Duration'}==''){
    $duration = 0;
} else{
    $duration = $obj->{'Duration'};
}




$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

$gantt_id = substr(strrchr($url, '='), 1);
/*if($obj->{'gantt_id'}==null){
    $gantt_id = 0;
} else{
    $gantt_id = $obj->{'gantt_id'};
}
*/
$q = 'INSERT INTO j_gantt_tasks SET Name = "'.$obj->{'Name'}.'", StartDate = "'.$obj->{'StartDate'}.'", EndDate = "'.$obj->{'EndDate'}.'",
      Duration = "'.$obj->{'Duration'}.'", DurationUnit = "'.$obj->{'DurationUnit'}.'", PercentDone = "'.$obj->{'PercentDone'}.'", Cls = "'.$obj->{'Cls'}.'", gantt_id="'.$gantt_id.'",
      parentId = "'.$obj->{'parentId'}.'"';

$r = mysql_query($q);
if(!$r){
    echo db_error($q);
}

$obj->{'id'} = mysql_insert_id();

echo json_encode($array);'

4

1 に答える 1

0

部分文字列を試してください

$url = (!empty($_SERVER['HTTPS'])) ?
     "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : 
     "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];


$last2 = substring($url,-2);
于 2012-08-09T14:25:06.543 に答える