如何将变量从一个php文件打印到另一个php文件 [英] how to print variable from one php file to another php file
本文介绍了如何将变量从一个php文件打印到另一个php文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
header.php文件此代码用于搜索操作
header.php file this code is for search operaitions
<?php
@session_start();
// drop down list
<select name="select">
<option value="empty">none</option>
<option value="fiction">fiction</option>
<option value="journals">journals</option>
<option value="acadamic">acadamic</option>
</select>
<form action="" method="POST">
// search box
<input type="text" value="Enter a keyword here..." name="q" size="10" id="searchfield" title="searchfield" onFocus="clearText(this)" onBlur="clearText(this)" />
<input type="submit" name="Search" value="" alt="Search" id="searchbutton" title="Search" />
<br/>
if (isset($_GET['q']) && isset ($_GET['q']) != "")
{
if($_GET['select'] == "fiction"){
$sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE category = 'fiction'";
}else if($_GET['select'] == "journals"){
$sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE category = 'journals'";
}
else if($_GET['select'] == "acadamic"){
$sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE category = 'acadamic'";
}
$query = mysql_query($sqlcommand) or die($sqlcommand);
$count = mysql_num_rows($query);
if ($count>0)
{
global $searchoutput; // using global variable to print value in other php file
$searchoutput = " $count results ";
// after successufl search I am trying to print the result in new php file using below command
echo '<META http-equiv="refresh" content="0;URL='.INDEX_URL.'result.php">';
}
}
else {
$searchoutput="0 result";
}
?>
result.php
result.php
<?php
echo $searchoutput; // problem is control is again shifting to header.php file and printing always "0 result" from else block
?>
问题是控制再次转移到header.php文件并从else块始终打印0结果
请任何人解决我的问题
problem is control is again shifting to header.php file and printing always "0 result" from else block
please anyone solve my problem
推荐答案
_GET ['q'])&& isset(
_GET['q']) && isset (
_GET ['q'])!=)
{
if(
_GET['q']) != "") { if(
_GET ['选择'] ==小说){
_GET['select'] == "fiction"){
这篇关于如何将变量从一个php文件打印到另一个php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文