Jump to content

[SOLVED] Chunk_Split and PHP and Smarty


FForce2195

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.