Jump to content

Trying to include a pages using a database


chrispos
Go to solution Solved by chrispos,

Recommended Posts

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

Link to comment
Share on other sites

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'
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.