Quantcast
Channel: WampServer - WampServer English
Viewing all articles
Browse latest Browse all 3177

Randomizing Data From A Table (1 reply)

$
0
0
I'm trying to randomize a data from my SQL database using PHP - and I'm displaying the results in an HTML page.


It works fine using this code:

$random = mysqli_query($con,"SELECT * FROM tbData WHERE Selected != 0 order by RAND() LIMIT 1" ) ;
$row = mysqli_fetch_array($random);

I'm retrieving the names in the 'Name' column.

The problem is I want to prevent duplicates from being 'drawn'; so I added a second column named 'Selected' and added '1' as default to all records. So the code snippet above selects from any records that has '1' in the 'Selected' column, so logically, I need to turn this '1' into a '0' to prevent it from being 'drawn'.

I'm working with this second code block to do it, but it seems to fail in changing the '1's to '0's:

$random1 = mysqli_query($con,"UPDATE tbData SET Selected = '0' WHERE Name = ".$row['Name']." " ) ;

Any help with this?

Viewing all articles
Browse latest Browse all 3177

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>