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;

In jQuery, suppose you have an element of some kind that you’re hiding and showing, using .hide(), .show() or .toggle(). How do you test to see if that element is currently hidden or visible on the screen?

 // Checks for display:[none|block], ignores visible:[true|false]
 $(element).is(":visible") 

You can use the “hidden” and “visible” selectors.

 $('element:hidden')
 $('element:visible')
                <div class="pagination">               
                  <span class="prev"></span>
                  <span class="num" id="1">1</span> 
                  <span class="num_active" id="2">2</span> 
                  <span class="num" id="3">3</span> 
                  <span class="num" id="4">4</span> 
                  <span class="num" id="5">5</span> 
                  <span class="num" id="6">6</span> 
                  <span class="next"></span>
                 </div>
  $('.pagination span').click(function(){
	$(".pagination span").removeClass("num_active").addClass("num"); 
	$(".pagination span:first").removeClass("num").addClass('prev');
	$(".pagination span:last").removeClass("num").addClass('next');
        $(this).addClass("num_active"); 
  });
	//taking number as parameter
	function convert_digit_to_words($no)  
	{   
	
	//creating array  of word for each digit
	 $words = array('0'=> 'Zero' ,'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' => 'fourteen','15' => 'fifteen','16' => 'sixteen','17' => 'seventeen','18' => 'eighteen','19' => 'nineteen','20' => 'twenty','30' => 'thirty','40' => 'forty','50' => 'fifty','60' => 'sixty','70' => 'seventy','80' => 'eighty','90' => 'ninty','100' => 'hundred','1000' => 'thousand','100000' => 'lac','10000000' => 'crore');
	 //$words = array('0'=> '0' ,'1'=> '1' ,'2'=> '2' ,'3' => '3','4' => '4','5' => '5','6' => '6','7' => '7','8' => '8','9' => '9','10' => '10','11' => '11','12' => '12','13' => '13','14' => '14','15' => '15','16' => '16','17' => '17','18' => '18','19' => '19','20' => '20','30' => '30','40' => '40','50' => '50','60' => '60','70' => '70','80' => '80','90' => '90','100' => '100','1000' => '1000','100000' => '100000','10000000' => '10000000');
	 
	 
	 //for decimal number taking decimal part
	 
	$cash=(int)$no;  //take number wihout decimal
	$decpart = $no - $cash; //get decimal part of number
	
	$decpart=sprintf("%01.2f",$decpart); //take only two digit after decimal
	
	$decpart1=substr($decpart,2,1); //take first digit after decimal
	$decpart2=substr($decpart,3,1);   //take second digit after decimal  
	
	$decimalstr='';
	
	//if given no. is decimal than  preparing string for decimal digit's word
	
	if($decpart>0)
	{
	 $decimalstr.="point ".$numbers[$decpart1]." ".$numbers[$decpart2];
	}
	 
	    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))  //check if $high value is in $words array
	              return $words["$highno"]." ".$novalue." ".convert_digit_to_words($remainno).$decimalstr;  //recursion
	          else {
	             $unit=$highno%10;
	             $ten =(int)($highno/10)*10;
	             return $words["$ten"]." ".$words["$unit"]." ".$novalue." ".convert_digit_to_words($remainno
	             ).$decimalstr; //recursion
	           }
	    }
	}
Posted in PHP.
    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);

package com.apryll.package2;

public class sample2 
{
  public static void main(String args[])  
  {
    sample2 objsample2 = new sample2();
    objsample2.argCount(1, 2, 3, 4);
  }
	
  public void argCount(int num1, int num2, int... args)
  {
    System.out.println(num1);
    System.out.println(num2);
    System.out.println(args.length);
  }
}

OP
1
2
2

Please Note the Last 2 which accounts for the array argument args as num1 and num2 does not account for array arguments

If the Code is like below then it would have been a error

  public void argCount(int num1, int num2, int... args)