Jump to content

[SOLVED] php limit


dezkit

Recommended Posts

is it possible so that if Team2 has a name of more than 4, so that it shows three dots "..."

 

<h2 class="matches"><span>Matches</span></h2>
<div class="cbox">
<div class="matches">
	<?
	$q = mysql_query("SELECT * FROM `matches` ORDER BY id DESC LIMIT 0,5");
	$matches = mysql_num_rows($q);
	if($matches > 0) {
	?>

	<table cellspacing="0" style="font-size: 10px;">
	<?
	$i = 0;
	while($r = mysql_fetch_array($q)) {
		$i += 1;
		$winner = split("-",$r['score']);
		if($winner[0] > $winner[1]) {
			$status = "<td class=\"win\">Win</td>";
		} else if($winner[0] < $winner[1]) {
			$status = "<td class=\"loss\">Loss</td>";
		} else {
			$status = "<td class=\"tie\">Tie</td>";
		}
		?>
		<tr class="row<?=($i&1)?>">
			<td><font style="font-size:9px; color: #888888;">vs</font> <?=$r['team2']?></td>
			<td class="score"><?=$r['score']?></td>
			<?=$status?>
		</tr>
	<? }
	?></table><?
	} else {

		echo "<p>We haven't played any matches yet!</p>";
	}
	?>
	<p><a href="index.php?p=matches">View all matches</a></p>

</div>
</div>

Link to comment
Share on other sites

One line...

 

echo (  strlen( $r['team2'] ) > 4 ? substr( $r['team2'], 0, 4 ).'...' : $r['team2']  );

 

Replace

<?=$r['team2']?>

 

With

<?php echo (  strlen( $r['team2'] ) > 4 ? substr( $r['team2'], 0, 4 ).'...' : $r['team2']  ); ?>

Link to comment
Share on other sites

Just to elaborate... using full tags isn't necessarily 'better.' Full tags are more compatible... as some server have short tags turned off.

 

If you want to make sure you script will work on ANY php build you execute it on, always use full tags (<?php #code# ?> )

 

If you only plan on executing the script on YOUR server, then short tags are fine and dandy and will save you a bit of time and disk space :)

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.