Menu
Hello! This concerns a php website. I am attempting to call a specific page (home_text.php) from within my index.php. Since this is the page content for the homepage, I would like it to appear there and only there.
I am attempting to do this using an “if” statement. Here is my partially successful attempt:
[code=php]<?php
if ($page = “?”) include(“home_text.php”);
} ?>
This seems to do what I want but places the home_text.php content on [I]every
Thank you!!
[code=php]<?php
if ($page = "?") include("home_text.php");
} ?>[/code]
[code=php]<?php
if ($page == "?")
{
include("home_text.php");
}
?>[/code]
Thanks for your response.
As may well be quite obvious, I'm not overly versed in php usage ?
I am modifying an existing site for a friend. It uses one main page (index.php), from which all the other pages get their foundation. For this reason if I just put add an [I]echo[/I] or [I]include[/I] to that main page, the home_text.php then it will appear on each page. I thought that the way to deal with this was to specify the page by using an if statement.
Does this make much sense?[/QUOTE]
[code=php]<?php
if ($page == "?")
{
include("home_text.php");
}
?>[/code]
[code=php]
<?php require_once('Connections/santi.php'); ?>
<?php
//Connection statement
require_once('Connections/santi_ado.php');
$pages = explode("|",$_GET['p']);
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_sections = 1;
$pageNum_sections = 0;
if (isset($_GET['pageNum_sections'])) {
$pageNum_sections = $_GET['pageNum_sections'];
}
$startRow_sections = $pageNum_sections * $maxRows_sections;
$colname_sections = "-1";
if (isset($pages[0])) {
$colname_sections = $pages[0];
}
mysql_select_db($database_santiago, $santiago);
$query_sections = sprintf("SELECT * FROM pages WHERE section
= %s ORDER BY number
ASC", GetSQLValueString($colname_sections, "text"));
$query_limit_sections = sprintf("%s LIMIT %d, %d", $query_sections, $startRow_sections, $maxRows_sections);
$sections = mysql_query($query_limit_sections, $santiago) or die(mysql_error());
$row_sections = mysql_fetch_assoc($sections);
if (isset($_GET['totalRows_sections'])) {
$totalRows_sections = $_GET['totalRows_sections'];
} else {
$all_sections = mysql_query($query_sections);
$totalRows_sections = mysql_num_rows($all_sections);
}
$totalPages_sections = ceil($totalRows_sections/$maxRows_sections)-1;
$queryString_sections = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_sections") == false &&
stristr($param, "totalRows_sections") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_sections = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_sections = sprintf("&totalRows_sections=%d%s", $totalRows_sections, $queryString_sections);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Olivia Santiago - Fine Artist</title>
<meta name="description" content="This is the website for Olivia Santiago, a hawaiian-born painter now living in Florence, Italy">
<link href="img/santiago.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function oliviars_popup(oliviars) {
var w = 600;
var h = 600;
var l = Math.floor((screen.width-w)/2);
var t = Math.floor((screen.height-h)/2);
window.open(oliviars,"", "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ", status=no, menubar=no, toolbar=no, scrollbar=no, directories=no" );
}
//-->
</script>
</head>
<body>
<?php
if ($pages[0] == "links"){ // visualizza i link
?>
<div id="os_body">
<div id="os_top1"><ul><li><a href="?">Home</a></li>
<li><a href="?p=portraits|1" <?php if ($pages[0]=="portraits") { echo "class="a_active""; } ?>>Portraits</a></li>
<li><a href="?p=landscapes|1" <?php if ($pages[0]=="landscapes") { echo "class="a_active""; } ?>>Landscapes</a></li>
<li><a href="?p=still-life|1" <?php if ($pages[0]=="still-life") { echo "class="a_active""; } ?>>Still life</a></li>
<li><a href="?p=bio|1" <?php if ($pages[0]=="bio") { echo "class="a_active""; } ?>>Bio</a></li>
<li><a href="?p=events|1" <?php if ($pages[0]=="events") { echo "class="a_active""; } ?>>Events</a></li>
<li><a href="?p=links|1" <?php if ($pages[0]=="links") { echo "class="a_active""; } ?>>Links</a></li>
</ul> <img src="img/tread.jpg" />
</div>
<div id="os_page1">
<div id="box_text"> <div id="text">
<?php
// begin Recordset
$query_links = sprintf("SELECT * FROM link ORDER BY ordine ASC");
$links = $santiago_ado->SelectLimit($query_links) or die($santiago_ado->ErrorMsg());
$totalRows_links = $links->RecordCount();
// end Recordset
?>
<table class="os_table_links">
<tr >
<td height="20" ></td></tr>
<?php
while (!$links->EOF) {
?>
<tr >
<td height="35" ><p><strong><?php echo $links->Fields('descrizione'); ?></strong><br/><?php if ($links->Fields('url') != "") { ?><a href="<?php echo $links->Fields('url'); ?>" target="_blank" ><?php }?><?php echo $links->Fields('url'); ?></a></p></td>
</tr>
<?php
$links->MoveNext();
}
?>
</table>
</div></div>
</div>
<div id="os_bottom">
<div id="pages">
<div id="page_previous"><?php if ($pageNum_sections > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_sections=%d%s", $currentPage, max(0, $pageNum_sections - 1), $queryString_sections); ?>">previous</a>
<?php } // Show if not first page ?></div>
<div id="message"><a href="mailto:[email protected]" class="credits" >Web Art - [email protected]</a></div>
<div id="page_next"><?php if ($pageNum_sections < $totalPages_sections) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_sections=%d%s", $currentPage, min($totalPages_sections, $pageNum_sections + 1), $queryString_sections); ?>">next</a><?php } // Show if not last page ?></div>
</div>
</div>
</div>
<?php
}
elseif($pages[0] != "links"){ ?>
<div id="os_body">
<div id="os_top1"><ul><li><a href="?">Home</a></li>
<li><a href="?p=portraits|1" <?php if ($pages[0]=="portraits") { echo "class="a_active""; } ?>>Portraits</a></li>
<li><a href="?p=landscapes|1" <?php if ($pages[0]=="landscapes") { echo "class="a_active""; } ?>>Landscapes</a></li>
<li><a href="?p=still-life|1" <?php if ($pages[0]=="still-life") { echo "class="a_active""; } ?>>Still life</a></li>
<li><a href="?p=bio|1" <?php if ($pages[0]=="bio") { echo "class="a_active""; } ?>>Bio</a></li>
<li><a href="?p=events|1" <?php if ($pages[0]=="events") { echo "class="a_active""; } ?>>Events</a></li>
<li><a href="?p=links|1" <?php if ($pages[0]=="links") { echo "class="a_active""; } ?>>Links</a></li>
</ul> <img src="img/tread.jpg" />
</div>
<div id="os_page1">
<?php if ($totalRows_sections > 0) { // Show if recordset not empty
include("modules.php");
} ?>
</div>
<div id="os_bottom">
<div id="pages">
<div id="page_previous"><?php if ($pageNum_sections > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_sections=%d%s", $currentPage, max(0, $pageNum_sections - 1), $queryString_sections); ?>">previous</a>
<?php } // Show if not first page ?></div>
<div id="page_next"><?php if ($pageNum_sections < $totalPages_sections) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_sections=%d%s", $currentPage, min($totalPages_sections, $pageNum_sections + 1), $queryString_sections); ?>">next</a><?php } // Show if not last page ?></div>
</div>
</div>
<div id="os_copyright"> Copyright © 2008 by L. Olivia Santiago - All rights reserved</div>
</div>
<?php
if ($pages = "?") include("home_text.php");
} ?>
</body>
</html>
<?php
mysql_free_result($sections);
?>
[/code]
[code=php]<?php
if ($page == "?")
{
include("home_text.php");
}
?>[/code]
put a print_r($pages); on that page. It will show what is set for each page.[/QUOTE]
right after $pages = explode("|",$_GET['p']);
within the PHP tags. It will tell you the content of $pages, which is what determines what is pulled onto the page. If you see that your "homepage" has a unique value of $pages then you know what to search for in your if statement that includes your home content.[/QUOTE]
[code=php]Array
(
[0] =>
)
[/code]
[code=php]Array
(
[0] => portraits
[1] => 1
)
[/code]
<?php
if ($pages[0] == "[0] =>") include("home_text.php");
} ?>[/QUOTE]
[code=php]<?php
if (empty($pages[0]))
{
include("home_text.php");
}
?>[/code]
[code=php]<?php
if (empty($pages[0]))
{
include("home_text.php");
}
?>[/code]
[/QUOTE]
[code=php]Parse error: syntax error, unexpected $end in C:xampp...index.php on line 214[/code]
0.1.9 — BETA 5.18