chrispos Posted April 24, 2013 Share Posted April 24, 2013 Hi All Thanks for looking. I am trying to include individual pages to appear on a page with each page name in a database. When I put the include page it shows it exact but what I would like to do is have the pages included in the main page. Here is the code i have used include 'config.php'; $query = "SELECT * FROM `hotel`ORDER BY RAND()"; $result = mysql_query ($query); // Run the query. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <h2>' . $row['name'] . '</h2> <p> '. $row['page'] . '</p> '; } ; mysql_free_result ($result); // Free up the resources. mysql_close(); row page being each subjects individual page. Thanks for looking Quote Link to comment Share on other sites More sharing options...
DHood Posted April 24, 2013 Share Posted April 24, 2013 Have you tried include($page); Quote Link to comment Share on other sites More sharing options...
davidannis Posted April 24, 2013 Share Posted April 24, 2013 or perhaps include ($row['page']); Quote Link to comment Share on other sites More sharing options...
chrispos Posted April 24, 2013 Author Share Posted April 24, 2013 Tried these but still it will not show the pages very strange to be honest Quote Link to comment Share on other sites More sharing options...
davidannis Posted April 24, 2013 Share Posted April 24, 2013 does $row['page'] have the path either relative (from the script to the page) or absolute (from the root directory)? Quote Link to comment Share on other sites More sharing options...
chrispos Posted April 24, 2013 Author Share Posted April 24, 2013 If I explain exactly then this might help and by the way thanks for your help it is great OK when I am including the config.php page (database connection I am using include 'config.php'; The hotels pages are stored in the same directory so I am using the code above include 'config.php'; $query = "SELECT * FROM `hotel`ORDER BY RAND()"; $result = mysql_query ($query); // Run the query. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <h2>' . $row['name'] . '</h2> <p>'. include $row['page'].'</p> '; } ; mysql_free_result ($result); // Free up the resources. mysql_close(); I have set up a page to test if the pages are shown just by putting in include page etc and that works so it is not a directory issue. I tried the code as you wrote it and in theory it should work. I have set them up to show images and links in the past but it does not want to include the pages very strange. In the database I am storing the include pages as 'dhot.php' Quote Link to comment Share on other sites More sharing options...
chrispos Posted April 24, 2013 Author Share Posted April 24, 2013 The reason I am trying to include a page is because it started out as an SQL issue but I had an issue with that. The code I used is below include 'config.php'; include 'date.class.php'; $start = new Date(false ,$d, $m, $y); $end = new Date(false ,$d1, $m1, $y1); $query = "SELECT * FROM `hotel`ORDER BY RAND()"; $result = mysql_query ($query); // Run the query. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <h2>' . $row['name'] . '</h2> '; } ; $result = mysql_query ("SELECT * FROM rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"); $num_rows = mysql_num_rows($result); echo "$num_rows Rows\n"; mysql_free_result ($result); // Free up the resources. mysql_close(); d m y and d1 m1 y1 are start dates and end dates and what happens when the form is posted is it comes up with the hotel name as it should but it does not come up with the number of rows for each hotel. I had better explain this more so you get the picture. Three tables hotel rooms and bookings. Hotel has hid as do the rooms and bookings tables. (Hotel I D) Rooms have room id and booking have booking id. The rows show but only for one hotel so that tells me that the hotel id is not being picked up on the count query so if anyone has any ideas there that could be the answer to the question but as much as I have tried i am stumped. Quote Link to comment Share on other sites More sharing options...
davidannis Posted April 24, 2013 Share Posted April 24, 2013 Try changing this echo ' <h2>' . $row['name'] . '</h2> <p>'. include $row['page'].'</p> to this: echo ' <h2>' . $row['name'] . '</h2> <p>'; include ($row['page']); echo '</p> Quote Link to comment Share on other sites More sharing options...
chrispos Posted April 24, 2013 Author Share Posted April 24, 2013 (edited) The hotel names are coming up fine. Thank you I have tried it but no it does not work. I think I am going to have to try a different way Edited April 24, 2013 by chrispos Quote Link to comment Share on other sites More sharing options...
Solution chrispos Posted April 24, 2013 Author Solution Share Posted April 24, 2013 This is now resolved by using a different approach the code is as follows should it be of interest include 'config.php'; include 'date.class.php'; $start = new Date(false ,$d, $m, $y); $end = new Date(false ,$d1, $m1, $y1); $query = "SELECT * FROM `hotel`ORDER BY RAND()"; $result = mysql_query ($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) if (mysql_num_rows($result)>0){ $hid = $row['hid']; $result1 = mysql_query ("SELECT * FROM rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"); $num_rows = mysql_num_rows($result1); echo $row['name']."<br>"; echo $row['hid']."<br>"; echo "$num_rows Rows<br><br>"; } mysql_free_result ($result); // Free up the resources. mysql_close(); Thank you for looking and helping Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.