Link to home
Start Free TrialLog in
Avatar of Caiapfas
Caiapfas

asked on

help adding a simple feature to a php script

I need to make it where I can name a villa, in a certian place and it will put it on top of the list. and then the sql query takes over for the rest.
So a certian place on top, I put the villa name and it goes on top of the list.
please help thanks

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(script)



<?



//$description = str_replace("<br>", "\n", $description);



mysql_connect (localhost, UN, PW);

   

mysql_select_db (newsletter2);



$query="SELECT * FROM website_villas WHERE bedrooms_min < 4 AND bedrooms_min <> 0 OR bedrooms_max < 4 ORDER BY bedrooms_max DESC";

$result=mysql_query($query);



$num=mysql_numrows($result);



mysql_close();







$i=0;

while ($i < $num) {



$vid=mysql_result($result,$i,"vid");

$name=mysql_result($result,$i,"name");

$visible=mysql_result($result,$i,"visible");



if ($visible == "true") {



$feature_1=mysql_result($result,$i,"feature_1");

$type=mysql_result($result,$i,"type");

$description=mysql_result($result,$i,"description");

$amenities=mysql_result($result,$i,"amenities");

$location=mysql_result($result,$i,"location");

$bedrooms_min=mysql_result($result,$i,"bedrooms_min");

$bedrooms_max=mysql_result($result,$i,"bedrooms_max");

$bathrooms_min=mysql_result($result,$i,"bathrooms_min");

$bathrooms_max=mysql_result($result,$i,"bathrooms_max");

$accommodations=mysql_result($result,$i,"accommodations");

$size_min=mysql_result($result,$i,"size_min");

$size_max=mysql_result($result,$i,"size_max");

$staff=mysql_result($result,$i,"staff");

$price_min=mysql_result($result,$i,"price_min");

$price_max=mysql_result($result,$i,"price_max");

$image_folder=mysql_result($result,$i,"image_folder");

$main_image=mysql_result($result,$i,"main_image");

$file_name=mysql_result($result,$i,"file_name");

$feat = null;

if ($feature_1 <> "none") {

       $feat = " - <font color=#FF0000>" . $feature_1 . "</font>";

}



if ($size_min)

      {

            $size = $size_min . " - " . $size_max . " sq. ft.";

      } else if ($size_max)

      {

            $size = $size_max . " sq. ft.";

      } else {

            $size = "&nbsp;";

      }



if ($price_min)

      {

            $price = "$" . $price_min . " - $" . $price_max . " per night";

      } else if ($price_max)

      {

            $price = "$" . $price_max . " per night";

      } else {

            $price = "&nbsp;";

      }



if ($bedrooms_min)

      {

            $bedrooms = $bedrooms_min . " - " . $bedrooms_max;

      } else if ($bedrooms_max)

      {

            $bedrooms = $bedrooms_max;

      } else {

            $bedrooms = "&nbsp;";

      }



$bathrooms_min = (float)$bathrooms_min;

$bathrooms_max = (float)$bathrooms_max;

      

if ($bathrooms_min > 0)

      {

            $bathrooms = $bathrooms_min . " - " . $bathrooms_max;

      } else if ($bathrooms_max > 0)

      {

            $bathrooms = $bathrooms_max;

      } else {

            $bathrooms = "&nbsp;";

      }

      

if ($vid > 67) {

      $file_name = "villas/" . $file_name;

      }



$list_var = $list_var . "<tr><td align=center valign=middle><a href=../$file_name><img src=../images/$image_folder/thumbnails/$main_image border=0></a></td><td nowrap><a href=../$file_name>$name</font></a>$feat</td><td>$location</td><td align=center>$bedrooms</td><td align=center>$bathrooms</td><td>$size</td><td>$price</td></tr>";



$feat = null;



}



++$i;

}







$html_var_1 = <<<EOD

<h3 align="center">1 to 3 Bedroom Villas and Condos</h3>

<table border="1" cellspacing="0" cellpadding="2" align="center" bordercolor="#000000" style="border-collapse: collapse;">

<tr bgcolor="teal"><td></td><td><font color="#FFFFFF">Villa Name</font></td><td><font color="#FFFFFF">Location</font></td><td><font color="#FFFFFF">Bedrooms</font></td><td><font color="#FFFFFF">Bathrooms</font></td><td><font color="#FFFFFF">Size</font></td><td><font color="#FFFFFF">Price</font></td></tr>

$list_var

</table>



EOD;



$html_var_final = str_replace ("$", "&#36;", $html_var_1);









require("classes/class_tplsys.php");



$tplObj = new tplSys("./");

    $tplObj->getFile( array(

        'villas' => 'templates/villas.tpl' )

    );



    $tplObj->varRef( "villas", array(

        "VILLAS"    =>    $html_var_final )

    );



    $tplObj->varRef( "villas", array(

        "TITLE"    =>    'Cabo San Lucas Villas - 1 - 3 Bedrooms' )

    );

      

    $tplObj->parseDynamic("villas");



?>
SOLUTION
Avatar of jeffparis
jeffparis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jeffparis
jeffparis

CORRECTION:

I would add a new ROW in 'website_villas' named 'sticky'. Make it an 'enum' with the value '0','1'.

Then, for those to be listed at the top, give them the value of 1 and the normal listings as 0.

Then, add a second query, this:
$query="SELECT * FROM website_villas WHERE sticky != 0 AND bedrooms_min < 4 AND bedrooms_min <> 0 OR bedrooms_max < 4 ORDER BY bedrooms_max DESC";

That is the easiest solution I can think of. This second query's results should be shown first, of course.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Caiapfas

ASKER

how do i add sticky to the table , it wont add for me and went it does , i dont see it listed?


SQL-query:
ALTER TABLE website_villas ADD sticky ENUM not null

but dont see it?
ok got it to add, but i cant get it changed to ENUM?
ok got it to work!


but now i have 2 more files i need "sticky" to work with

view_4_br.php
$query="SELECT * FROM website_villas WHERE bedrooms_min = 4 OR bedrooms_max = 4 ORDER BY price_max DESC";

view_over_4_br.php
$query="SELECT * FROM website_villas WHERE bedrooms_max > 4 ORDER BY bedrooms_max DESC";
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial