Page 1 sur 1

fonction substr

Posté : 17 mars 2010, 22:14
par noublio
hello a tous,

comment couper le titre du topic dans ce code msvp ? j'ai essayé, j'y comprends pas grand chose.
 <?php
    // How Many Topics you want to display?
    $topicnumber = 6;
    // Scrolling towards up or down?
    $scroll = "up";
    // Change this to your phpBB path
    $urlPath = "/forum";
 
    // Database Configuration (Where your phpBB config.php file is located)
    include 'forum/config.php';
 
    $table_topics = $table_prefix. "topics";
    $table_forums = $table_prefix. "forums";
    $table_posts = $table_prefix. "posts";
    $table_users = $table_prefix. "users";
    $link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect");
    mysql_select_db("$dbname") or die("Could not select database");
 
    $query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username
    FROM $table_topics t, $table_forums f, $table_posts p, $table_users u
    WHERE t.topic_id = p.topic_id AND
    f.forum_id = t.forum_id AND
    t.forum_id != 4 AND
    t.topic_status <> 2 AND
    p.post_id = t.topic_last_post_id AND
    p.poster_id = u.user_id
 
    ORDER BY p.post_id DESC LIMIT $topicnumber";
	$result = substr(topic_title,0,10);
    $result = mysql_query($query) or die("Query failed");									
 	
    print "
    <table cellpadding='3' cellSpacing='2' width='350'>";
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
 
    echo  "<tr valign='top'><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#FFCC00\"><b><a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\" TARGET=\"_blank\">" .
    $row["topic_title"] .
    "</a></td></font></b><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#C0C0C0\"> " .
    "</td><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#C0C0C0\">" .
    date('G:i', $row["post_time"]) .
    "</td></tr></font>";
    }
    print "</table>";
    mysql_free_result($result);
    mysql_close($link);
    ?>

Re: fonction substr

Posté : 17 mars 2010, 22:16
par Invité
j'avais ajouté cette ligne : $result = substr(topic_title,0,10); mais en vain

Re: fonction substr

Posté : 20 mars 2010, 12:33
par Ryle
Le principe est bon, mais tu ne l'applique pas correctement.

Le titre du topic provient de ta base de données. Il te faut par conséquent exécuter ta requête, puis parcourir les résultats, et alors seulement tu porras récupérer le titre pour le tronquer.

Au lieu de faire appel à $row["topic_title"] pour afficher le titre du topic, il te suffit de faire
substr($row["topic_title"],0,10)
à l'endroit souhaité :)