Jump to content

Joak

Members
  • Posts

    20
  • Joined

  • Last visited

Joak's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yes ..... $obj it's an array, and only has 'id' => 2,'name' => 'Jhon'; the value1 and value2 are the names "original" that I recive bye the mobile application ... I forgot change when paste the result of error_log file ..... I can't do "echo" ... I have a hostting server.
  2. I'm getting this values ... [09-Jun-2014 12:44:17] Array ( [id] => 2 [name] => Jhon ) [09-Jun-2014 12:44:17] [09-Jun-2014 12:44:17] [09-Jun-2014 12:44:17] Execute failed to run [09-Jun-2014 12:44:17] Array ( [value1] => 2 [value2] => This was sent from ios to server ) [09-Jun-2014 12:44:17] J [09-Jun-2014 12:44:17] J The code of function function redeem() { // Check for required parameters $json = file_get_contents('php://input'); $obj = json_decode($json,true); // prepare the query $stmt = $this->db->prepare('INSERT INTO prueba (id,nombre) VALUES (?, ?)'); $stmt->bind_param('is',$id,$name); // loop througght he json objects to insert into mysql foreach($obj as $assocArray) { error_log(print_r($obj,true)); $id = $assocArray['id']; $name = $assocArray['name']; error_log(print_r($id,true)); error_log(print_r($name,true)); if (!$stmt->execute()) // execute the query´ { error_log(print_r('Execute failed to run',true)); }else{ $stmt = $this->db->prepare('COMMIT'); $stmt->execute(); } } } I'm confused .... why in the first loop, the variables are null? when excute the Insert .,.... I don't have any value in the variables
  3. Psycho ... I'm only checking the errors in error_log file. My code <?php class RedeemAPI { private $db; // Constructor - open DB connection function __construct() { $this->db = new mysqli('localhost', 'futchoco', 'Futcho1907', 'futchoco_futsoft'); /* verificar la conexión */ if (mysqli_connect_errno()) { printf("Conexión fallida: %s\n", mysqli_connect_error()); exit(); } $this->db->autocommit(FALSE); } // Destructor - close DB connection function __destruct() { $this->db->close(); } // Main method to redeem a code function redeem() { // Check for required parameters $json = file_get_contents('php://input'); $obj = json_decode($json,true); // prepare the query $stmt = $this->db->prepare('INSERT INTO prueba (id,nombre) VALUES (?, ?)'); $stmt->bind_param('is',$id,$name); // loop througght he json objects to insert into mysql foreach($obj as $assocArray) { //error_log(print_r($obj,true)); $id = $assocArray['id']; $name = $assocArray['name']; error_log(print_r($id,true)); error_log(print_r($name,true)); $stmt->execute(); // execute the query $stmt = $this->db->prepare('COMMIT'); $stmt->execute(); } } } // This is the first thing that gets called when this page is loaded // Creates a new instance of the RedeemAPI class and calls the redeem method $api = new RedeemAPI; $api->redeem(); ?>
  4. After assigned the values .... I have this...The id it's null and the name only has the first letter [09-Jun-2014 11:57:32] [09-Jun-2014 11:57:32] [09-Jun-2014 11:57:32] J [09-Jun-2014 11:57:32] J
  5. Psycho ..... I don't have any error ...... but I can't insert the record
  6. This contents of $obj [09-Jun-2014 10:48:55] Array ( [id] => 2 [name] => Jhon )
  7. I can do the commit ..... but the table has the number 0 has id, and null in name column
  8. Ch0cu3r, thanks for you comment. I fix it, I have not any error message, but how can I do the commit?$stmt = $this->db->commit();
  9. Hi guys A mobile application send data in Json format, so I want to insert the data into Mysql table, when I try to insert I have gotten the error "PHP Warning: mysqli::prepare() expects exactly 1 parameter, 3 given", my table only has 2 columns, "id" and "name" column. The array has this data ( [0] => ('id', '2') [1] => ('name', 'Jhon') ) The function to parse and insert data ... function redeem() { // Check for required parameters $json = file_get_contents('php://input'); $obj = json_decode($json,true); // Assumes $obj == array(0 => $assocArray, 1 => $assocArray) foreach($obj as $index => $assocArray) { // Assumes $assocArray == array(0 => array('id' => '2'), 1 => array('name' => 'John')) $stmt = $this->db->prepare('INSERT INTO prueba (id,nombre) VALUES (%d,%s)',$assocArray[0]['id'],$assocArray[1]['name']) or die(mysqli_error($this->db)); $stmt->execute(); } }
  10. Hello guys. I execute a query and then put the records into array, the query has ORDER BY .... why I don't have the same order in the array?, If I execute the query, the record one it's no the same that $arreglo[0]. $stmt = $this->db->prepare('SELECT a.id_torneo, b.tor_nombre, a.id_jornada, a.id_juego, a.cal_fecha_hora, id_arbitro, a.cal_estatus, a.cal_default, c.id_equipo, d.equ_nombre, c.enc_locvis, e.id_jugador, e.jug_nombre_pila, e.jug_apellido_pat, e.jug_apellido_mat, e.jug_representante, e.jug_numero, jug_fechimp_reg FROM calendario a, torneo b, encuentro c, equipo d, jugador e WHERE a.id_cliente =? AND a.id_sucursal = ? AND date(a. cal_fecha_hora)= date(?) AND a.id_cliente = b.id_cliente AND a.id_sucursal = b.id_sucursal AND a.id_torneo = b.id_torneo AND a.id_cliente = c.id_cliente AND a.id_sucursal = c.id_sucursal AND a.id_torneo = c.id_torneo AND a.id_jornada = c.id_jornada AND a.id_juego = c.id_juego AND a.id_cliente = d.id_cliente AND c.id_sucursal = d.id_sucursal AND c.id_torneo = d.id_torneo AND c.id_equipo = d.id_equipo AND d.id_cliente = e.id_cliente AND d.id_sucursal = e.id_sucursal AND d.id_torneo = e.id_torneo AND d.id_equipo = e.id_equipo AND e.jug_estatus = "A" ORDER BY 5,11') or die(mysqli_error($this->db)); $stmt->bind_param("iis", $cliente, $sucursal, $fecha); $stmt->execute(); $stmt->bind_result($id_torneo, $tor_nombre, $id_jornada, $id_juego, $fecha_partido, $id_arbitro, $cal_estatus, $cal_default, $id_equipo, $equipo_nombre, $locvis, $id_jugador, $jug_nombre, $jug_apellidop, $jug_apellidom, $jug_rep, $jug_playera, $jug_fechareg); $arreglo = array() ; $contador = 0; while ($stmt->fetch()) { $arreglo[$contador] = array("id_torneo"=>$id_torneo,"torneo_nombre"=>$tor_nombre,"id_jornada"=>$id_jornada,"id_juego"=>$id_juego,"fecha_partido"=>$fecha_partido,"id_arbitro"=>$id_arbitro,"cal_estatus"=>$cal_estatus,"cal_default"=>$cal_default,"id_equipo"=>$id_equipo,"equipo_nombre"=>$equipo_nombre,"locvis"=>$locvis,"id_jugador"=>$id_jugador,"jug_nombre"=>$jug_nombre,"jug_apellidop"=>$jug_apellidop,"jug_apellidom"=>$jug_apellidom,"jug_rep"=>$jug_rep,"jug_player"=>$jug_playera,"jug_fechareg"=>$jug_fechareg); $contador++; }
  11. WEBSTYLES ... you right .... ALL are player's Vodka team .. they have to exist in the first level {JSON} {0} id_equipo:"7" nom_equipo:"Vodka Juniors" locvis: "L" [ ]Jugadores {0} id_jugador:"1" jugador_nom:"Juan Carlos"
  12. Thanks Psycho The problem it's when I want to convert to JSON format with your code I got this... {JSON} {0} id_equipo:"7" nom_equipo:"Vodka Juniors" locvis:"L" Jugadores {0} {1} And I want this format ..... notice Jugadores it's another level of my first array(Equipos) {JSON} {0} id_equipo:"7" nom_equipo:"Vodka Juniors" locvis:"L" Jugadores {0} {1}
  13. Zane .... I have gotten the same result .... Jugadores doesen't part for the Equipo array $equipo['Jugadores'] = $jugador; { "0": { "id_equipo": "7", "nom_equipo": "Vodka Juniors", "locvis": "L" }, "Jugadores": [ { "id_jugador": "12", "jugador_nom": "Omar", "jugador_pat": "Ortiz", "jugador_mat": "Flores", "jug_repre": "N", "jug_playera": "16", "fechareg": null } ] } I want this.... { "0": { "id_equipo": "7", "nom_equipo": "Vodka Juniors", "locvis": "L", "Jugadores": [ { "id_jugador": "12", "jugador_nom": "Omar", "jugador_pat": "Ortiz", "jugador_mat": "Flores", "jug_repre": "N", "jug_playera": "16", "fechareg": null } ] } }
  14. Hello WebStyles The results... //Jugadores Array Array ( [0] => Array ( [id_jugador] => 12 [jugador_nom] => Omar [jugador_pat] => Ortiz [jugador_mat] => Flores [jug_repre] => N [jug_playera] => 16 [fechareg] => ) [1] => Array ( [id_jugador] => 1 [jugador_nom] => Francisco [jugador_pat] => Rojas [jugador_mat] => Ortega [jug_repre] => N [jug_playera] => 17 [fechareg] => ) ) //Equipo Array Array ( [0] => Array ( [id_equipo] => 7 [nom_equipo] => Vodka Juniors [locvis] => L ) )
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.