2016-05-19 25 views
-3

私はのfunctions.php別のPHPファイルからPHP変数を取得するには?

while ($row_posts = mysqli_fetch_array($run_news)) { 

    $news_id = $row_posts['news_id']; 
    $user_id = $row_posts['user_id']; 
    $topic_id = $row_posts['topic_id']; 
    $news_title = $row_posts['news_title']; 
    $news_date = $row_posts['news_date']; 

    // getting the user who has posted the thread 

    $user = "select * from users where user_id ='$user_id' AND posts = 'yes'"; 

    $run_user = mysqli_query($con, $user); 
    $row_user = mysqli_fetch_array($run_user); 
    $user_name = $row_user['user_name']; 
    $user_image = $row_user['user_image']; 

そして、私はあなたが変数を持ってしようとしている場合は$文字列を動的にユーザー

$string = 'Massive fire underneath Metro-North tracks in MODEL TOWN disrupts train service.'; 
$lower_string= strtolower($string); 
+1

は ''ファイル)(含めますか?あなたが何をしているのかは分かりません... –

+0

変数スコープの古典的なケース –

+0

私はそれを含んでいますが、while(function.phpで)しばらくしてから、(showmap.php)で$ news_titleを取得していますそのタイトルを$ string –

答えて

0

から来ることにしたい別のファイルshowmap.phpを持っています同じリクエストで転送するには、include()またはrequire()のようなものを使用する必要があります。

しかし、ファイルが別のPHPファイルにリダイレクトされていても、変数を使用できるようにするには、セッションまたはクッキーに保存することができます。

セッション内に書かれたものは、複数のPHPページで利用できます。ここで

は、セッションを使用しての詳細です:http://www.w3schools.com/php/php_sessions.asp

関連する問題