2012-08-01 64 views
0

我有哪些內容正在被送入動態兩頁,第一個index.php文件包括其他頁面person.php當我點擊鏈接:如何在php中使用其他元標記的頁面值?

的index.php:

<?php include("db1.php"); 
define('WP_USE_THEMES', false); 
require('blog/wp-blog-header.php'); 
$pages=array(
       "person"=>"person.php" 


       ); 

?> 
<!DOCTYPE html> 
<head> 
<title>Untitled Document</title> 
<meta property="og:title" content=""/> 

    <meta property="og:url" content=""/> 
    <meta property="og:site_name" content=""/> 
    <meta property="og:description" content=""/> 
</head> 

<body> 
<? 
    $sql="select id, name,title,image from persons where cat =10 "; 
    $rs=mysql_query($sql)or die(mysql_error()); 
    if(list($id,$name,$title,$image)=mysql_fetch_array($rs)){ 
     ?> 
<a href="?page=person&p=<? echo $id;?>" id="<? echo $id;?>" class="details"> 
<? 
    } 
    ?> 
<div class="twelve columns" id="persons"> 

     <? 
if($_GET["page"]=="") 
        $p="persons1"; 
       else 
        $p=$_GET["page"]; 

       if($pages[$p]!="") 
        include($pages[$p]); 
       else 
        echo "page not found "; 
        ?> 
        </div> 
</body> 
</html> 

第2頁:person.php:

<? include("db1.php");?> 
<?php 
define('WP_USE_THEMES', false); 
require('blog/wp-blog-header.php'); 
?> 
<div class="row"> 
    <div class="twelve columns"> 
     <div class="eight columns"> 

    <? 
    if(isset($_GET['p'])){ 
$id=str_replace('-',' ',(string)$_GET['p']); 
$name1=""; 
    $sql="select id, name,title,details,image,cat from persons where name ='".$id."' order by name asc"; 
    $rs=mysql_query($sql)or die(mysql_error()); 
    if(list($id,$name,$title,$details,$image,$cat)=mysql_fetch_array($rs)){ 
     $a=$name; 
    ?> 
    <h3><? echo $name;?></h3> 
    <h5><? echo $title;?></h5> 
    <p align="justify"> 
     <img alt="<? echo $name;?>" src="images/persons/<? echo $image?>" title="<? echo $name;?>" style="float:right; margin-left:15px;" /> 
     <? echo $details;?> 
    </p> 
    <? 
    } 
    } 
?> 

當包括頁面如何使用person.php頁面的值的index.php的meta標籤?

+0

哪裏是在要使用'person.php'的數據?在它的表面上,這應該是非常簡單的,因爲'person.php'不使用從index.php繼承的任何數據,因此它可以在腳本的頂部運行並且結果被捕獲到輸出中緩衝區,稍後再回聲。另外,讓我向你介紹一個叫做[Bobby Tables]的老敵人(http://bobby-tables.com/) – DaveRandom 2012-08-01 15:54:12

+0

我想用($ name,$ title,$ details,$ image)結果MySQL在index.php的元標記中的person.php中選擇,問題是人應該被包含在頭標記之後,因爲我的頁面結構 – 2012-08-01 15:57:52

+0

好吧,我不想只給你答案,直到你已經自己嘗試過了,或者你不會學到任何東西,但以下是你需要完成的所有信息:你需要將包含文件的邏輯移動到index.php的頂部,高於''。您需要使用[輸出緩衝](http://php.net/ob-start)來捕捉'person.php'的輸出,以便它可以在正確的位置輸出。一旦包含文件,它創建的變量將在index.php中可用。如果你對此有任何疑問,我會很樂意幫助你,但先去玩一下。 – DaveRandom 2012-08-01 16:07:59

回答

0

您可以使用php global關鍵字聲明您想要使用的變量,以便在您的兩個文件中定義變量。詳情請看這裏:http://us3.php.net/manual/en/language.variables.scope.php

但是,使用像你一樣的通用名稱($ name,$ title,$ details,$ image)必然會導致衝突,尤其是在Wordpress環境中。最好的辦法是選擇一個唯一的變量名,聲明爲一個數組,並設置每個這些項目的要素:

global $amer_enaya_fb_metadata; 
$amer_enaya_fb_metadata = array('name' => $name, ...); 
相關問題