Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/12/2011, 16:34
php1
 
Fecha de Ingreso: junio-2011
Mensajes: 36
Antigüedad: 12 años, 11 meses
Puntos: 0
como condiciono una variable con un campo de la bd

Hola tengo lo siguiente:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_laboratorio, $laboratorio);
$query_productos = "SELECT * FROM ingreso_productos";
$productos = mysql_query($query_productos, $laboratorio) or die(mysql_error());
$row_productos = mysql_fetch_assoc($productos);
$totalRows_productos = mysql_num_rows($productos);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table border="1">
<tr>
<td>nombre</td>
<td>Tipo</td>
<td>costo_producto</td>
<td>precio_venta</td>
<td>fecha</td>
<td>Existencia</td>
<td></td>
</tr>

<?php
$id=$row_productos['id_producto'];
$agregarlo="<a href='listaprueba.php?id_producto=$id&accion=agreg ar'>Agregar
</a>"?>
<?php do { ?>
<tr>
<td><?php echo $row_productos['nombre']; ?></td>

<td><?php echo $row_productos['Tipo']; ?></td>
<td><?php echo $row_productos['costo_producto']; ?></td>
<td><?php echo $row_productos['precio_venta']; ?></td>
<td><?php echo $row_productos['fecha']; ?></td>
<td><?php echo $row_productos['Existencia']; ?></td>
<td><?php echo $agregarlo ?></td>
</tr>
<?php } while ($row_productos = mysql_fetch_assoc($productos)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($productos);
?>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<?php
if(isset($_GET['id_producto']))
$id=$_GET['id_producto'];

if(isset($_GET['accion']))
$realizar=$_GET['accion'];
else
$realizar='vacio';

switch($realizar){

case "agregar";
if(isset($_SESSION['lab_manager'][$id]))
$_SESSION['lab_manager'][$id]++;
else
$_SESSION['lab_manager'][$id]=1;

break;

case "eliminar";
if(isset($_SESSION['lab_manager'][$id])){
$_SESSION['lab_manager'][$id]--;

if($_SESSION['lab_manager'][$id]==0);
unset($_SESSION['lab_manager']['$id']);
}
break;

case "vacio";
unset($_SESSION['lab_manager']);
break;



}
//planteamiento
if(isset($_SESSION['lab_manager'])){

echo "<table border='1'>";
echo "<tr>";
echo "<td>Nombre </td>";
echo "<td>Cantidad </td>";
echo "<td>Valor</td>";
echo "</tr>";


$total=0;

foreach($_SESSION['lab_manager']as $id=> $existencia){


$consulta=mysql_query("select * from ingreso_productos where id_producto=$id" ,$db);
$mostrar=mysql_fetch_array($consulta);
$nombre=$mostrar['nombre'];
$precio_venta=$mostrar['precio_venta'];
$costo=$existencia*$precio_venta;
$total=$total+$costo;


echo "<tr>";
echo "<td>$nombre</td>" ;
echo "<td>$existencia <a href='principal.php?id_producto=$id&accion=elimina r'>rebajar</a></td>" ;
echo "<td>$costo</td>" ;
echo "</tr>";


}//termina foreach

echo "<tr>";
echo "<td>Total: </td>";
echo "<td>$total </td>";

echo "</tr>";
echo "</table>";
echo "<a href='principal.php?id_producto=$id&accion=vacio'> Cancelar</a> || <a href='prueba1.php'>Seguir comprando</a>";
}//terminar si no la envian

else
echo "No hay cotizacion <a href='prueba1.php'>Agrega un producto</a>";
?>
Quiero comprobar si el tipo de mi producto es a se hace un descuento o si es b se hace otro pero como compara mi variable que en este caso es la de $tipo con el campo de mi base de datos donde se almacena el tipo. Ojala alguien pueda ayudarme