Jump to content

connecting sql database


bbala

Recommended Posts

hi all,

i'm new to php and web design.

While fetching data from a database table, i use mysql_query function and store the output in a variable. Is the variable contain all the data or its just a reference? how can i access its contents without mysql_fetch_array function. I'm actually trying to print the records in random order but mysql_fetch_array function returns records sequentially!

Link to comment
Share on other sites

You will have to call it using mysql_fetch_array then randomise the results.

$result = mysql_query("Your query");$contents = array();while ($row = mysql_fetch_array($result)) {$contents[] = $row;}$contents = shuffle($contents);

There! You have a random 2-dimensional array of the data you requested.

Link to comment
Share on other sites

I'm not sure. On one hand you have to sort the data structure yourself, and on the other you need to generate a random number for each record. I think the memory overhead of the array might make the database more efficient, but it probably depends how many records there are and how many fields are in the array.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...