Jump to content

connecting sql database


bbala
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...