从数据库中获取随机数据,

I have a little problem, I've got this database with these fields.

Table Data{
         ID
         Name,
         Text,
         Location,
         imagepath
         }

And now I want the put these values into my fields, the data is just strings.

<h3><!-- Text value here --> - <!-- Name value here --></h3>
<p> <!-- Location data here --> </p>

And I also got this JS script that generates new fields, when the user clicks on a button.

$('.Next').click(function(e) {
 e.preventDefault();
 Slide.appendSlide('<!-- HTML DATA HERE   NAME AND TEXT & LOCATION VALUES -->')});

I want the ID to be random, and I don't want the user to get the same data twice. How should i approach this? I've tried a getdata.php but failed.

Thank you so much! Happy holidays!

Honestly i would look at saving the page id to $_session['visited']. Then each time they view a page append that to the session variable comma separated

$_session['visited'] .= ",".$page_id;

Then your sql will be.

EDITED

Ok so let make this code safe

$ph = explode(",",$_session['visited']);
foreach($ph as $check){
  if (!isnumeric($check)){
    echo "Not numeric, possible injection";
    exit;
  }
}
$parmcount=count($ph);
$inclause=implode(',',array_fill(0,$parmcount,'?'))
$sql='SELECT * FROM table WHERE ID NOT IN (%s)';
$preparesql=sprintf($sql,$inclause);
$st=$db->prepare($preparesql);
$st->execute($parms);

Or alternative just save all viewed ids as an array in the first place.