我需要能夠把我以前建立的網站的一部分放入另一個網站即時製作。然而,無論是在PHP和有問題的語法(即過多的子集「和「),我怎樣才能把這個代碼:如何將一個複雜的php代碼放入另一個php代碼中?
if(mysql_num_rows($result) == 0)
{
echo 'No categories defined yet.';
}
else
{
//prepare the table
echo '<table border="1">
<tr>
<th>Category</th>
<th>Last topic</th>
</tr>';
while($row = mysql_fetch_assoc($result))
{
echo '<tr>';
echo '<td class="leftpart">';
echo '<h3><a href="category.php?id=' . $row['cat_id'] . '">' . $row['cat_name'] . '</a></h3>' . $row['cat_description'];
echo '</td>';
echo '<td class="rightpart">';
//fetch last topic for each cat
$topicsql = "SELECT
topic_id,
topic_subject,
topic_date,
topic_cat
FROM
topics
WHERE
topic_cat = " . $row['cat_id'] . "
ORDER BY
topic_date
DESC
LIMIT
1";
$topicsresult = mysql_query($topicsql);
if(!$topicsresult)
{
echo 'Last topic could not be displayed.';
}
else
{
if(mysql_num_rows($topicsresult) == 0)
{
echo 'no topics';
}
else
{
while($topicrow = mysql_fetch_assoc($topicsresult))
echo '<a href="topic.php?id=' . $topicrow['topic_id'] . '">' . $topicrow['topic_subject'] . '</a> at ' . date('d-m-Y', strtotime($topicrow['topic_date']));
}
}
echo '</td>';
echo '</tr>';
}
}
這個代碼(我想表本身在裏面股利主的歡迎下)
echo
"<div id=holder>
<div id='nav'>
<a href='chat.php'>Chat with your friends!</a>
<br><br><a href='changepassword.php'>Change password</a><br><br>
<a href='logout.php'>Logout</a>
</div>
<div id='main'>
Welcome, ".$_SESSION['user_name']."!
</div>
</div>";
//fetch last topic for each cat
$topicsql = "SELECT
topic_id,
topic_subject,
topic_date,
topic_cat
FROM
topics
WHERE
topic_cat = " . $row['cat_id'] . "
ORDER BY
topic_date
DESC
LIMIT
1";
$topicsresult = mysql_query($topicsql);
if(!$topicsresult)
{
echo 'Last topic could not be displayed.';
}
else
{
if(mysql_num_rows($topicsresult) == 0)
{
echo 'no topics';
}
else
{
while($topicrow = mysql_fetch_assoc($topicsresult))
echo '<a href="topic.php?id=' . $topicrow['topic_id'] . '">' . $topicrow['topic_subject'] . '</a> at ' . date('d-m-Y', strtotime($topicrow['topic_date']));
}
}
echo '</td>';
echo '</tr>';
}
}
};
我認識到這是相當複雜的,但我很迷失在這一點上,語法,所以如果有人可以幫助我在此ITD有點不勝感激
警告你的代碼可能容易受到sql注入攻擊。 –
我知道了,即時執行sha1和/或鹽後,我知道這 – ryno
「sha1和/或鹽」與SQL注入沒有任何關係。 – ceejayoz