The following short quiz consists of 4 questions and will tell you whether you are qualified to be a professional. The questions are NOT that difficult.

1. How do you put a giraffe into a refrigerator?

Correct Answer: Open the refrigerator, put in the giraffe, and close the door. This question tests whether you tend to do simple things in an overly complicated way.

2. How do you put an elephant into a refrigerator?

Did you say, Open the refrigerator, put in the elephant, and close the refrigerator?

Wrong Answer.

Correct Answer: Open the refrigerator, take out the giraffe, put in the elephant and close the door. This tests your ability to think through the repercussions of your previous actions.

3. The Lion King is hosting an animal conference. All the animals attend…. except one. Which animal does not attend?

Correct Answer: The Elephant. The elephant is in the refrigerator. You just put him in there. This tests your memory.

Okay, even if you did not answer the first three questions correctly, you still have one more chance to show your true abilities.

4. There is a river you must cross but it is used by crocodiles, and you do not have a boat. How do you manage it?

Correct Answer: You jump into the river and swim across. Have you not been listening? All the crocodiles are attending the Animal Meeting. This tests whether you learn quickly from your mistakes.

function seo($input)
{
    //remove single quote and dash
    $input = str_replace(array("'", "-"), "", $input); 

    //convert to lowercase
    $input = mb_convert_case($input, MB_CASE_LOWER, "UTF-8"); 

    //replace everything non an with dashes
    $input = preg_replace("#[^a-zA-Z0-9]+#", "-", $input); 

    //replace multiple dashes with one
    $input = preg_replace("#(-){2,}#", "$1", $input);

    //trim dashes from beginning and end of string if any
    $input = trim($input, "-"); 
    
    //voila
    return $input; 
}

OP:
echo seo(“Tom’s Fish & Chips”); //toms-fish-chips
echo seo(“1-2-3 Pizza”); //123-pizza

I have a real estate website where people can search property based on Location, Property Type and Builder.

I have a Table like below.

CREATE TABLE Project(ProjectId INT NOT NULL PRIMARY KEY AUTO_INCREMENT, 
                     Location  VARCHAR(255), 
                     PropertyType VARCHAR(255), 
                     Builder VARCHAR(255), 
                     ProjectName  VARCHAR(255),
                     Status TINYINT)
                     
                     
INSERT INTO Project(Location, PropertyType, Builder, ProjectName)
             VALUES('Location A', 'Flats',     'Builder A', 'Project A', 1),
                   ('Location A', 'Villas',    'Builder B', 'Project B', 1),
                   ('Location B', 'Flats',     'Builder A', 'Project C', 1),
                   ('Location C', 'Villas',    'Builder C', 'Project D', 1),
                   ('Location B', 'Plots',     'Builder B', 'Project E', 1),
                   ('Location A', 'Row House', 'Builder C', 'Project F', 1),
                   ('Location A', 'Plots',     'Builder A', 'Project G', 1),
                   ('Location C', 'Plots',     'Builder C', 'Project H', 1),
                   ('Location C', 'Flats',     'Builder B', 'Project I', 1),
                   ('Location C', 'Villas',    'Builder B', 'Project J', 1),
                   ('Location A', 'Villas',    'Builder A', 'Project K', 1),
                   ('Location C', 'Flats',     'Builder B', 'Project L', 1);

The search procedure which I use is in such a way that It brings back search result as per the parameters they selected i.e Property Type, Location, Builder Name

Now there may be projects for some search parameters as below

Flats by Builder A at Location C

I want to change procedure in such a way the parameters in filters in where clause should change to bring result all the time by considering other possibilities like for the above

Flats by Builder A at Location C

There is no Flats by Builder A at Location C so it should display Flats at Location C by Other Builders

Location C   Flats     Builder B    Project I

The Filter should Consider PropertyType, Location and Builder Name

Villas at Location B

There is No Villas at Location B So

Location A    Villas   Builder B   Project B
Location C    Villas   Builder B   Project J
Location A    Villas   Builder A   Project K

The search should happen by

PropertyType -> Location -> Builder

If there is No project for a particular Builder in that Location then

PropertyType -> Location

If there is No project for a particular Location then

PropertyType

The parameters in the filters should be eliminated in such a way it brings similar result to search param.


       PropertyType -> Location -> Builder       No Records
       PropertyType -> Location                  No Records
       PropertyType                              Records Found

Solution

DROP PROCEDURE  IF EXISTS getProjectResult;
CREATE PROCEDURE getProjectResult(IN PropertyType VARCHAR(255), IN Location VARCHAR(255), IN BuilderName VARCHAR(255))
BEGIN
  DROP TABLE IF EXISTS tblTempProjIds;
  CREATE TEMPORARY TABLE tblTempProjIds(ProjId INT, Points INT);
  
  SET @PropertyTypePoints = 0;
  SET @LocationPoints     = 0;
  SET @BuilderName        = 0;
  
  IF PropertyType  '' THEN
    SET @PropertyTypePoints = 5;
  END IF;
  
  IF Location  '' THEN
    SET @LocationPoints = 3;
  END IF;
  
  IF BuilderName  '' THEN
    SET @BuilderName = 1;
  END IF;
  
  SET @BestScore = @PropertyTypePoints + @LocationPoints + @BuilderName;
  
  SET @strSQL ='INSERT INTO tblTempProjIds(ProjId, Points) SELECT ProjectId,
                       CASE WHEN PropertyType= ? then 5 else 0 end + 
                       CASE WHEN Location = ? then 3 else 0 end +  
                       CASE WHEN Builder = ? then 1 else 0 end as score
                  FROM project
                 ORDER BY score DESC';
                   
  SET @PropertyType = PropertyType;
  SET @Location     = Location;
  SET @BuilderName  = BuilderName;
  
  PREPARE stmt FROM @strSQL;
  EXECUTE stmt USING @PropertyType, @Location, @BuilderName;  
  DEALLOCATE PREPARE stmt; 
  
  #SELECT * FROM tblTempProjIds;
  
  SET @strSQLCount ='SELECT @Num := MAX(Points) 
                       FROM tblTempProjIds';
                      
                 
  PREPARE stmt FROM @strSQLCount;
  EXECUTE stmt;  
  DEALLOCATE PREPARE stmt;  
  
  
  CASE @Num 
     WHEN 9 THEN SET @Where = CONCAT(' AND PropertyType="', PropertyType, '" AND Location="', Location, '" AND Builder="', BuilderName, '"');     
     WHEN 8 THEN SET @Where = CONCAT(' AND PropertyType="', PropertyType, '" AND Location="', Location, '"');     
     WHEN 6 THEN SET @Where = CONCAT(' AND PropertyType="', PropertyType, '" AND Builder ="', BuilderName, '"'); 
     WHEN 5 THEN SET @Where = CONCAT(' AND PropertyType="', PropertyType, '"'); 
     WHEN 4 THEN SET @Where = CONCAT(' AND Location="', Location, '" AND Builder ="', BuilderName, '"');
     WHEN 3 THEN SET @Where = CONCAT(' AND Location="', Location, '"');
     WHEN 1 THEN SET @Where = CONCAT(' AND Builder="', BuilderName, '"'); 
     WHEN 0 THEN SET @Where = '';
   END CASE;
   
   
    SET @FinalSQL =    CONCAT('SELECT * 
                                 FROM project
                                WHERE status = 1 ', @Where);
                            
    PREPARE stmt FROM @FinalSQL;
    EXECUTE stmt;  
    DEALLOCATE PREPARE stmt;             
END;
    function no_to_words($no)
    {
    $words = array('0'=> '' ,'1'=> 'one' ,'2'=> 'two' ,'3' => 'three','4' => 'four','5' => 'five','6' => 'six','7' => 'seven','8' => 'eight','9' => 'nine','10' => 'ten','11' => 'eleven','12' => 'twelve','13' => 'thirteen','14' => 'fouteen','15' => 'fifteen','16' => 'sixteen','17' => 'seventeen','18' => 'eighteen','19' => 'nineteen','20' => 'twenty','30' => 'thirty','40' => 'fourty','50' => 'fifty','60' => 'sixty','70' => 'seventy','80' => 'eighty','90' => 'ninty','100' => 'hundred &','1000' => 'thousand','100000' => 'lakh','10000000' => 'crore');
    if($no == 0)
    return ' ';
    else {
    $novalue='';
    $highno=$no;
    $remainno=0;
    $value=100;
    $value1=1000;
    while($no>=100) {
    if(($value <= $no) &&($no < $value1)) {
    $novalue=$words["$value"];
    $highno = (int)($no/$value);
    $remainno = $no % $value;
    break;
    }
    $value= $value1;
    $value1 = $value * 100;
    }
    if(array_key_exists("$highno",$words))
    return $words["$highno"]." ".$novalue." ".no_to_words($remainno);
    else {
    $unit=$highno%10;
    $ten =(int)($highno/10)*10;
    return $words["$ten"]." ".$words["$unit"]." ".$novalue." ".no_to_words($remainno);
    }
    }
    }
    echo no_to_words(12345401);

How to Store CSV Ids in Hidden Field
Script

function AddProjectId(pProjectId) 
{
    var arrProjectIds = new Array();
    var strComma = '';
    csvProjectIds = $('#hdnInterestedProjectIds').val();
    csvProjectIds = $.trim(csvProjectIds);
    
    if (csvProjectIds != '') 
    {
        arrProjectIds = csvProjectIds.split(', ');
        lngArrLength = arrProjectIds.length;
    } else {
        lngArrLength = 0;
    }
    
    if (arrProjectIds.indexOf(pProjectId) != 0) {
        if (lngArrLength > 0)
            strComma = ', ';
        csvProjectIds = csvProjectIds + strComma + pProjectId;
    }
    
    $('#hdnInterestedProjectIds').val(csvProjectIds);
}

function RemoveProjectId(pProjectId) 
{
    csvProjectIds = $('#hdnInterestedProjectIds').val();
    csvNewProjectIds = '';
    arrProjectids = csvProjectIds.split(', ');
    arrNewProjectIds = new Array();
    lngArrLength = arrProjectids.length;
    
    for (i = 0; i < lngArrLength; i++) 
    {
        if (arrProjectids[i] != pProjectId) 
        {
            arrNewProjectIds.push(arrProjectids[i]);
        }
    }
    
    for (i = 0; i < arrNewProjectIds.length; i++) 
    {
        strComma = '';
        
        if ((csvNewProjectIds != '') && (arrNewProjectIds.length != (arrNewProjectIds.length - 1)))
            strComma = ', ';
        
        csvNewProjectIds = csvNewProjectIds + strComma + arrNewProjectIds[i];
    }
    
    $('#hdnInterestedProjectIds').val(csvNewProjectIds);
}
<input type=”hidden” name=”hdnInterestedProjectIds” id=”hdnInterestedProjectIds”/>