Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

help adding a simple feature to a php script

Posted on 2005-04-07
7
Medium Priority
?
189 Views
Last Modified: 2010-07-27
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");



?>
0
Comment
Question by:Caiapfas
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Assisted Solution

by:jeffparis
jeffparis earned 400 total points
ID: 13731539
I would add a new database table 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.
0
 
LVL 1

Expert Comment

by:jeffparis
ID: 13731555
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.
0
 
LVL 7

Accepted Solution

by:
Promethyl earned 1600 total points
ID: 13741983
$query="SELECT * FROM website_villas WHERE bedrooms_min < 4 AND bedrooms_min <> 0 OR bedrooms_max < 4 ORDER BY sticky desc, bedrooms_max DESC";

Always do the least amount of queries. Handle the sticky ones seperately. (They'll always be first.)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Caiapfas
ID: 13757220
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?
0
 
LVL 2

Author Comment

by:Caiapfas
ID: 13757270
ok got it to add, but i cant get it changed to ENUM?
0
 
LVL 2

Author Comment

by:Caiapfas
ID: 13758350
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";
0
 
LVL 7

Assisted Solution

by:Promethyl
Promethyl earned 1600 total points
ID: 13758423
$query="SELECT * FROM website_villas WHERE bedrooms_min = 4 OR bedrooms_max = 4 ORDER BY sticky desc, price_max DESC";

$query="SELECT * FROM website_villas WHERE bedrooms_max > 4 ORDER BY sticky desc, bedrooms_max DESC";
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question