Using array in php query? -



Using array in php query? -

i want obtain number of rows in query using mysql_num_rows.the query contains 2 arrays. want store number in array. here's code

$antecedent=array(); for($i=0;$i<=$index;$i++){ if(isset($period[$i])|| isset($gpa[$i]) || isset($antecedent[$i])){ $queryantecedent=mysql_query("select * mytable study_period='$period[$i]' , ipk='$gpa[$i]'") or die (mysql_error()); $antecedent[$i]=mysql_num_rows($queryantecedent); }//endif }//endfor print_r ($antecedent);

when used 1 array within query, code works. on other hand, when set 2 arrays in it..the code doesn't work(all element in array antecedent contain 0). how slve this? no way using 2 arrays in query? give thanks you

if you're not getting mysql error when query runs, query returning no rows. seek building query separately , store in variable, can view you've built:

$sql = "select * mytable study_period='$period[$i]' , ipk='$gpa[$i]'"; $queryantecedent=mysql_query($sql) or die (mysql_error()); echo $sql;

note you're doing || (or) in main if() statement. will allow query go ahead if one of arrays have values. you'd need alter && (and) comparing instead, requires all arrays have values available.

for instance, if $gpa[$i] happens empty, query becomes

select * ... , ipk='';

which not want.

php arrays mysql-num-rows

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -