JQuery - For no recorre registros completo

 
Vista:
sin imagen de perfil

For no recorre registros completo

Publicado por Cristian (1 intervención) el 02/11/2022 15:59:38
Buen día junto con saludarles y agradecerles de ante mano toda cooperación, les paso a contar mi problema, tengo una validación previa antes de enviar a guardar un registro, esta validación revisa si tengo stock en una tabla, pasa que cuando no tiene stock en el primer registro si me envía el mensaje pero ya sin stock en el segundo registro no lo encuentra. Adjunto código del ciclo que estoy tratando hacer:

Agrego código de pagina donde tengo el botón de guardar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var verificar=$('#formingreso').serialize();
	$.ajax({
	data: verificar,
	type: "post",
	url: "includes/verificarstockmaterial.php",
		success: function(response){
		myArray = response.split(";");
 
			for($i=0; $i<myArray.length; $i++)
			{
			   myArray2 = myArray[$i].split(",");
 
				if(myArray2[0].trim() === "no"){
					bootbox.alert({
					  title: 'Entrega Materiales Bodega Móvil',
					  message: '<div class="trans text-center"><br><br><strong>EL CODIGO MATERIAL N°:<strong> '+ myArray2[1] +'</strong> ESTA FUERA DEL STOCK SOLICITADO</strong><br><br></div>',
					})//Fin alert
				}
				else
	                        {
					var guardar=$('#formingreso').serialize();
					$.ajax({
					data: guardar,
					type: "post",
					url: "includes/actualizar_material.php",
						success: function(elem){
						   bootbox.alert({
						   title: 'Entrega Materiales Bodega Móvil',
						   message: "<div class='trans text-center'></br><strong>SE GUARDO CORRECTAMENTE</strong><br><br></div>",
						    callback: function () {
							location.reload();
						     }
						   }) //Fin alert
					         } //Fin del Success
					});//Fin Ajax Ingreso
                                    }//fin del else
   			} //Fin del Sucess
 
		});//Fin Ajax Ingreso

Agrego código del includes/verificarstockmaterial.php:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
include "conexion.php";
$producto=$_POST['producto'];
$cantidad=$_POST['cantidad'];
$actual = [count($producto)];
 
for($i=0; $i < count($producto); $i++){
 
	$descripcionproducto=$producto[$i];
 
        $buscarcodigoproducto = mysql_query("SELECT * FROM ta_materiales WHERE descripcion_material='$descripcionproducto'", $conexion);
 
        while ($filacodpro = mysql_fetch_assoc($buscarcodigoproducto)){
             $material = $filacodpro['codigo_material'];
        }
 
	$buscarstock = mysql_query("SELECT cantidad FROM ta_materiales WHERE codigo_material='$material'", $conexion);
        $numero_filas_stock = mysql_num_rows($buscarstock);
 
	if($numero_filas_stock != 0){
		while ($filastock = mysql_fetch_assoc($buscarstock)){
			$stockactual = $filastock['cantidad'];
		}
 
		if ($stockactual >= $cantidad[$i]){
			$actual	= "si".','.$material;
		}else{
			$actual = "no".','.$material.';';
 
		echo $actual;
	}
}
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder