Ver Mensaje Individual
  #10 (permalink)  
Antiguo 13/09/2012, 07:04
Avatar de gerardo1987
gerardo1987
 
Fecha de Ingreso: septiembre-2012
Ubicación: Tamaulipas
Mensajes: 106
Antigüedad: 12 años, 5 meses
Puntos: 2
Pregunta Respuesta: Pasar Valor de Columna MySQL a Variable

Cita:
Iniciado por jrsantos Ver Mensaje
Código PHP:
Ver original
  1. mysql_connect("localhost", "root", "root*") or die(mysql_error());
  2. mysql_select_db(contencion) or die(mysql_error());
  3.  
  4. $variable = "x";
  5. $datos = mysql_query("SELECT campo1, campo2 FROM tabla WHERE campo1='$variable'  ");
  6.  
  7. if (!mysql_num_rows($datos)) {
  8. echo "No existe datos para esta variable ";
  9. die();
  10. }
  11. while($row = mysql_fetch_array($datos)){
  12. $variable2 = $row ['campo2'];
  13. }
  14. echo $variable2;
  15. ?>

Saludos!
Todavia no me sale, tendre algun error de sintaxis, aqui esta mi codigo

Código PHP:
$variable "$_POST['variabledepost']";
$datos mysql_query("SELECT campo1, campo2 FROM tabla WHERE campo1='$variable'");
if (!
mysql_num_rows($datos)) {
echo 
"No existe datos para esta variable ";
die();
}
while(
$row mysql_fetch_array($datos)){
$variable2 $row ['campo2'];
}
echo 
$variable2
Mencionando tambien que la variable la estoy agarrando de un POST
__________________
Carlos G. Treviño
Ing. Mecatrónico