Jump to content

PHP Suggest


gijew

Recommended Posts

I tried finding something on this via Google but through the word "suggest" in there and you get nothing but "suggestions.."; phooey!

 

So instead of spending hours on the wrong way of going about this I thought I would come here for suggestions on how to do this as my brain just made it a tough one. What I'm trying to accomplish here is a way to suggest alternative names based off of set details the software knows about (name, birthday, etc...) but they have to be unique as well. The tricky part and what would really make this work nicely is to have certain criteria display (or check if available) first and if none are available get random:

  • [firstname][lastname]
  • [firstinitial][lastname]
  • [lastname][dob]
  • not available, get random results

 

I know that this isn't exact because i'm writing it as I go here so there could very well be errors but this is what I've come up with in semi-pseudo code/code:

 

<?php
function suggest_slug() {
  $suggest = array();
  $first_name = $_SESSION['first_name'];
  $last_name = $_SESSION['last_name'];
  $dob = $_SESSION['dob'];
  $dob_year_short = date('y',mktime(0,0,0,0,0,$dob));

  $suggest = array(
    $first_name,
    $last_name,
    $dob,
    $dob_year_short
  );

  foreach ($suggest as $slug) {
     do {
        $try_this = $slug;
        $query = $db->GetRow("select slug from whatever where slug = '".$slug."'");
     } while (count($query) > 0) {
        return $slug;
     }
  }
  If (!$slug) {
      array_rand($suggest);
      // loop through array and throw out say 5 random results 
   }
}
?>

 

Once again, this is just what was in my mind as to how it MAY work but I'm looking for suggestions on perhaps a better way or even better would be a known way to make this run better :)

Link to comment
https://forums.phpfreaks.com/topic/111384-php-suggest/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.