This topic is locked
[SOLVED]

 Creating multiple "Views" without creating multiple "Views

11/30/2009 11:27:08 AM
PHPRunner General questions
W
wfcentral author

I know this is going to sound as weird as the title...
I have created a database for a city website with listings for dining, attractions, hotels, museums, arts, etc.
I need to create pages on the website for Dining, Attractions, Hotels, Museums, etc complete with search capability.
When you are on the Dining page you should only see the Dining listings.
When you are on the Attractions page you should only see the Attractions listings.
and so on...
I know I can go into PHPRunner and create views with different mySQL statements that say "where type = dining" however, if I do that I will end up with about 16 different views (there are more categories than I use in my example above) and whenever they want to change the "look" of the listings page I will have to edit 16 Custom views in phpRunner.
Is there a way I can just create one listing in phpRunner and dynamically call that group on a specific page.
I tried it by passing a search variable in the URL, but that goofs up the search box on that page.

S
swgiles 11/30/2009

Create a session varible, call it $_SESSION['PageType'] or something of the like. On the events page, before page is processed, you'll want something like

$_SESSION['PageType']= (some unique identifier);


I'd just do numbers and document what they correspond to (1 =dining, 2= attractions ect), but that's your call.
Now in the After Table initialized event

if ($_SESSION['PageType'] != 0) //where 0 lists everything

{

$gsqlWhereExpr = whereAdd($gsqlWhereExpr,"dbo.CityListingTbl.PageType ='" . $_SESSION['PageType'] . "'");

}


So to recap, have a key column in your table that says what type of listing the entry is. In the before process event, make a session variable that corrosponds to the key column, remebering to have a number (or string) that corrosponds to displaying the full table. Finally, in the "Before table initialized event, add a where clause to the SQL call, only calling the information that the session varible says to.
That eliminates the need for any veiws <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=45809&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
However I don't know if this extends you beyond your programming skill, and I can't claim to know too much PHP. If anyone with more knowledge then me thinks there is a better way, please share!
Hmm however I may not be understanding correcty. You'd still need to make differant reports for each page, and you could just change the SQL there. If you mean to do it all on one page, add PHP snippets as links or buttons on the main page, and ignore the bit about "before page process". Have the snippets change the session variable and refresh the page, and that should solve it. Hope I helped more then I confused!

W
wfcentral author 12/3/2009

two problems...

  1. I can't seem to get your solution to work
  2. It seems like even if I did get it to work it would require me to still create 30 different views - I don't understand how you would change the where statement dynamically.
    What I'm trying to do is this...
    table.listings

    id / name / type

    1 / Holiday Inn / hotel

    2 / Red Roof Inn / hotel

    3 / Chili's / restaurant

    4 / Applebees / restaurant
    I want to create one listing page in phpRunner and customize it so it displays just right...
    then, I want to create standard php pages like this
    hotels.php

    restaurants.php
    Those pages would look like this (very simplistic)
    hotels.php

    <html>

    <body>
    Set Where variable = "type = hotel"
    include phprunner list page
    </body>

    </html>
    restaurants.php

    <html>

    <body>
    Set Where variable = "type = restaurants"
    include phprunner list page
    </body>

    </html>

J
Jane 12/4/2009

Hi,
you can create just one view, then add WHERE clause dynamically in the After table initialized event on the Events tab:

if ($_SESSION['PageType'] != 0) //where 0 lists everything

{

$gsqlWhereExpr = whereAdd($gsqlWhereExpr,"dbo.CityListingTbl.PageType ='" . $_SESSION['PageType'] . "'");

}



Then fill $_SESSION['PageType'] in your custom hotels.php, restaurants.php files.

W
wfcentral author 12/4/2009

for this line
if ($_SESSION['PageType'] != 0) //where 0 lists everything

{

$gsqlWhereExpr = whereAdd($gsqlWhereExpr,"dbo.CityListingTbl.PageType ='" . $_SESSION['PageType'] . "'");

}
if my database is called "city" and my table is called "listings" and the field I'm checking is called "type"
would I put...
if ($_SESSION['PageType'] != 0) //where 0 lists everything

{

$gsqlWhereExpr = whereAdd($gsqlWhereExpr,"dbo.listings.type ='" . $_SESSION['PageType'] . "'");

}



Hi,
you can create just one view, then add WHERE clause dynamically in the After table initialized event on the Events tab:

if ($_SESSION['PageType'] != 0) //where 0 lists everything

{

$gsqlWhereExpr = whereAdd($gsqlWhereExpr,"dbo.CityListingTbl.PageType ='" . $_SESSION['PageType'] . "'");

}



Then fill $_SESSION['PageType'] in your custom hotels.php, restaurants.php files.

S
swgiles 12/4/2009

Yep, that's how it corresponds.