Foros del Web » Programando para Internet » PHP »

problema doble lectura a mysqli (1)

Estas en el tema de problema doble lectura a mysqli (1) en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 01/09/2015, 16:50
 
Fecha de Ingreso: agosto-2015
Ubicación: caracas
Mensajes: 31
Antigüedad: 8 años, 8 meses
Puntos: 0
Pregunta problema doble lectura a mysqli (1)

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
  #2 (permalink)  
Antiguo 01/09/2015, 16:52
 
Fecha de Ingreso: agosto-2015
Ubicación: caracas
Mensajes: 31
Antigüedad: 8 años, 8 meses
Puntos: 0
problema doble lectura a mysqli(2)

continuacion...

</form>
</div>
<table width="900" border= "0" id="dinamica" align="center">
<?php
do { ?><tr>
<td class="td1" width="80" align="center"
<?php
switch ($row_Recordset1['id_dummy']) {
case 1:
$ss='background="imagenes/1.png" style="color:#FFF"';
break;
case 2:
$ss='background="imagenes/2.png" style="color:#000"';
break;
case 3:
$ss='background="imagenes/3.png" style="color:#FFF"';
break;
case 4:
$ss='background="imagenes/4.png" style="color:#000"';
break;
case 5:
$ss='background="imagenes/5.png" style="color:#FFF"';
break;
case 6:
$ss='background="imagenes/6.png" style="color:#FF0"';
break;
case 7:
$ss='background="imagenes/7.png" style="color:#000"';
break;
case 8:
$ss='background="imagenes/8.png" style="color:#000"';
break;
case 9:
$ss='background="imagenes/9.png" style="color:#000"';
break;
case 10:
$ss='background="imagenes/10.png" style="color:#F00"';
break;
case 11:
$ss=' background="imagenes/11.png" style="color:#000"';
break;
case 12:
$ss='background="imagenes/12.png" style="color:#000"';
break;
case 13:
$SS='background="imagenes/13.png" style="color:#000"';
break;
case 14:
$ss='background="imagenes/14.png" style="color:#FF0"';
break;
}
echo $ss?>>
<?php echo $row_Recordset1['id_dummy'];?></td>
&nbsp
<td class="
<?php
if ($row_Recordset1['status']==1){?>
td2"
<?php
}
else{
?>
td22"
<?php
}
$i="";
if ($row_Recordset1['status']==1){
$i="" ;
$ss='style="color:#FF0"bgcolor="#000000"';
}
if ($row_Recordset1['status']==2){
$i=" * RETIRADO" ;
$ss='style="color:#CCCCCC " background="imagenes/gb.png"';}
if ($row_Recordset1['status']==3){
$i=" * INVALIDADO";
$ss='background="imagenes/gb.png"'; }
echo $ss?>><?php
echo $row_Recordset1['ejemplar'] ?>&nbsp;<?php echo $i; ?></td>
<td class="td2" bgcolor="#000000" width="133" align="right"><?php
if ($row_Recordset1['status']==1){
if($row_Recordset1['precio']>0){
echo $row_Recordset1['precio']; }
}
?>&nbsp</td>
<td class="td3" bgcolor="#000000" width="50">
<?php
if ($row_Recordset1['status']==1){
switch ($row_Recordset1['masomenos']) {
case 0:
?>
<img src="imagenes/sube.gif">
<?php
break;
case 1:
?>
<img src="imagenes/baja.gif">
<?php
break;
}}
?>
</td>
</tr>
<?php
} while ($row_Recordset1 = mysqli_fetch_assoc($Recordset1));
?>
</table>
<?php
?>
</div>
</body>
</html>
<?php
}
mysqli_free_result($Recordset1);
?>


dinamica.php


<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_dinamica = "localhost";
$database_dinamica = "dinamica";
$username_dinamica = "root";
$password_dinamica = "m67";
$dinamica = mysqli_connect($hostname_dinamica, $username_dinamica, $password_dinamica,$database_dinamica) or die("Error " . mysqli_error($link));
?>


fechas.php


<?php
function cambiaf_a_normal($fecha){
$fecha=date("d-m-Y",strtotime($fecha));
//$fecha = str_replace("-", "/", $fecha);
return $fecha;
}
function cambiaf_a_mysql($fecha){
//$fecha = str_replace("/", "-", $fecha);
$fecha=date("Y-m-d",strtotime($fecha));
return $fecha;
}
?>


estilo.css

@charset "utf-8";
/* CSS Document */

body {
font-family: "Arial Black", Gadget, sans-serif;
background-image: url(images/bg_texture.gif);
background-repeat: repeat;
font-weight: lighter;
background-color: #333;
}
.td1 {
<?php
if ($totalRows_Recordset1<9) {
?> font-size:16px;
<?php
} else if (($totalRows_Recordset1>8) and ($totalRows_Recordset1<13)){
?> font-size:14px;
<?php
}
else {
?> font-size:10x;
<?php
}
?>
font-family: Verdana, Geneva, sans-serif;
font-weight: bold;
border-radius: 15px 0px 0px 15px;
-moz-border-radius: 15px 0px 0px 15px;
-webkit-border-radius: 15px 0px 0px 15px;
border: 1px solid #999;
text-indent: 0;
}
.td2 {
<?php
if ($totalRows_Recordset1<9) {
?> font-size:16px;
<?php
} else if (($totalRows_Recordset1>8) and ($totalRows_Recordset1<13)){
?> font-size:14px;
<?php
}
else {
?> font-size:12px;
<?php
}
?>
font-family: Verdana, Geneva, sans-serif;
font-weight: bold;
border: 1px solid #999;
text-indent: 30;
color:#FF0;
}
.td22 {
font-size:12px;
font-family: Verdana, Geneva, sans-serif;
font-weight: bold;
border: 1px solid #999;
text-indent: 30;
text-align:justify;
color:#FF6;
}
.td3 {
font-size: 180%;
font-family: Verdana, Geneva, sans-serif;
font-weight: bold;
border-radius: 0px 15px 15px 0px;
-moz-border-radius: 0px 15px 15px 0px;
-webkit-border-radius: 0px 15px 15px 0px;
border: 1px solid #999;
text-indent: 5 ;
color:#FF0;
}
.hi {
font-family: Verdana, Geneva, sans-serif;
font-weight: bold;
font-size: 20px; color:#FFF
border-radius: 15px 15px 15px 15px;
-moz-border-radius: 15px 15px 15px 15px;
-webkit-border-radius: 15px 15px 15px 15px;
border: 0px solid #999;
text-indent: 0;
}
.layer1 {
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
font-size: 12px;
font-weight: bold;
text-align: center;
}
.t{
font-size: 20px; color:#000
}
.tit {
font-size: 30px; color:#FFF
}
.tit1 {
font-size: 20px; color:#CCC
}
entrada {
color: #FFF;
}

... ME QUEDE CORTO...
COMO LES ENVIO LA ESTRUCTURA DE LA DB LAS TABLAS Y LOS REGISTROS POR ESTE MEDIO ???

db =dinamica


tabla carreras

id int ai primary
fecha date
hipodromo int
jornada int
carrera int
csntejemp int
status int


tabla hipodromos

id int ai primary
nombrehip varchar(100)
logo varchar(100)


tabla dummy

idD ai primary
id_dummy int
idhipodromo int
idcarrera int
ejemplar varchar (100)
precio int
masomenos int
status int

Gracias, ORFAO

Etiquetas: doble, fecha, html, lectura, mysql, registro, select, sql, tabla, usuarios, variable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:28.