Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

Dynamic pages php

Status
Not open for further replies.
Joined
Jun 6, 2011
Posts
760
Reaction score
7
Hi guys, Just trying to finish off the last bit of work on my sites just to add abit more to the site before they get sent elsewhere,

Basiclly hotel listings get pulled down off the mysql database table and displays a list of hotels and prices in that area, as seen at londonhoteloffers.org.uk/search.php at the moment tho the view details link is a link that points to that hotel on laterooms, but I would like to be able to be able to click that link and then it creates a dynamic page by pull the rest of the data row from the db of the hotel infomation on my site, I have looked around in row to do this and I kind of understand how its done I just cant find what im looking for on google, I thought I did but wasnt quite right, can anyone tell me what its called Im looking for or point me to a site or tutorial of what im trying to do,

Thank you for you time

Ryan
 
Change the link to:

yourdynamicpage.php?ID=12345

Where 12345 is the id number of the hotel from the database.

Then in yourdynamicpage.php use:

$hotelID = $_GET['ID']

You then use the $hotelID variable within the SQL query to bring back the data you need to build the page.

Grant
 
if you already query the db to get the summary data from the row, you simply need to extend the query now to select the other columns you'd like to display and format your html accordingly to display the returned data.
 
thanks for the reply, can you point me somewhere to where i can read up about this, or tell me what its called im looking for so i can search it myself, pref somewhere that has examples

thanks
 
also where in the link you put 12345 instead would it be ['hotelid'] or ['ID']

thanks
 
Play around with it and work it out for yourself, I've just given you the basics of what you need to do.

Also, why have you opened two identical threads for this?? Please get admin to close one down.

Grant
 
If your using GET, for ANYTHING cleanse the data. For a number use is_numeric to verify someone isn't trying to inject anything.
 
i would rather not get little bits of info like this now i sort of know what im doing as it makes it harder to guess! that why im asking to point me somewhere that has a tutorial on this or info of what im after, or even just tell me what its called im looking for
Thanks
 
passing variable in url

passing variable between pages


or something similar
 
Yea I know, Im always trying to learn tho for the future projects thanks for all you help,
 
You need to look up

Conditional Select SQL

Conditional Select URL Encoded SQL

Clean Variables PHP

SQL Injection Protection
 
I jsut cant get this to work, I can get the id in the url but cant get it to display the right data, just display the first result in the db and not the one with that id

I really do hate php

Ryan
 
I jsut cant get this to work, I can get the id in the url but cant get it to display the right data, just display the first result in the db and not the one with that id

I really do hate php

Ryan

It sounds like the problem is in the logic / SQL, not PHP :) You need to put the id from the url into there WHERE clause.

Without wanting to put you down in a public forum, this is very basic PHP/SQL and not difficult to find tutorials for with a simple Google search.

Do yourself a favour and order yourself something like this Build Your Own Database Driven Web Site Using PHP & MySQL. These Sitepoint books make a very good place to start.
 
I jsut cant get this to work, I can get the id in the url but cant get it to display the right data, just display the first result in the db and not the one with that id

I really do hate php

Ryan

So youre passing the hotel ID field from the database to the dynamic page?

Then on the dynamic page you query the database to bring back the data for that hotel ID

SELECT * From tablename WHERE id = the id number youve passed to the page

Grant
 
Hmmm thats what I thought I had done
SELECT * FROM hotels WHERE id = ['HotelID'];

Right ok well I will give it 5 and try again as I must be missing something somewhere as Im pretty sure I have evrything else

Ryan
 
You need to do something like

$h_id = $_GET['Hotel_ID'];

Ideally you need to test the h_hid variable is_numeric to ensure someone isn't passing you fly code.

Now your SELECT needs to have the

WHERE id = $h_id

Passing a variable direct is asking for it really.
 
Firstly, good job for having a crack at this.

You don't learn anything if you simple copy and paste from around the web

So you have the hotel id passed as a parameter(hotelid) in the url, such as

domain.com?hotelid=1

<?

//This gets the hotel id from the url and stores it in a variable for use
$iHotelId = $_GET['hotelid'];

//Check if it is a number.
//This is to give a minimal amount of safety against people adding extra //things to this parameter hotelid in your url.
//see http://en.wikipedia.org/wiki/SQL_injection

if (is_numeric($iHotelId)) {
$query= "SELECT * FROM hotels WHERE id = $iHotelId";

// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for //debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

}else {
die('An invalid parameter has been passed in the URL');
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
echo $row['hotelname'];
echo $row['hotelDesc'];

}

// Free the resources associated with the result set
// This is done automatically at the end of the script
mysql_free_result($result);

?>

Hope this helps a little

A
 
Last edited:
Cheers everyone for there help, I think we are there now with all your help, what is it called when you change the url to say the hotel name instead of it being say desc.php?id=ba ba

so its something like desc.php/hotel-name?

Thnaks again everyone
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members online

Premium Members

New Threads

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
      There are no messages in the current room.
      Top Bottom