 |
 |
Форум сетевых администраторов » Программирование » PHP » Функция...
| Автор |
| Тема |
 |
|
 |
|
|
|
Участник+


Нарушения: 
Зарегистрирован: Oct 2001
Место проживания: Торонто
Публикаций: 259
Статус:  |
вот есть код:
PHP:
<?php
include("config.php");
$connection = mysql_connect("$servername","$dbusername","$dbpassword") or die ("Cannot connect to server.");
$db = mysql_select_db("$dbname", $connection) or die ("Could not select database.");
$sql = "SELECT title, threadid, replycount, postusername, lastposter from thread order by lastpost desc limit 14";
$sql_result = mysql_query($sql, $connection) or die ("Could not execute query.");
if (!$sql_result) {
echo "<p>Could not get record.";
}
while ($row = mysql_fetch_array($sql_result)) {
$threadid = $row["threadid"];
$thetitle = $row["title"];
$replycount = $row["replycount"];
$postusername = $row["postusername"];
$postuserid = $row["postuserid"];
$lastposter = $row["lastposter"];
echo "<body text=#000000 link=#000000 vlink=#000000 alink=#000000><font size=2 face=Verdana,Arial,Helvetica><table width=150>";
echo ">> <a href=\"forum/showthread.php?s=&threadid=$threadid\"><b>$thetitle</b></a> -$lastposter [$replycount]<br>";
echo "</table></font></body>";
}
mysql_free_result($sql_result);
mysql_close($connection);
?>
нужно сделать функцию из этого кода..чтоб не изпользывать print, echo и тд..помогите плз.
Сообщить модератору об этом сообщении | Предупреждение | IP: определен
|
11-09-2002 20:53 |
|
|
Администратор
|
ты это имеешь ввиду?
[php]
<?php
include("config.php");
$connection... |
[сооб. #24242]
11-09-2002 23:22 |
|
Администратор


Зарегистрирован: May 2001
Место проживания:
Публикаций: 4642
Статус:  |
ты это имеешь ввиду?
PHP:
<?php
include("config.php");
$connection = mysql_connect("$servername","$dbusername","$dbpassword") or die ("Cannot connect to server.");
$db = mysql_select_db("$dbname", $connection) or die ("Could not select database.");
$sql = "SELECT title, threadid, replycount, postusername, lastposter from thread order by lastpost desc limit 14";
$sql_result = mysql_query($sql, $connection) or die ("Could not execute query.");
if (!$sql_result) {
?>
<p>Could not get record.
<?php
}
while ($row = mysql_fetch_array($sql_result)) {
$threadid = $row["threadid"];
$thetitle = $row["title"];
$replycount = $row["replycount"];
$postusername = $row["postusername"];
$postuserid = $row["postuserid"];
$lastposter = $row["lastposter"];
?>
<body text=#000000 link=#000000 vlink=#000000 alink=#000000><font size=2 face=Verdana,Arial,Helvetica><table width=150>
>> <a href=\"forum/showthread.php?s=&threadid=$threadid\"><b>$thetitle</b></a> -$lastposter [$replycount]<br>
</table></font></body>
<?php
}
mysql_free_result($sql_result);
mysql_close($connection);
?>
__________________
Всегда есть решение.
Сообщить модератору об этом сообщении | Предупреждение | IP: определен
|
11-09-2002 23:22 |
|
|
Участник+
|
нет..
как это:
[php]
function phpblock_topStories(){
global... |
[сооб. #24249]
12-09-2002 05:57 |
|
Участник+


Нарушения: 
Зарегистрирован: Oct 2001
Место проживания: Торонто
Публикаций: 259
Статус:  |
нет..
как это:
PHP:
function phpblock_topStories(){
global $_TABLES;
$result = DB_query("SELECT sid,title,hits FROM {$_TABLES["stories"]} WHERE draft_flag = 0 AND Hits > 0 ORDER BY Hits desc LIMIT 5");
$nrows = DB_numRows($result);
if ($nrows > 0) {
$topstories = array ();
for ($x = 1; $x <= $nrows; $x++) {
$A = DB_fetchArray($result);
$itemlen = strlen($A['title']);
$toptitle = stripslashes ($A['title']) ;
$urlstart = '<a href="' . $_CONF['site_url'] . '/article.php?story=' . $A['sid'] .'">';
// Trim the length if over 17 characters - needed for the Xsilver template Right Block side but others are wider
if ($itemlen > 20) {
$toptitle = substr($toptitle, 0, 17) . "...";
}
$toptitle = str_replace('$','$', $toptitle);
$toptitle = str_replace (' ', ' ', $toptitle);
$toptitle = $toptitle . '('. $A['hits'] . ')';
$topstories[] = $urlstart . '<small>' .$toptitle. '</small></a>';
}
$retval .= COM_makeList ($topstories);
} else {
$retval .= "No Stories<br>" . LB;
}
return $retval;
}
Сообщить модератору об этом сообщении | Предупреждение | IP: определен
|
12-09-2002 05:57 |
|
|
Администратор
|
[PHP]
<?php
include("config.php");
function list() {
global $servername,... |
[сооб. #24255]
12-09-2002 07:10 |
|
Администратор


Зарегистрирован: May 2001
Место проживания:
Публикаций: 4642
Статус:  |
PHP:
<?php
include("config.php");
function list() {
global $servername, $dbusername, $dbpassword, $dbname;
$connection = mysql_connect("$servername","$dbusername","$dbpassword") or die ("Cannot connect to server.");
$db = mysql_select_db("$dbname", $connection) or die ("Could not select database.");
$sql = "SELECT title, threadid, replycount, postusername, lastposter from thread order by lastpost desc limit 14";
$sql_result = mysql_query($sql, $connection) or die ("Could not execute query.");
if (!$sql_result) {
?>
<p>Could not get record.
<?php
}
while ($row = mysql_fetch_array($sql_result)) {
$threadid = $row["threadid"];
$thetitle = $row["title"];
$replycount = $row["replycount"];
$postusername = $row["postusername"];
$postuserid = $row["postuserid"];
$lastposter = $row["lastposter"];
?>
<body text=#000000 link=#000000 vlink=#000000 alink=#000000><font size=2 face=Verdana,Arial,Helvetica><table width=150>
>> <a href=\"forum/showthread.php?s=&threadid=$threadid\"><b>$thetitle</b></a> -$lastposter [$replycount]<br>
</table></font></body>
<?php
}
mysql_free_result($sql_result);
mysql_close($connection);
}
?>
__________________
Всегда есть решение.
Сообщить модератору об этом сообщении | Предупреждение | IP: определен
|
12-09-2002 07:10 |
|
|


|
Формат времени GMT. Текущее время 02:18.
|
Правила форума:
Вы не можете создавать новые темы.
Вы не можете отвечать на существующие темы.
Вы не можете прикреплять файлы.
Вы не можете редактировать свои сообщения. |
HTML теги выкл.
Спец. код вкл.
Смайлики вкл.
[IMG] тег выкл.
|
|
|
|
| |
Page generated in 1.41354394 seconds (99.48% PHP - 0.52% MySQL) with 23 queries.
|
 |