Jump to content

Restaurant Directory Help


Seglespaan

Recommended Posts

Hi,

 

I'm creating a restaurant directory which is linked to an sql database.

 

On the main page the user can search either in the search box or by using two dropdowns, Restaurant (restaurant / takeaway) type & Cuisine type,

 

the user is then drected to restaurantlist.php where the results of the search are shown in a list.

 

by clicking on the restuarant name the user is then taken to restaurantdetails.php where the full restaurant page is displayed.

 

What I want is a next and previous button that takes the user to the next/previous Italian restaurant on the previously displayed list of restaurants, (assuming they chose italian restaurants in the search fields)

 

I have been struggling with this for a few days now and woul really appreciate any help u can give,

 

Cheers

 

Seglespaan

Link to comment
https://forums.phpfreaks.com/topic/122742-restaurant-directory-help/
Share on other sites

You could have two SQL queries.

 

The first SQL query could fetch the restaurant id WHERE the restaurant id is less than the one you're on (sort this by ID ascending). The second SQL query could fetch the restaurant id WHERE the restaurant id is greater than the one you're on (sort this by ID descending).

 

Loop through your sql results respectively and have a php variable inside the loop that sets itself to the respective restaurant id. For the first SQL query, the php variable will contain the closet previous restaurant id after this loop. For the second SQL query, the other php variable will contain the closet next restaurant id after this loop.

 

Make an if statement around each button (previous or next) to make sure there was a result. If it passes, link to the respective restaurant id's restaurant detail page.

 

I'm sure this isn't the best way to do it, but I think it would work and should at least give you another idea.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.