Форум сетевых администраторов
Показаны 4 сообщений на этой странице

Форум сетевых администраторов (http://netadmin.ws/forum/index.php)
- PHP (http://netadmin.ws/forum/forumdisplay.php?forumid=6)
-- Функция... (http://netadmin.ws/forum/showthread.php?threadid=3069)


Помещено MASTER 11-09-2002 в 20:53:

Функция...

вот есть код:

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 и тд..помогите плз.


Помещено polo 11-09-2002 в 23:22:

ты это имеешь ввиду?

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);
?>

__________________
Всегда есть решение.


Помещено MASTER 12-09-2002 в 05:57:

нет..

как это:

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('$','&#36;', $toptitle);    
        
$toptitle = str_replace (' ', '&nbsp;', $toptitle); 
        
$toptitle = $toptitle . '('. $A['hits'] . ')'; 
        
$topstories[] = $urlstart . '<small>' .$toptitle. '</small></a>'; 
    } 
    
$retval .= COM_makeList ($topstories); 
} else { 
    
$retval .= "No Stories<br>" . LB; 
} 
return 
$retval; 

}


Помещено polo 12-09-2002 в 07:10:


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);
}
?>

__________________
Всегда есть решение.


Формат времени GMT. Текущее время 02:10.
Показаны 4 сообщений на этой странице

Powered by: vBulletin Version 2.2.4
Copyright © Jelsoft Enterprises Limited 2000, 2001.