On 11 July 2010 02:26, Jason Pruim <li...@pruimphotography.com> wrote:
>
> On Jul 10, 2010, at 12:03 PM, Ashley Sheridan wrote:
>
>> On Sat, 2010-07-10 at 11:58 -0400, Jason Pruim wrote:
>>
>>> Okay so I've been fighting with this for awhile now and haven't found
>>> a better way yet....
>>>
>>> What I want to do, is I have a small portion of my website included
>>> into a template. It is displaying hosting plans so on the main site
>>> "index.php" I want it to display a little bit of text (Same as on the
>>> main hosting page) and just 1 random hosting plan. then if they click
>>> on that plan and go into the main hosting section, I want them to see
>>> ALL the hosting plans.
>>>
>>> Here's the code that I'm using:
>>>
>>> if($_SERVER['PHP_SELF'] = "/index.php") {
>>>    $sql = "SELECT * FROM `hosting` ORDER BY RAND() LIMIT 1";
>>> }else{
>>>    $sql = "SELECT * FROM `hosting` ORDER BY `hostingSort` ASC";
>>>
>>> }
>>>
>>> Now... I know there MUST be a better way to do it but I can't see the
>>> tree's through the forest.
>>>
>>> Any other way I could do it?
>>>
>>> I'm avoiding having lots of duplicate code/text on my pages.
>>>
>>>
>>>
>>
>>
>> To avoid duplicating code, use an include file. If you already have some
>> form of include (for a DB for example) then you can include your other
>> includes in that.
>>
>> Also, not sure if it was a type in your email, but I think you want to
>> use == in your if statement there, instead of = ;)
>
> Hey Ash,
>
> I may not have explained it properly :)
>
> I have 2 files... hosting.php and hostingsmall.php which have the EXACT same
> content in them other then the SQL statement. Hostingsmall.php has a "LIMIT
> 1" at the end...
>
> What I want to do is be able to get rid of hostingsmall.php which is
> currently included on my main page and run it all off of hosting.php but
> still be able to limit the query at the front page...
>
> the $_SERVER['PHP_SELF'] seems to be doing the trick... Just wanted to find
> a better way since I've heard you should trust PHP_SELF...
>
> But if that's my best bet since it's working I can stick with it :)

If the only difference between the 2 files is the SQL statement, then
maybe you could ...

<?php
// hosting.php

// Define SQL
$sql = ' ... ';

// Include template
include 'template.php';
?>

And the same for hostingsmall.php, except you have a different SQL statement.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to