I want to pull 2 random rows from my database and print them as links.
I am using the following statement to SELECT rows from my MySQL database:
SELECT title, id FROM articles
Now, I want to put this data into an array
Let's say this query returns the following from the database:
ID TITLE
2 Nowhere
3 Headed Home
4 Another One
5 Last Title
I want to put these into an array as follows:
$input = array(2 => "Nowhere", 3 => "Headed Home", 4 => "Another One", 5 => "Last Title");
I think that PHP has already put this data into an array, but I don't know how to get it out.
I ultimately want to pull 2 random rows from this:
srand ((float) microtime() * 10000000);
$input = array(2 => "Nowhere", 3 => "Headed Home", 4 => "Another One", 5 => "Last Title");
$rand_keys = array_rand ($input, 2);
print $input[$rand_keys[0]]."\n";
print $input[$rand_keys[1]]."\n";
And have the titles appear as a link, using the id in the <a href>
Am I even close? Anyone have any ideas?