Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/09/2015, 17:34
moisesorfao
 
Fecha de Ingreso: agosto-2015
Ubicación: caracas
Mensajes: 31
Antigüedad: 8 años, 8 meses
Puntos: 0
problema lectura doble a mysqli

Hola a todo(s,as).
tengo un problema con mi codigo.

no se por que tengo que leer de la db dos veces consecutivas en el caso de recordset1 y dd porque he tratado de eliminar alguna de las dos y me da un error en la linea 170 ????
lo otro es que cuando presiono enter deberia pasarme al campo siguiente pero cuando esta en el boton imprimir me salta al campo cantidad (a menos que lo mantenga presionado),
este codigo esta en periodo de diseño por lo que aun falta imprimir el ticket de venta, etc.
otra pregunta relacionada es de como actualizar esta pagina automaticamente cuando cambien los dados en la tabla dummy.


ademas de esto me gustarian sugerencias, observaciones, comentarios y o recomendaciones para optimizar el codigo..




aqui les dejo el codigo. y al final la estructura de la db



ventaticket3.php

<?php require_once('Connections/dinamica.php');
include("fechas.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("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue) : mysqli_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;
}
}
mysqli_query($dinamica,"SET NAMES 'utf8'");
//mysql_select_db($database_dinamica, $dinamica);
$query_hipodromos = "SELECT * FROM hipodromos ,dummy WHERE dummy.idhipodromo=hipodromos.id AND dummy.id_dummy=1 ORDER BY dummy.id_dummy ASC";
$hipodromos = mysqli_query($dinamica,$query_hipodromos) or die(mysqli_error());
$row_hipodromos = mysqli_fetch_assoc($hipodromos);
$totalRows_hipodromos = mysqli_num_rows($hipodromos);
if(!isset($_POST['hi'])){
$hi=$row_hipodromos['id'];
}else{
$hi=$_POST['hi'];
}
$query_Recordset1 = "SELECT * FROM dummy WHERE idhipodromo='$hi' ORDER BY idhipodromo,id_dummy";
$Recordset1 = mysqli_query($dinamica,$query_Recordset1) or die(mysqli_error());
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);
//if ($row_recordset1['status']=0){
// $mensaje='No hay carreras abiertas ...';}
//else { $mensaje='No hay carreras abiertas ...';}
//*******************
$query_dd = "SELECT * FROM dummy WHERE idhipodromo='$hi' ORDER BY idhipodromo,id_dummy";
$dd = mysqli_query($dinamica,$query_dd) or die(mysqli_error());
$row_dd = mysqli_fetch_assoc($dd);
$totalRows_dd = mysqli_num_rows($dd);
//*genero las variables que se pasan a la funcion calcular ************************
$v=array();
do{
$v[]= $row_dd['precio'];

} while ($row_dd = mysqli_fetch_assoc($dd));
$objeto=json_encode($v);
//* fin genero las variables que se pasan a la funcion calcular ************************
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<link rel="icon" type="image/png" href="imagenes/title_img.png" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Ventas</title>
<script type="text/javascript">
function calcula(cantidad, campo) {
var ejemplar=document.getElementById("ejemplar").value
var json=eval(<?php echo $objeto; ?>);

var precio=json[ejemplar-1];
document.getElementById(campo).value = cantidad * precio;

}
</script>
<script>
function refrescar()
{
//window.location.reload();
}
</script>
<script language=
"JavaScript">
function A(e,t)
{
var k=null;
(e.keyCode) ? k=e.keyCode : k=e.which;
if(k==13) (!t) ? B() : t.focus();
}
function B()
{
//refrescar();
//document.forms[0].submit();
return true;
}
</script>
<link type="text/css" rel="stylesheet" href="css/estilo.css" />

