Single quoting the vars isn’t necessary and will return the same result. You can’t echo the the result of an executed query directly and expect to see the query results. mysql_query returns a result id. Hence the output chafikb was getting.
I tried the new guys method and got this error
Error retrieving information from database!
Error: You have an error in your SQL syntax near ‘‘african’ WHERE pid=‘1’’ at line 1
give me a sec to try Messiah’s.
Yep, correct. You can’t simply echo the result, it isn’t in any… “form” (not an array/string etc., although you can make a multi dimensional array from it).
mysql_fetch_row only returns array with numeric keys (0 meaning the first column you asked for in the query, 1 the second etc.)
mysql_fetch_assoc only returns array with string hashes or what ever it is called, so it returns the name of the column, not the order.
Example:
$rslt = mysql_query('SELECT colA, colB, colC FROM Table LIMIT 1');
$row1 = mysql_fetch_assoc($rslt);
//lets say then that I didn't have the line above, will then not go to the next line, but just use the first.
//while loop isn't needed since I have LIMIT 1
$row2 = mysql_fetch_row($rslt);
//then $row1[0] = $row2['colA']; $row1[1] = $row2['colB'] and $row1[2] = $row2['colC']
So it seems that ordered from fastest to slowest it would be like this:
[fphp]mysql_fetch_row[/fphp]
[fphp]mysql_fetch_assoc[/fphp]
[fphp]mysql_fetch_array[/fphp]
Although you could argue about the order of the last two I would say [fphp]mysql_fetch_array[/fphp] is slower since it outputs more data.
Then again the difference isn’t enough to worry about
Indeed, little faster
Any comment on mysql_num_rows vs incrementing a variable ($rows[‘rows’]++) vs count($rows)
I made a little benchmark script but the results are various…
($rows is inside a while loop with mysql_fetch_assoc)
well, I suppose mysql_num_rows is propably the best, I would be suprised if the php development team didn’t always try to make functions faster then you could by actually creating it yourself ;). Another thing is that it makes much cleaner code, to use mysql_num_rows, and pretty and clean are often more important then having it a bit faster.