Nieuw lid |
|
Hoi allen,
ik heb voor mijn site een script dat random links uit mijn db haalt. Nu zou ik daar een afkortscript aan willen koppelen maar blijkbaar wil het niet zo goed lukken.
Het randomscript ziet er als volgt uit:config.php
<?PHP
//SETTINGS
$linksscripturl = "http://*****/randomer"; //The URL to this script (No trailing slash)
$login = "*****"; //Name to use when logging into the admin panel
$password = "*****"; //Password to the name above
$dbname = "*****"; //Database name where 13 links
$sqlhost = "localhost"; //Host name for mysql (Usually 'localhost')
$sqlusername = "*****"; //Username for the mysql database
$sqlpassword = "*****"; //Password to the mysql database
//Connects to the database, do not edit this
//EDIT NOTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!
function func_MysqlConnect3()
{
global $dbname;
global $sqlhost;
global $sqlusername;
global $sqlpassword;
global $connection;
$connection = mysql_connect($sqlhost,$sqlusername,$sqlpassword) or die ("<font face=verdana>Error: ".mysql_error());
$db = mysql_select_db($dbname) or die ("<font face=verdana>Error: ".mysql_error());
}
function func_Rand($sAmount, $sCategory)
{
func_MysqlConnect3();
if($sCategory == "misc"){$sBoolean = "";}else{$sBoolean = "WHERE category='$sCategory'";}
if($sCategory == "all")
{
$sQuery = "SELECT * FROM randomer ORDER BY RAND() LIMIT $sAmount";
}
else
{
$sQuery = "SELECT * FROM randomer $sBoolean ORDER BY RAND() LIMIT $sAmount";
}
$sQueryresult = mysql_query($sQuery);
WHILE ($sRow = mysql_fetch_array($sQueryresult))
{
PRINT "$sRow[category] - <A HREF=$sRow[url] TARGET=_BLANK >$sRow[caption]</A><BR>\n";
}
mysql_close();
}
?>
<?PHP //SETTINGS $linksscripturl = "http://*****/randomer"; //The URL to this script (No trailing slash) $login = "*****"; //Name to use when logging into the admin panel $password = "*****"; //Password to the name above $dbname = "*****"; //Database name where 13 links $sqlhost = "localhost"; //Host name for mysql (Usually 'localhost') $sqlusername = "*****"; //Username for the mysql database $sqlpassword = "*****"; //Password to the mysql database //Connects to the database, do not edit this //EDIT NOTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING! function func_MysqlConnect3() { } function func_Rand($sAmount, $sCategory) { func_MysqlConnect3(); if($sCategory == "misc"){$sBoolean = "";}else{$sBoolean = "WHERE category='$sCategory'";} if($sCategory == "all") { $sQuery = "SELECT * FROM randomer ORDER BY RAND() LIMIT $sAmount"; } else { $sQuery = "SELECT * FROM randomer $sBoolean ORDER BY RAND() LIMIT $sAmount"; } { PRINT "$sRow[category] - <A HREF=$sRow[url] TARGET=_BLANK >$sRow[caption]</A><BR>\n"; } } ?>
In mijn index.php:
<?PHP func_Rand(150, "textlinks");?>
<?PHP func_Rand(150, "textlinks");?>
Ik heb wel een afkortscript maar ik krijg het niet in mijn randomscript verwerkt ( of op de index.php )
Het afkortscript is als volgt:
Voor de select
<? function afkorten($string, $lenght, $end = ' ...') { if (strlen($string) > $lenght) { $lenght -= strlen($end); $last = strrpos(substr($string, 0, $lenght + 1), ' '); return substr($string, 0, (!$last)? $lenght: $last) . $end; } return $string; } ?>
Na de select
<? $tekst=afkorten($row[je_tekst],50); ?>
Voor de select <? function afkorten ($string, $lenght, $end = ' ...') { if (strlen($string) > $lenght) { $lenght -= strlen($end); $last = strrpos(substr($string, 0, $lenght + 1), ' '); return substr($string, 0, (!$last)? $lenght: $last) . $end; } return $string; } ?> Na de select <? $tekst=afkorten($row[je_tekst],50); ?>
Iemand een gedacht hoe ik dit het best oplos ?
Thx alvast
|