I am trying to find out which is the proper way to fetch data from my database. Either way works, but what’s the difference; an in-depth explanation?
$sql = mysql_query("SELECT * FROM _$setprofile");
while($row = mysql_fetch_array($sql)) {
$username = $row['user'];
$password = $row['pass'];
echo "$username:$password";
}
versus the function below…
$sql = mysql_query("SELECT user,pass FROM _$setprofile");
while($row = mysql_fetch_row($sql)) {
echo "$row[0]:$row[1]";
}
This is something I’ve always wanted to know.
The difference is you’re re-assigning the variables in the first example. But you could just say:
Or you could pull out a hash
The right way depends on the application or your preference, I personally avoid the numeric indexed arrays unless I specifically need them. Who wants to try to keep a mental tab of what data is in which index?