php countering in javascript doesn't work -


okay here code :

var co = 0; var comp = ''; <?php $i = 0;?> while (co < <?php echo $db->count_rows(); ?>) {     if ((parseint(value) >= <?php echo $mfr[$i] ?>) && (parseint(value) <= <?php echo $mto[$i] ?>))     {         comp = 't';         break;     }     co++;     <?php $i++; ?> } 

i'm still learning whole php , javascript thing, , know there many things still had work to improve understanding both language. that's why need in this

i'm trying while iteration work can compare variable javascript variable php took value database. php variable ('$mfr' , '$mto'), can see, array. want @ every element of both , if meets condition update variable 'comp' , stop whole while iteration

but problem '$i' variable doesn't iteration thing. runs once '$mfr' , '$mto' value doesn't go anywhere. how can fix can compare javascript value php '$mfr' , '$mto' value?

your appreciated, thank :)

edit

well, function of custom validation jqgrid. , know php server-side , javascript client-side language theoretically, though don't know practically

what i'm trying when user input value , submit it, system check whether value entered between value of 'fromid' , 'toid' column of table in database

here full code of function

function checkid(value) { var co = 0; var comp = ''; <?php $i = 0;?> while (co < <?php echo $db->count_rows(); ?>) {     if ((parseint(value) >= <?php echo $mfr[$i] ?>) && (parseint(value) <= <?php echo $mto[$i] ?>))     {         comp = 't';         break;     }     co++;     <?php echo $i++; ?> }  if (comp != 't') {     return [true, "", ""]; } else {     return [false, "value entered between range. please try again!", ""]; } } 

while how got '$mfr' , '$mto' variable

<?php $db=new database($dbtype, $dbhost, $database, $dbuser, $dbpassword, $port, $dsn); $db->query("select fromid, toid core_id"); $i = 0; while($row = $db->get_row()) { $mfr[$i] = $row[fromid]; $mto[$i] = $row[toid]; $i++; } ?> 

if theres better way this, please tell me

typically, php server side logic , js client side logic. if want send value js processed in php, you'll need use ajax, jquery makes pretty easy jquery.ajax().

getting client value processed difficult part. once can that, rewriting code logic in full php should not difficult.

edit: if i'm misunderstanding variable value comes from, please so!

edit 2: looks want have client input compared server side data. js not have access php variables unless sent there. likewise, can send js value server validation in php.

in case, use json send send js validation dates. assuming don't have many dates, faster sending value server , waiting response.

i found example of using json @ another post. can send array like:

<?php      $xdata = array(           'foo'    => 'bar',           'baz' => array('green','blue')      ); ?> <script type="text/javascript">     var xdata = <?php echo json_encode($xdata); ?>;      alert(xdata['foo']);     alert(xdata['baz'][0]);      // dot notation can used if key/name simple:     alert(xdata.foo);     alert(xdata.baz[0]); </script> 

for code, put $mfr , $mto single 2d array. here how new js might look, assuming xdata contains $mfr , $mto:

function checkid(value) {   var co = 0, comp = '', = 0, nrows = xdata.mfr.length;    while (co < nrows) {     if ((parseint(value) >= xdata.mfr[i]) && (parseint(value) <= xdata.mto[i])) {       comp = 't';       break;     }     co++;     i++;   }    if (comp != 't') {     return [true, "", ""];   } else {     return [false, "value entered between range. please try again!", ""];   } } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -