oop - php num_rows greater than 0 -
in effort update old code , learn @ same time, i've become lost. i'm not sure if got right, i'm hoping point me in right direction instead of bashing newbness. know move away mysql statements why i'm trying move oop , learn go. not sure if should use
if($rs->num_rows > 0)
or if should
if($rows_returned > 0)
the following i'm hoping decent start, original @ bottom.
<? // functions.php required connect database usual require("db.inc.php"); //our sql statement $sql1 = 'select * flights flightnumber='" . $_request['data2'] . "''); $rs=$conn->query($sql1); if($rs == false) { trigger_error('wrong sql:' . $sql1 . ' error:' . $conn->error, e_user_error); }else { $rows_returned = $rs->num_rows; if ($rs->num_rows > 0 ){ ($i=0$i<$num_result;$i++) { $rs->data_seek(0); while($row = $rs->fetch_assoc()){ echo '1|flightplan\n'; echo $row['departure'] .'\n'; echo $row['destination'].'\n'; ....more echo's removed save reading..... } } else{ echo '0|flightnumber not found'; } /* original kept guide updating * * $query = mysql_query("select * `flights` flightnumber="".$_request['data2']."'"); * $num_result = mysql_num_rows($query); * if ($num_result > 0) * { * ($i=0;$i<$num_result;$i++) * { * $result = mysql_fetch_array($query); * echo "1|flightplan\n"; * echo $result['departure']."\n"; * echo $result['destination']."\n"; * ....more echo's removed save reading..... * } * } * else * { * echo "0|flightnumber not found"; * } */ ?>
your second answer correct. if you're getting data query object want use later, it's recommended store data in new variable. way, when release query object don't lose data.
good luck coding!
Comments
Post a Comment