</head>
<body onload="document.getElementById('ejemplar').focus( )"
>
<div class="layer1" align="center">
<p>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="275" id="FlashID" title="hipicoweb" align="left">
<param name="movie" value="imagenes/Hipicoerb banner.swf">
<param name="quality" value="high">
<param name="wmode" value="transparent">
<param name="swfversion" value="6.0.65.0">
<!-- Esta etiqueta param indica a los usuarios de Flash Player 6.0 r65 o posterior que descarguen la versión más reciente de Flash Player. Elimínela si no desea que los usuarios vean el mensaje. -->
<param name="expressinstall" value="scripts/expressInstall.swf">
<!-- La siguiente etiqueta object es para navegadores distintos de IE. Ocúltela a IE mediante IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="imagenes/Hipicoerb banner.swf" width="380" height="67">
<!--<![endif]-->
<param name="quality" value="high">
<param name="wmode" value="transparent">
<param name="swfversion" value="6.0.65.0">
<param name="expressinstall" value="scripts/expressInstall.swf">
<!-- El navegador muestra el siguiente contenido alternativo para usuarios con Flash Player 6.0 o versiones anteriores. -->
<div>
<h4>El contenido de esta página requiere una versión más reciente de Adobe Flash Player.</h4>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Obtener Adobe Flash Player" width="100" height="30" /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
<?php
if($totalRows_hipodromos>0){
$im="imagenes/logo".$hi.".png "
?>
<img src="
<?php
echo "imagenes/logo".$hi.".png ";
?>
" width="100" height="60">
<?php
}
?>
<img src="imagenes/TABLA_DINAMICA.gif" width="400" height="60" alt="titulodin">&nbsp <span class="tit1"> C.H. Sport Bock Amazonas V.I.P.</span>
<?PHP
if($totalRows_hipodromos>0){
?>
</p>
<div align="center">
<form action='ventaticket3.php' method='POST'>
<p>
<select name="hi" class="hi" id="hi" onchange='submit();'>
<?php
$h=1;
do {
?>
<option value="<?php echo $row_hipodromos['id']
?>"
<?php
if (isset($_POST['hi']) and $_POST['hi']==$row_hipodromos['id'] )
{?>selected<?php }?>
><?php echo $row_hipodromos['nombrehip']?></option>
<?php
$h++;
} while ($row_hipodromos = mysqli_fetch_assoc($hipodromos));
?>
</select>
<span class="tit1">
<?php
$j=$row_Recordset1['idcarrera'];
$query_carreras = "SELECT * FROM carreras WHERE id=$j ";
$carreras = mysqli_query($dinamica,$query_carreras) or die(mysqli_error());
$row_carreras = mysqli_fetch_assoc($carreras);
?>
<?php echo $row_carreras['jornada']?>a Jornada - <?php echo $row_carreras['carrera']?>a Carrera - <?php echo cambiaf_a_normal($row_carreras['fecha'])?>
</span> <span class="tit">&nbsp;&nbsp; La tabla paga 350 Bs.
</span></p>
</form>
</div>
<div align center>
<form name="sumar" method="post">
<table align="center" border="0">
<tr bgcolor="#000000" style="color:#FFF">
<td align="center"><strong>Ej.</strong></td>
<td align="center"><strong>Cant.</strong></td>
<td align="center">Tolal</td>
</tr>
<tr>
<td height="35" align="center"><input type="number" class="t" name="ejemplar" id="ejemplar" value="" size="4" maxlength="4" min=1 max=
<?php
echo $totalRows_Recordset1;
?>

onBlur="calcula(this.value, 'tot');"
onchange="A(event,this.form.cant);"
onkeyup="A(event,this.form.cant);"
/></td>
<td align="center"><input type="number" id="cant" size="4" maxlength="4" min=1 max=50 class="t" onBlur="calcula(this.value, 'tot');"
onChange="A(event,this.form.imprime,
);"
onKeyUp="A(event,this.form.imprime);"
/></td>
<td align="center"><input type="number" name="tot" id="tot" value="" size="4" maxlength="4" class="t" min=0 max=50000 disabled /></td>
</tr>
<tr>
<td height="35" colspan="3" align="center"><?php
if (isset($_POST['hi'])){
?>
<input name="hi" type="hidden" id="hi" value="<?php echo $_POST['hi']; ?>" />
<?php
}
?>
<input type="button" id="imprime" value="Imprimir" onclick='submit()'/> <input type="button" id="cancelar" value="Cancelar" onclick='submit()'/></td>
</tr>
</table>
... continua antemano.