Jump to content
php.lv forumi

substr funkcija..


Linee

Recommended Posts

Sveiki. Esmu absolūta 0 kodēšanā, ceru uz jūsu palīdzību,

 

Man vienam skriptam vajadzētu uzlikt substr funkciju, kas izvada no foruma topika nosaukumu... respektīvi vajag, lai viņš izvada tikai pirmos 25 simbolus no topika nosaukuma...

Koderim vajadzētu būt tīrākais sviestmaizei to izdarīt.. es tāds nēesmu :D

<html>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<?php



$config->user_page = ''; ## Ievadi linku uz Profila atrašanās vietu

$config->noavatar_link = 'http://.../forum/public/style_images/.../profile/default_large.png'; ## ievadi linku uz no avatar atrašanās vietu

$config->forum_url = 'forum'; ## Ievadi linku uz foruma atrašanās vietu
$config->limit = '5'; ## Cik postus izvadam ?
$config->topic_link = 'http://.../forum' ; ## Links uz topiku 


$config->mysql = (object)array(

'host' => 'localhost', ## Ievadi MYSQL datubāzes hostu

'user' => 'user', ## Ievadi MYSQL datubāzes useri

'db' => 'user', ## Ievadi MYSQL datubāzes db

'pw' => 'pass', ## Ievadi MYSQL datubāzes paroli

'prefix'=> '' 



);





/** Beidzās skripta konfigurācija **/



$conn = @mysql_connect($config->mysql->host, $config->mysql->user, $config->mysql->pw) or die('<p>Neizdevās pieslēgties datubāzes lietotājam `' . $config->mysql->user . '`!</p>');

@mysql_select_db($config->mysql->db,$conn) or die('<p>Neizdevās pieslēgties datubāzei `' . $config->mysql->db . '`!</p>')





;







$query = mysql_query("

SELECT

t.title as ttitle,

t.tid as tid,

t.state as tstate,

t.posts as tposts ,

t.start_date as tstart_date,

t.last_poster_id as tlast_poster_id,

t.starter_name  as tstarter_name,

t.last_poster_name as tlast_poster_name,

t.seo_first_name as tseo_first_name,

t.pinned  as tpinned,

t.poll_state as tpoll_state,

t.title_seo as ttitle_seo,

t.seo_last_name as tseo_last_name,

t.views as tviews,



m.member_group_id as mmember_group_id,

m.posts as posts,



g.prefix AS group_ref,

g.suffix AS group_suf,

g.g_title AS gtitle,



a.pp_main_photo as pp_thumb_photo



FROM  ".$config->mysql->prefix."topics t 

LEFT JOIN  ".$config->mysql->prefix." members m ON m.member_id = t.last_poster_id

LEFT JOIN  ".$config->mysql->prefix."groups g ON g.g_id = m.member_group_id

LEFT JOIN  ".$config->mysql->prefix."profile_portal a ON a.pp_member_id = m.member_id

GROUP BY t.tid


ORDER BY t.last_post DESC 



LIMIT ".$config->limit."

") or die(mysql_error());



while($row = mysql_fetch_array($query)){



if(empty($row['pp_thumb_photo'])){

$avatar = $config->noavatar_link;

}else{

$avatar = $config->forum_url.'/uploads/'.$row['pp_thumb_photo'];

}




?>

<!-- Izvadam pēdējā atbildētāja avataru -->

<div class="Forum">

<div class="Forumimg">



<img alt="" src="<?php echo $avatar;?>" width="25px;" height="25px;"></a>

</div>

<div class="ForumT">





<a style=" text-decoration: none;" href="/forum/index.php?/topic/<?php echo htmlspecialchars($row['tid']);?>-<?php echo htmlspecialchars($row['ttitle']);?>" class="tooltip"  >

<span style="font-weight: bold;"><?php echo htmlspecialchars($row['ttitle']);?></span><br />

<span style="font-size: 10px;">Komentāri: <?php echo htmlspecialchars($row['tposts']);?></span>

</a>

</div>

</div>

<?php



}

?> 

</html>
Link to comment
Share on other sites

Var divos variantos - nogriezt ar php vai ar MySQL:

a) Tur kur ir <?php echo htmlspecialchars($row['ttitle']);?></span><br /> ieliec:

<?php echo htmlspecialchars(mb_substr($row['ttitle'],0,25));?></span><br />

jābūt multibyte funkciju atbalstam http://lv.php.net/mb_substr (ar parasto substr() var būt problēmas ar unicode (utf8))

vai

 

b) tur kur ir
SELECT

t.title as ttitle,

 

ieliec

SELECT

LEFT(t.title,25) as ttitle

 

Dokumentācija: http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_left

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...