FForce2195 Posted October 8, 2008 Share Posted October 8, 2008 Hello. I've been studying PHP for about 9 days. I have a table that I imported from another database. There are 16 fields. I only want to display 2 to 4 of them on the screen. A slight problem that I just noticed is that one of the fields contains long, continuous URLs. This field is 'comment_content.' So I wrote $sql_date = "select comment_author, comment_date_gmt, comment_content from $table0a ORDER by comment_ID DESC LIMIT 0,500"; $xdate_julia = mysql_query($sql_date, $my_julia) or die(mysql_error()); print "<html>"; print "<body>"; print "<table border=1>"; print "<tr><td>comment_author</td><td>comment_author_url</td><td>comment_date</td><td>comment_content</td></tr>"; while ($date_row = mysql_fetch_array ($xdate_julia)) { print "<tr><td>" . $date_row["comment_author"] . "</td>"; print "<td>" . $date_row["comment_author_url"] . "</td>"; print "<td>" . $date_row["comment_date_gmt"] . "</td>"; print "<td>" . chunk_split($date_row["comment_content"],50) . "</td></tr>"; } print "</table>"; print "</body>"; print "</html>"; The result turns out okay. But I actually want to use <strong>Smarty</strong> to format the table with alternating colored rows and controlled column widths. So I wrote $xdate_julia = mysql_query("select comment_author, comment_date_gmt, comment_content from $table0a ORDER by comment_ID DESC LIMIT 0,500"); $spam_2k = array(); while ($row = mysql_fetch_assoc($xdate_julia)) { $spam_2k[] = $row; } //Smarty require_once("smarty_2619/libs/Smarty.class.php"); $smarty = new Smarty(); $smarty->assign("spam", $spam_2k); $smarty->display("spam_2k.tpl"); The result turns out okay with beautifully alternating colored rows. But I don't know when to use chunk_split in the second code. Anybody has any idea how I edit my code to split data in the comment_content field? By the way, there are a few thousand rows of data. Muchas gracias, Tom Link to comment https://forums.phpfreaks.com/topic/127481-solved-chunk_split-and-php-and-smarty/ Share on other sites More sharing options...
DarkWater Posted October 8, 2008 Share Posted October 8, 2008 What are you trying to do with chunk_split()? Are you using it to just make the long URLs break up so they don't overflow the <td>? If you are...just use wordwrap. It's slightly better for this, and it's pretty easy to use in Smarty too. Link to comment https://forums.phpfreaks.com/topic/127481-solved-chunk_split-and-php-and-smarty/#findComment-659549 Share on other sites More sharing options...
FForce2195 Posted October 8, 2008 Author Share Posted October 8, 2008 What are you trying to do with chunk_split()? Are you using it to just make the long URLs break up so they don't overflow the <td>? Yes. I'll test and see whichever works better. Link to comment https://forums.phpfreaks.com/topic/127481-solved-chunk_split-and-php-and-smarty/#findComment-659584 Share on other sites More sharing options...
DarkWater Posted October 8, 2008 Share Posted October 8, 2008 You'd use it (in Smarty) like so: {$some_var|wordwrap:50:"<br />\n":true} Link to comment https://forums.phpfreaks.com/topic/127481-solved-chunk_split-and-php-and-smarty/#findComment-659585 Share on other sites More sharing options...
FForce2195 Posted October 8, 2008 Author Share Posted October 8, 2008 You'd use it (in Smarty) like so: {$some_var|wordwrap:50:"<br />\n":true} Whoa... You are quick. You must have years of experience in PHP. Actually, wordwrap probably won't do it because I'm dealing with wrong URLs. I'll test it, anyway. Thank you very much. Link to comment https://forums.phpfreaks.com/topic/127481-solved-chunk_split-and-php-and-smarty/#findComment-659590 Share on other sites More sharing options...
DarkWater Posted October 8, 2008 Share Posted October 8, 2008 If you put that true as the third parameter, it cuts it off at the exact amount of characters instead of breaking it up at the nearest word, so it should work fine for URLs. Edit: And I'm not gonna lie, I have a copy of the Smarty manual printed out in a binder on my bookshelf. Link to comment https://forums.phpfreaks.com/topic/127481-solved-chunk_split-and-php-and-smarty/#findComment-659593 Share on other sites More sharing options...
FForce2195 Posted October 8, 2008 Author Share Posted October 8, 2008 Actually, wordwrap works fine. You are a savior. Thanks a lot again. What a great place for PHP newbies... Link to comment https://forums.phpfreaks.com/topic/127481-solved-chunk_split-and-php-and-smarty/#findComment-659595 Share on other sites More sharing options...
DarkWater Posted October 8, 2008 Share Posted October 8, 2008 No problem. =P Link to comment https://forums.phpfreaks.com/topic/127481-solved-chunk_split-and-php-and-smarty/#findComment-659597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.