Okay, so here's my problem:
I have a table structure like so:
###blog_id#####domain####
--------2-------------dude.dude.com
--------3-------------man.dude.com
--------4-------------etc.etc.com
I want to be able to loop through the table and pull out a random domain but ALSO pull out the corresponding blog_id.
This is important so that I can later use code like [$values[rand_id[2]] and [$values[rand_domain[2]] and have that output what i want.
Here's what I've already got cracking:
$sql="SELECT * FROM wp_blogs WHERE (public = '1' AND mature = '1' AND spam = '0' AND deleted = '0' AND blog_id != '1')";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$randomdomain = $row['domain'];
$randompath = $row['path'];
$randomids = $row['blog_id'];
if ('/' == substr($randompath, strlen($randompath)-1)) $randompath = substr_replace($randompath, '', strlen($randompath)-1); // strip trailing slash
$randomurl = $randomdomain . $randompath;
array_push($values, "$randomurl");
array_push($randomid, "$randomids");
}
shuffle($values);
shuffle($randomid);
$rand_keys = array_rand($values, 6);
$rand_id = array_rand($randomid, 6);
I can use $values[$rand_keys[4]] to get the 4th random entry but $randomid[$rand_id[4]] does not produce the correspdoning random id for the domain that gets pulled when i use $values[$rand_keys[4]].
The second problem that I'm having isn't really a problem but more of an efficiency question. Right now I'm using the following:
$sql2 = $wpdb->get_var("SELECT ID FROM wp_users WHERE user_url = 'http://" .$values[$rand_keys[1]]."/'");
$sql3 = $wpdb->get_var("SELECT ID FROM wp_users WHERE user_url = 'http://" .$values[$rand_keys[2]]."/'");
$sql4 = $wpdb->get_var("SELECT ID FROM wp_users WHERE user_url = 'http://" .$values[$rand_keys[3]]."/'");
$sql5 = $wpdb->get_var("SELECT ID FROM wp_users WHERE user_url = 'http://" .$values[$rand_keys[4]]."/'");
And I'm fairly sure there's a more efficient way of doing that also! lol...does anyone have any help to offer? I would be much obliged. 🙂