我有我的網站下面的PHP代碼基本上訪問,從一個MySQL表翻出信息的PHP腳本;引用的PHP代碼段
<?php include('event_connect.php'); ?>
是否可以在此腳本中包含對特定代碼段的引用?
基本上我有創建個人下拉例如39名不同的腳本在「XXX」下拉菜單中,只會顯示標識符爲「xxx」的記錄。
我以爲會更容易比createing 39個腳本是(如果可能)不同的地方在頁面上它被放置只是添加某種參考價值的,以上面的代碼。有點像VBA如何讓你從另一個選定的功能...
編輯:這是我用來訪問mysql數據庫的PHP,用niet提供的代碼添加了 - 作品一種享受!謝謝。
<?php
//Get te CSS styling
// Make a MySQL Connection
mysql_connect("xxxx", "xxxx", "xxxx", "xxxx") or
die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
// Retrieve all the data from the "xxxx" table
switch($section) {
case 1:
$result = mysql_query("SELECT * FROM `Events_List` WHERE `Value` = 'value_1' LIMIT 0 , 30") or die(mysql_error());
break;
case 2:
$result = mysql_query("SELECT * FROM `Events_List` WHERE `Value` = 'value_2' LIMIT 0 , 30") or die(mysql_error());
break;
// store the records of the "xxxx" table into $row array and loop through
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $name = $row['name'];
$Event = $row['Event'];
$Date = $row['Date'];
$Type = $row['Type'];
$Description = $row['Description'];
$Event = htmlspecialchars($row['Event'],ENT_QUOTES);
$Date = htmlspecialchars($row['Date'],ENT_QUOTES);
$Type = htmlspecialchars($row['Type'],ENT_QUOTES);
$Description = htmlspecialchars($row['Description'],ENT_QUOTES);
echo " <div id='ev_con'>
<div id='ev_img'> </div>
<div id='Event'> $Event </div>
<div id='Date'> $Date </div>
<div id='Type'> $Type </div>
<div id='Description'> $Description </div>
</div>";}
?>
這將運行一個查詢正常,但遇到了麻煩運行多個查詢..
老實說,我想不出你的問題是什麼意思。我不認爲你在問PHP是否有變量或函數,對嗎? –
使用「require_once()」而不是「包括()」爲startes,然後看看我們的PHP函數的一些教程。 – Arrok
嗨阿爾瓦羅,我認爲(和我希望)是Niet的馬蒂已經得到了答案下面,它是有道理的,一目瞭然,看起來像它在正確的軌道上! Arrok - 大量的在線教程,但並不總是有用的特定需求。總是發現堆棧溢出是解決編碼問題的最佳途徑之一:) – adrunis84