php - About the mysql_query -> mysql_fetch_array() procedure -
sample code:
$infoarray = array(); require_once("connectandselect.php"); // connects mysql , selects appropriate database $sql = "some sql"; if($results = mysql_query($sql)) { while($result = mysql_fetch_array($results, mysql_assoc)) { $infoarray[] = $result; } } else { // handle error } echo("<pre>"); print_r($infoarray); echo("</pre>");
in sample code, want result of query in $infoarray. simple task, simple measures... not. have enjoyed this:
$sql = "some sql"; $infoarray = mysql_results($sql);
but no, can see, have 2 variables , while loop don't care much. don't anything: i'll never use them again. furthermore, never know how call them. here use $results , $result, kind of represents are, can quite confusing since alike. here questions:
- is there simpler method don't know kind of task?
- and if not, names give one-use variables? there standard?
the while loop necessary if expecting multiple rows returned. if getting 1 row can use mysql_fetch_array().
$query = "some sql"; $result = mysql_query($query); $row = mysql_fetch_array($result);
for single line returns standard use. sure little clunky in php, @ least have process broken down debug-able steps.
Comments
Post a Comment