php - Return True or False & how to get just on true in a loop -
i have script sends via $.post information
$("#clickme").click(function(e){ var selected = $(".img input:checked").map(function(i,el){return el.name;}).get(); var prelucrare = selected.join(";") $.post('test.php', { rezultat: prelucrare, }, function(data){ $('#rez').html(data) }); });` and php file handles $.post
<?php require_once '../config.php'; if(isset($_post['rezultat'])) { $d = explode(';', $_post['rezultat']); foreach($d $numar_inregistrare){ $sql = "delete galerie_foto numar_inregistrare = '$numar_inregistrare'"; $rezultat = mysql_query($sql) or die(mysql_error()); return true; } } else { exit; } ?> i have 2 questions: 1. how can make js script thing if return value true , other thing if return value false ? ?
$.post('test.php', { rezultat: prelucrare, success: function(msg){ valid = (msg == 1) ? true : false; if(!valid) { $("#valid_input").html("please enter valid info"); } else { $("#valid_input").html(""); } } )}; - my other question returning result, because i'm in loop if there 3 things in array result truetruetrue instead of 1 true, can make 1 true ?
you can use "return" in functions , methods. print "true" or "false" once, in foreach loop can break out or in case exit 'false' if there's error. you'll have this:
foreach($d $numar_inregistrare){ $sql = "delete galerie_foto numar_inregistrare = '$numar_inregistrare'"; $rezultat = mysql_query($sql); if (!$rezultat) { exit('false'); } } echo 'true'; ....
Comments
Post a Comment