Jump to content

[SOLVED] What code do i want (conceptually) to solve this issue [img included]


Lyricsride

Recommended Posts

hey folks,

I have would like to implement a simple blurb sytstem. The only part confusing me is how i should have php detect when the box of news has been filled.

http://codes.concordia.ca/help.png

the image basically explains the concept.

What php code/concepts/tutorials should i be looking for?

Thanks for pointing me in the right direction!
Link to comment
Share on other sites

Assuming you have a mysql database, and know mysql, here is how I would approach it:

[code]
<?php
$sql = mysql_query("SELECT * FROM table_name order by id DESC LIMIT 5")or die(mysql_error());
while($row = mysql_fetch_array($sql){
echo '<p>'.$row['date'].'<br>';
echo str$row['content'].'</p>';
}
echo'<a href="display_all.php">Display all</a>';
?>
[/code]
Link to comment
Share on other sites

Thanks a lot for the reply Little Guy. I considered something similar to your suggestion, but the problem is that 5 posts (LIMIT 5) may not fit into the box. If one of those 5 "blurbs" is considerably long, it would push others outside the box. On the flip side, if all 5 "blurbs" are considerably short, they won't fill the box.

I do not want to use scrollbars either. Somehow PHP needs to dynamically detect how many "Blurbs" can really fit into the box, based on the size of those blurbs versus the size of the box.

Am i making sense?
Link to comment
Share on other sites

The box will be a set size. I guess that helps a little, i'll be able to tell PHP exactly what size it should be limited to. At least i think that should make it easier.... ha.

The current height in pixles is 285px. So that's the max size. I'm going to be using MySQL for databasing. I have access to GD 2.x.

Big thanks for the help. I'll try to reply faster!
:)

edit:
the width is also statically set at 355px. It's probably a given but just in case...
Link to comment
Share on other sites

Thanks fert, that's something else i was thinking. The annoying problem with that is, there could be blurbs as little as one line. Each blurb would require margins on the top and bottom, of course. That means the worst-case scenario the box must be able to handle is the amount of characters that would be outputted if each post was only one line long. The chances of this are slim but can't be ignored to function properly. It ends up being a very crude and static measurement.

I'm wondering if there can be a way to solve the problem using the GD library - albeit a convoluted one....

Link to comment
Share on other sites

After several forums and people suggesting my idea was a little "out there" i finally got it (with a few suggestions from the OZZU forums)

thanks for all your help guys.

[code]$boxHeight = 247;
while($stuffResult = mysqli_fetch_assoc($stuffGet))
{
//(A) The # of characters in the entire blurb
$charCount = strlen($stuffResult['text']);

//(B) Divide (A) by 48, this tells us how many lines there are
$lineCount = $charCount / 48;

//(C) Round (B) up to get the actual # of lines (can't be a float!)
$lineCount = ceil($lineCount);

//(D) Multiply (C) by 13 b/c each line is 13px high
$lineHeight = ($lineCount * 13);

//(E) Substract the total box height by the line height of the blurb, the while loop slowly eats away at the box space until it is full!
$boxHeight = $boxHeight - $lineHeight;

//the the blurb is NOT the last one, take an additonal 26px off the box height, to account for spacing the posts apart
if($boxHeight > 25)
{
//subtract 26px b/c this blurb has space at the bottom
$boxHeight = ($boxHeight - 26);
}

if($boxHeight > 0)
{
//echo 'box px: '.$boxHeight.'<br />';
//echo 'blurb px'.$lineHeight.'<br />';
//echo 'blurb line'.$lineCount;
//the actual blurb being displayed to the user
echo '<div style="float:left;">'.$stuffResult['date'].'</div>
<p style="margin-left:119px;margin-bottom:26px;">'.$stuffResult['text'].'</p>
';
}
}[/code]
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.