Jump to content

new to php


patchido

Recommended Posts

hey i dont know why my array is not being echoed, it it populated, but not echoed, here is my code

 

im really new to php, thanks :)

 

$query= "INSERT INTO tokens (producto, precio, photo)VALUES ";
for ($i=1; $i<sizeof($precio_array); $i++){
global $nombre_array;
global $pic_array;
global $precio_array;

$query .="($nombre_array[i] ,$precio_array[i] , $pic_array[i])";

}
echo $query;

 

Link to comment
Share on other sites

ok, this is my whole code

<?php
$xml = simplexml_load_file("cursos.xml");
$precio_array=array();
$nombre_array=array();
$pic_array=array();
if (count($xml->Articulo) > 0) {
$i=0;

    foreach ($xml->Articulo as $node) {
        // This prints out each of the models
    	$precio= substr($node->Precio.chr(10), 0, -3);
	array_push($precio_array, $precio);
	array_push($pic_array,$node->Pic.chr(10));
	array_push($nombre_array,$node->Nombre.chr(10));
	$i++;
    }
}

//print_r($precio_array);echo"<br />";
//print_r($pic_array);echo"<br />";
//print_r($nombre_array);

$query= "INSERT INTO tokens (producto, precio, photo)VALUES ";
for ($i=1; $i<sizeof($precio_array); $i++){
global $nombre_array;
global $pic_array;
global $precio_array;

$query .="($nombre_array[i] ,$precio_array[i] , $pic_array[i])";

}
echo $query;
?>

Link to comment
Share on other sites

thanks :)

 

 

another issue, will that create a correct sql query???

 

this is my result

INSERT INTO tokens (producto, precio, photo)VALUES ('Cuñas hexagonales para concreto ' ,'10 ' , 'images/tokens/2.jpg ')('Cutter reforzado 5'' ' ,'7 ' , 'images/tokens/3.jpg ')('Kg de Piola ' ,'16 ' , 'images/tokens/4.jpg ')('Brújula ' ,'' , 'images/tokens/5.jpg ')('Cutter super reforzado 6'' ' ,'20 ' , 'images/tokens/6.jpg ')('Cutter de Plastico ' ,'3 ' , 'images/tokens/7.jpg ')('Guantes de Carnaza ' ,'18 ' , 'images/tokens/8.jpg ')('Tanque de Propano ' ,'7 ' , 'images/tokens/9.jpg ')('Caja de plastico 16'' ' ,'25 ' , 'images/tokens/10.jpg ')('Metro de soga ' ,'3 ' , 'images/tokens/11.jpg ')('Caja de plastico 20'' ' ,'47 ' , 'images/tokens/12.jpg ')('Casero de madera ' ,'53 ' , 'images/tokens/13.jpg ')('Michigan de fibra 36'' ' ,'53 ' , 'images/tokens/14.jpg ')('Michigan de madera 36'' ' ,'55 ' , 'images/tokens/15.jpg ')('Doble michigan 36'' ' ,'65 ' , 'images/tokens/16.jpg ')('Pulaski 36'' ' ,'75 ' , 'images/tokens/17.jpg ')('Media labor 36'' ' ,'40 ' , 'images/tokens/18.jpg ')('Cazadoras 14'' ' ,'28 HT C' , 'images/tokens/19.jpg ')('Martillo golpe seco ' ,'31 ' , 'images/tokens/20.jpg ')('Mazo de hule ' ,'10 ' , 'images/tokens/21.jpg ')('Irrigación mango largo ' ,'35 ' , 'images/tokens/22.jpg ')('Pala cuadrada ' ,'35 ' , 'images/tokens/23.jpg ')('Pala Escarramán ' ,'35 ' , 'images/tokens/24.jpg ')('Navaja 15 funciones ' ,'38 ' , 'images/tokens/25.jpg ')('Zapapico 7lb ' ,'54 ' , 'images/tokens/26.jpg ')('Estufilla de propano ' ,'17' , 'images/tokens/27.jpg ')('Estufilla de gasolina coleman ' ,'130 ' , 'images/tokens/28.jpg ')('Hielera Igloo ' ,'49 ' , 'images/tokens/29.jpg ')('Lampara de propano coleman ' ,'34 ' , 'images/tokens/30.jpg ')('Lampara de gasolina coleman ' ,'164 ' , 'images/tokens/31.jpg ')('Tienda estilo Congaree ' ,'280 ' , 'images/tokens/32.jpg ')('Tienda estilo Bryce Canyon ' ,'309 ' , 'images/tokens/33.jpg ')('Generador de gasolina ' ,'535 ' , 'images/tokens/34.jpg ')('Motosierra ' ,'780 ' , 'images/tokens/35.jpg ')('Compresor de banda ' ,'1,168 ' , 'images/tokens/36.jpg ')

Link to comment
Share on other sites

No you need a comma between your values.

 

Try this

 

<?php 

$xml = simplexml_load_file("cursos.xml");
$values = array();
if (count($xml->Articulo) > 0) {
$i=0;

    foreach ($xml->Articulo as $node) {
        // This prints out each of the models
    	$precio = substr($node->Precio.chr(10), 0, -3);
// You have to escape the data, so ' will be converted to \' etc.
$precio = mysql_real_escape_string($precio);
$nombre = mysql_real_escape_string($node->Nombre.chr(10));
$pic =    mysql_real_escape_string($node->Pic.chr(10));
$values[] = "('$nombre','$precio','$pic'";
    }
}
$query =  "INSERT INTO tokens (producto, precio, photo) VALUES ";
$query .= implode(',', $values);
echo $query;

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.