GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech Make an 'echo' random in php? (https://gfy.com/showthread.php?t=1351750)

Publisher Bucks 01-26-2022 07:31 PM

Make an 'echo' random in php?
 
Quote:

$title = $row['Name'];
I'm using the above echo statement to insert data into a page however, it dawned on me that it could be better to pull from a larger selection of data from within that same defined column, is this possible to achieve using a simple echo statement like the one above, just with a little longer statement, that doesnt involve adding SQL queries?

I'm thinking it must be possible using something along the lines of this, maybe just to give an idea of what I'm looking for?

Quote:

$title = $row['Name'] RAND();
Quote:

<?php echo $title; random ?>
Is this possible?

TIA for any assistance.

NoWhErE 01-26-2022 07:57 PM

you'd have to save all the names as an array. I don't know if your data is available in that format, but if it is, all you need to do is $random_title = array_rand($your_array_of_names) and it will output a random result every time.

if your data isn't an array yet, you can create one by adding each name in your database like this

step 1: create an empty array
$array = array();

step 2: go through each name in your db and add it to the array
foreach($row as $name) {
$array[] = $name;
}

now your array is ready to be randomized.

Publisher Bucks 01-26-2022 08:36 PM

Quote:

Originally Posted by NoWhErE (Post 22958518)
you'd have to save all the names as an array. I don't know if your data is available in that format, but if it is, all you need to do is $random_title = array_rand($your_array_of_names) and it will output a random result every time.

if your data isn't an array yet, you can create one by adding each name in your database like this

step 1: create an empty array
$array = array();

step 2: go through each name in your db and add it to the array
foreach($row as $name) {
$array[] = $name;
}

now your array is ready to be randomized.

Much appreciated.

Thats what I was afraid of, itll take forever to setup the individual arrays, looks like I need to recode using SQL Queries instead :1orglaugh

Thanks!

NoWhErE 01-27-2022 07:28 AM

Quote:

Originally Posted by Publisher Bucks (Post 22958532)
Much appreciated.

Thats what I was afraid of, itll take forever to setup the individual arrays, looks like I need to recode using SQL Queries instead :1orglaugh

Thanks!

It depends. Either way, with SQL queries or with arrays, it should only be a few lines of code at most to get the data you want.


All times are GMT -7. The time now is 07:09 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123