strlen and substr error.. i think Oo...

Started by Hyperion (noobKID), July 10, 2013, 04:07:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hyperion (noobKID)

maybe you could help with something else? Now we are at problems anyhow...

I'm trying to remake my own forum for my own source, and trying to COUNT my forums threads AND my forums postes...

trying to do it simple like so:

Function:
Code (php) Select

function get_row_count($table, $suffix = "")
{
if ($suffix)
{
$suffix = " $suffix";
}
($r = mysql_query("SELECT COUNT(*) FROM $table$suffix")) or die(mysql_error());
($a = mysql_fetch_row($r)) or die(mysql_error());
return $a[0];
}

Forum Code:
Code (php) Select

//Actual Forums Query...
$f_res = mysql_query("SELECT * FROM forums WHERE FK_fc_id = ".(int)$fc_array['fc_id']);
while($f_array = mysql_fetch_assoc($f_res))//f = forums
{
$threads = number_format(get_row_count("forums_threads"));
$posts = number_format(get_row_count("forums_post"));

$HTMLOUT .= "<div id='forums_div_wrapper'>";
$HTMLOUT .= "<table align='center' width='100%' border='0'>";
$HTMLOUT .= "<tr>";

$HTMLOUT .= "<td width='auto' style='min-width:150px;'>";
$HTMLOUT .= "--<a href='forums.php?action=list&fc_id=".(int)$f_array['FK_fc_id']."&f_id=".(int)$f_array['f_id']."'>".$f_array['f_name']."</a>";
$HTMLOUT .= "</td>";

$HTMLOUT .= "<td style='min-width:300px;width:500px;'>";
$HTMLOUT .= "nooby test...";

$HTMLOUT .= "<span style='float:right;'>";
$HTMLOUT .= "by Hyperion 1 day ago";
$HTMLOUT .= "</span>";
$HTMLOUT .= "</td>";

$HTMLOUT .= "<td style='min-width:50px;width:60px;text-align:right;'>";
$HTMLOUT .= "$threads";
$HTMLOUT .= "</td>";

$HTMLOUT .= "<td style='min-width:50px;width:60px;text-align:right;'>";
$HTMLOUT .= "$posts";
$HTMLOUT .= "</td>";

$HTMLOUT .= "</tr>";
$HTMLOUT .= "</table>";
$HTMLOUT .= "</div>";
}


it seems simple, but i only have 1 thread in 1 forum with 1 post in it, and it gives a 1 on all 3 forums, any idea what i am doing wrong here? Oo...

stoner


Hyperion (noobKID)

ohh, yeah... my bad x), anyhow, you were right, but i needed to put in else after if, else it would just take all the once with ... needed, and then the rest one more time x)...

-thanks x)

stoner

Should this line:
if(strlen($f_array['f_name'])<20)

Not be
if(strlen($f_array['f_name'])>20)
  as your wanting to shorted names over 20 characters.

Also below your code, you need code to output ones which are not caught by the if statement.

So something like this.

if(strlen($f_array['f_name'])>20)//If bigger than 20 letters...
{
$HTMLOUT .= "--<a href='forums.php?action=list&fc_id=".(int)$f_array['FK_fc_id']."&f_id=".(int)$f_array['f_id']."'>".substr($f_array['f_name'],0,15)."...</a>";
}
$HTMLOUT .= "--<a href='forums.php?action=list&fc_id=".(int)$f_array['FK_fc_id']."&f_id=".(int)$f_array['f_id']."'>".$f_array['f_name']."</a>";


Hyperion (noobKID)

Hey u-232.
I think i have done it right, and yet not... it is hard to explain, but this is my php code as a start:

Code (php) Select

if(strlen($f_array['f_name'])<20)//If bigger than 20 letters...
{
$HTMLOUT .= "--<a href='forums.php?action=list&fc_id=".(int)$f_array['FK_fc_id']."&f_id=".(int)$f_array['f_id']."'>".substr($f_array['f_name'],0,15)."...</a>";
}


so, what i am trying to do here (wish to do is a proper word i suppose), is to replace the word(s) with 15 letters, and 3 simple (dot -> ...) sign's, if the word is over 20 letters long.

BUT!

i have currently 3 forums listed, AND 2 out of 3 are coming out with the dots, the last one are not coming out, BUT the div/table for the number 3 ARE coming out, just without the title/head title, if you understand what i am saying.

Anyone knows what i am doing wrong here 'Oo...

-THANKS! :)

[attachment deleted by admin]