Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/08/2011, 06:43
Avatar de mauromalmsteen
mauromalmsteen
 
Fecha de Ingreso: mayo-2011
Ubicación: Buenos Aires
Mensajes: 8
Antigüedad: 13 años
Puntos: 0
Problema con variable php en Mysql

Hola gente, que tal? Me llamo Mauro y soy de Buenos Aires. Estoy iniciando hace algunos meses con php. Me he comprado libros y leido muchos tutoriales de internet sobre el tema, aunque hay muchas cosas que me estan haciendo pegar la cabeza contra la pared!! como le sucede a la mayoria

El tema en cuestion...

Estoy trabajando en un proyecto donde me manejo principalmente con una base de datos en Mysql. En esa base tengo los siguientes datos, por ejemplo:



Lo que estoy intentando hacer es lo siguiente: ingresando a través de un formulario de texto un numero de "id_Movil", que genere una consulta a la db, tomando únicamente la fila que contenga ese numero de id_Movil ingresado.

Estoy intentando hacerlo de la siguiente manera:

Formulario para ingresar el numero de id_Movil (incluido en el index.php) :

Código PHP:
<form action="id_movil.php" id="validate_form" method="GET"><div><label for="Id_Movil"Ingrese su Id de movil: </label><input id="movil" type="text" name="Id del movil" value="" /></div>
<
input type="submit" class="button" value="Enviar"  /> </form
El cual ejecutará id_movil.php :

Código HTML:
function load() {
      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(-34.660609,-58.580448),
        zoom: 5,
        mapTypeId: 'roadmap'
      });
      var infoWindow = new google.maps.InfoWindow;

      // ACA EL XML QUE CAPTURA LOS DATOS
      downloadUrl("xml_unico_id.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("idMovil");
          var address = markers[i].getAttribute("address");
          var type = markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("Latitud")),
              parseFloat(markers[i].getAttribute("Longitud")));
          var html = "<b>" + name + "</b> <br/>" + address;
          var icon = customIcons[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });
    }
De ahí mismo debería descargar "xml_unico_id.php" donde es ahí que tomo el numero ingresado en la selección de id:

Código PHP:
// Conecta a la base
$connection=mysql_connect ("xxx.xxx.xxx.xxx"$username$password);
if (!
$connection) {
  die(
'Not connected : ' mysql_error());
}

// Set the active mySQL database
$db_selected mysql_select_db($database$connection);
if (!
$db_selected) {
  die (
'Can\'t use db : ' mysql_error());
}

$query"SELECT Id_Movil=$Id_Movil from gps_ultpos"
$result mysql_query($query);
if (!
$result) {
  die(
'Consulta invalida: ' mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){

  echo 
'<marker ';
  echo 
'idMovil="' parseToXML('&','&amp;'$row['IdMovil']) . '" ';
  echo 
'address="' parseToXML($row['address']) . '" ';
  echo 
'Latitud="' $row['Latitud'] . '" ';
  echo 
'Longitud="' $row['Longitud'] . '" ';
  echo 
'type="' $row['type'] . '" ';
  echo 
'/>';
}

echo 
'</markers>'
Mi problema es que no puedo tomar el dato que necesito de la db, o no entiendo bien como hacerlo, a partir de una variable generada por el texto ingresado en el formulario del index. Lo intenté hacerlo usando

$query= "SELECT Id_Movil=$Id_Movil from gps_ultpos"; // Debería tomar únicamente la fila con el el Id_Movil

Si realizo la consulta sin tomar en cuenta esa variable

$query= "SELECT Id_Movil from gps_ultpos";

funciona perfectamente, aunque selecciona todos los Id_Movil, lo cual no me sirve para este caso...

Si alguien me pudiera dar alguna pista en que le estoy errando, o decirme si estoy haciendo una gran burrada (jaja) le estaré muy agradecido, ya que no le estoy podiendo encontrar la vuelta luego de leer muchos tutoriales.

Muchisimas gracias, Mauro