CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Truncate text - works with one problem

Print topic Send  topic

Author Message
Jerry
Posted: 01/12/2004, 12:55 PM

CCS 2, php, MySql, Windows Server 2003 web edition. (code built on xp
machine)
I am having a problem with a truncate function.

The code is listed below.

My problem:
On my index page I have it call a table called "news". However I need it to
limit the output to "x" number of letters. (see function code below) I
call the first 3 rows in this table. Inside the table are the fields
"news_id, date, title, news". In the grid on the index page I call all of
these items. All show correctly except for the "news" field, which is where
I have my truncate function. It does its job great, except it shows the
same record in all three rows of the grid. The ID (which I changed to a
link to view the full article), title, and date all show the correct
information, but the news always shows what is in the first "news" row of
the database.

Anyone have any ideas? I have tried everything I could think of. Including
moving the function to cover the whole grid rather then just the "news"
field. The function currently runs "before show" in the "news" label. This
function is on the page once in two separate grids.


----------------------------------------------------------------------------
-------------------
Here is the function:

in common.php:
function smart_truncate ($str2cut,$trig_value=200")
{$newstr="";

if(strlen($str2cut)<=$trig_val)
return $str2cut;

$newlen=strrpos(substr($str2cut,0,$trig_val),"");

$newstr=substr($str2cut,0,$newlen);
else
$newstr=substr($str2cut,0,@trig_val);

return $newstr"...<i>Click here to view full article</i>";
}

***NOTE: for some reason in that last line <i> is the only HTML tag I can
get to work.. I would like to change the color on this too, but for some
reason it wont let me.. any ideas why??? ***
----------------------------------------------------------------------------
--------------------

This part goes on the page in the before show

Global $index_box_4
$full_story=CCDlookup("info","index_box_4", "id>0",
$DBConnection1=new clsDBConnection1);

$snip_story = smart_truncate($full_story);
$index_box_4 -->info-->SetValue($snip_story);

----------------------------------------------------------------------------
-------------------------

Thanks for any help,
Jerry


Jerry
Posted: 01/12/2004, 6:15 PM

The truncate function I got from the codecharge studio news group aprox 4-5
months ago. I had quite a few people help me with it, and this is how it
ended up. I am far from being advanced enough to do this on my own! I'd
love to take the credit for it, but I cant. It does work wonderfully except
for my one minor problem.

This is close to how I have my link set up. I just changed the news_id from
a label to a link, and send that to another page that calls the full
article. Works great.

I am on the way out of the office for the day, but I will try your
suggestion in the morning. Thanks a million for the help. I'll let you
know how it worked out.
Jerry




"Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
news:btvch0$ith$1@news.codecharge.com...
> Jerry,
>
> Mind if I ask where did you get that truncate function? It is incredibly
> similar to one I created for one of my clients... including the function
> name, the variables and the logic... wow!
>
> Anyway... You can try to modify the field directly on the grid. Just setup
> your grid to display the full story, then modify the output in the
> BeforeShow event of the info field. For example, let's say that your
grid's
> name is index_box_4 and the story field is info, then do somethig like
this:
>
> //index_box_4_info_BeforeShow @16-3860B259
> function index_box_4_info_BeforeShow()
> {
> $index_box_4_info_BeforeShow = true;
> //End index_box_4_info_BeforeShow
>
> //Custom Code @29-70651C89
> // -------------------------
> global $index_box_4;
>
> $full_story=$index_box_4->info->GetValue();
> $index_box_4->info->SetValue(smart_truncate($full_story));
>
> // -------------------------
> //End Custom Code
>
> //Close index_box_4_info_BeforeShow @16-CD9AD5A1
> return $index_box_4_info_BeforeShow;
> }
> //End Close index_box_4_info_BeforeShow
>
>
> For the hyperlink to the story, you should add an actual Link control
under
> the story field. In this case, the HTML template should look something
like:
> {info}<br><a href="{info_link_Src}">{info_link}</a>
>
> Regards,
>
> Sixto
>
>
> "Jerry" <jerryb@pccms.com> wrote in message
>news:btuqji$mtr$1@news.codecharge.com...
> > CCS 2, php, MySql, Windows Server 2003 web edition. (code built on xp
> > machine)
> > I am having a problem with a truncate function.
> >
> > The code is listed below.
> >
> > My problem:
> > On my index page I have it call a table called "news". However I need
it
> to
> > limit the output to "x" number of letters. (see function code below) I
> > call the first 3 rows in this table. Inside the table are the fields
> > "news_id, date, title, news". In the grid on the index page I call all
of
> > these items. All show correctly except for the "news" field, which is
> where
> > I have my truncate function. It does its job great, except it shows the
> > same record in all three rows of the grid. The ID (which I changed to a
> > link to view the full article), title, and date all show the correct
> > information, but the news always shows what is in the first "news" row
of
> > the database.
> >
> > Anyone have any ideas? I have tried everything I could think of.
> Including
> > moving the function to cover the whole grid rather then just the "news"
> > field. The function currently runs "before show" in the "news" label.
> This
> > function is on the page once in two separate grids.
> >
> >
>
> --------------------------------------------------------------------------
> --
> > -------------------
> > Here is the function:
> >
> > in common.php:
> > function smart_truncate ($str2cut,$trig_value=200")
> > {$newstr="";
> >
> > if(strlen($str2cut)<=$trig_val)
> > return $str2cut;
> >
> > $newlen=strrpos(substr($str2cut,0,$trig_val),"");
> >
> > $newstr=substr($str2cut,0,$newlen);
> > else
> > $newstr=substr($str2cut,0,@trig_val);
> >
> > return $newstr"...<i>Click here to view full article</i>";
> > }
> >
> > ***NOTE: for some reason in that last line <i> is the only HTML tag I
can
> > get to work.. I would like to change the color on this too, but for
some
> > reason it wont let me.. any ideas why??? ***
>
> --------------------------------------------------------------------------
> --
> > --------------------
> >
> > This part goes on the page in the before show
> >
> > Global $index_box_4
> > $full_story=CCDlookup("info","index_box_4", "id>0",
> > $DBConnection1=new clsDBConnection1);
> >
> > $snip_story = smart_truncate($full_story);
> > $index_box_4 -->info-->SetValue($snip_story);
> >
>
> --------------------------------------------------------------------------
> --
> > -------------------------
> >
> > Thanks for any help,
> > Jerry
> >
> >
> >
>
>

Sixto Luis Santos
Posted: 01/12/2004, 8:01 PM

Jerry,

Mind if I ask where did you get that truncate function? It is incredibly
similar to one I created for one of my clients... including the function
name, the variables and the logic... wow!

Anyway... You can try to modify the field directly on the grid. Just setup
your grid to display the full story, then modify the output in the
BeforeShow event of the info field. For example, let's say that your grid's
name is index_box_4 and the story field is info, then do somethig like this:

//index_box_4_info_BeforeShow @16-3860B259
function index_box_4_info_BeforeShow()
{
$index_box_4_info_BeforeShow = true;
//End index_box_4_info_BeforeShow

//Custom Code @29-70651C89
// -------------------------
global $index_box_4;

$full_story=$index_box_4->info->GetValue();
$index_box_4->info->SetValue(smart_truncate($full_story));

// -------------------------
//End Custom Code

//Close index_box_4_info_BeforeShow @16-CD9AD5A1
return $index_box_4_info_BeforeShow;
}
//End Close index_box_4_info_BeforeShow


For the hyperlink to the story, you should add an actual Link control under
the story field. In this case, the HTML template should look something like:
{info}<br><a href="{info_link_Src}">{info_link}</a>

Regards,

Sixto


"Jerry" <jerryb@pccms.com> wrote in message
news:btuqji$mtr$1@news.codecharge.com...
> CCS 2, php, MySql, Windows Server 2003 web edition. (code built on xp
> machine)
> I am having a problem with a truncate function.
>
> The code is listed below.
>
> My problem:
> On my index page I have it call a table called "news". However I need it
to
> limit the output to "x" number of letters. (see function code below) I
> call the first 3 rows in this table. Inside the table are the fields
> "news_id, date, title, news". In the grid on the index page I call all of
> these items. All show correctly except for the "news" field, which is
where
> I have my truncate function. It does its job great, except it shows the
> same record in all three rows of the grid. The ID (which I changed to a
> link to view the full article), title, and date all show the correct
> information, but the news always shows what is in the first "news" row of
> the database.
>
> Anyone have any ideas? I have tried everything I could think of.
Including
> moving the function to cover the whole grid rather then just the "news"
> field. The function currently runs "before show" in the "news" label.
This
> function is on the page once in two separate grids.
>
>
> --------------------------------------------------------------------------
--
> -------------------
> Here is the function:
>
> in common.php:
> function smart_truncate ($str2cut,$trig_value=200")
> {$newstr="";
>
> if(strlen($str2cut)<=$trig_val)
> return $str2cut;
>
> $newlen=strrpos(substr($str2cut,0,$trig_val),"");
>
> $newstr=substr($str2cut,0,$newlen);
> else
> $newstr=substr($str2cut,0,@trig_val);
>
> return $newstr"...<i>Click here to view full article</i>";
> }
>
> ***NOTE: for some reason in that last line <i> is the only HTML tag I can
> get to work.. I would like to change the color on this too, but for some
> reason it wont let me.. any ideas why??? ***
> --------------------------------------------------------------------------
--
> --------------------
>
> This part goes on the page in the before show
>
> Global $index_box_4
> $full_story=CCDlookup("info","index_box_4", "id>0",
> $DBConnection1=new clsDBConnection1);
>
> $snip_story = smart_truncate($full_story);
> $index_box_4 -->info-->SetValue($snip_story);
>
> --------------------------------------------------------------------------
--
> -------------------------
>
> Thanks for any help,
> Jerry
>
>
>

jstuart


Posts: 26
Posted: 01/13/2004, 8:21 AM

Jerry, try this:

  
Global $index_box_4;  
$newdb = new clsDBConnection1();  
  
$full_story=CCDlookup("info","index_box_4", "id>0", $newdb);  
   
$snip_story = smart_truncate($full_story);  
$index_box_4->info->SetValue($snip_story);  
unset($newdb);  
 

Note: I did the following
A) Created the db connection OUTSIDE of the CCDLookup. I'm hesitant to say that how you did it is ok. IE you may be leaking memory there. :(
B) I am assuming that you made a typo in the $index_box_4 line. IE that it should have been -> and not -->. If that is the actual code, then your problem is cause of the -->. :) It's just one '-' (dash). :)
_________________
Jeff Stuart
jstuart@computer-city.net
View profile  Send private message
Jerry
Posted: 01/14/2004, 9:44 AM

Sorry, I didn't read this close enough. But this is the way I already have
it. I have the function set to run just in the field, not the whole grid.

But when I do this it gives me the same info for the "info" field in all
instances of the grid.

Any ideas?
Thanks again,
Jerry


"Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
news:btvch0$ith$1@news.codecharge.com...
> Jerry,
>
> Mind if I ask where did you get that truncate function? It is incredibly
> similar to one I created for one of my clients... including the function
> name, the variables and the logic... wow!
>
> Anyway... You can try to modify the field directly on the grid. Just setup
> your grid to display the full story, then modify the output in the
> BeforeShow event of the info field. For example, let's say that your
grid's
> name is index_box_4 and the story field is info, then do somethig like
this:
>
> //index_box_4_info_BeforeShow @16-3860B259
> function index_box_4_info_BeforeShow()
> {
> $index_box_4_info_BeforeShow = true;
> //End index_box_4_info_BeforeShow
>
> //Custom Code @29-70651C89
> // -------------------------
> global $index_box_4;
>
> $full_story=$index_box_4->info->GetValue();
> $index_box_4->info->SetValue(smart_truncate($full_story));
>
> // -------------------------
> //End Custom Code
>
> //Close index_box_4_info_BeforeShow @16-CD9AD5A1
> return $index_box_4_info_BeforeShow;
> }
> //End Close index_box_4_info_BeforeShow
>
>
> For the hyperlink to the story, you should add an actual Link control
under
> the story field. In this case, the HTML template should look something
like:
> {info}<br><a href="{info_link_Src}">{info_link}</a>
>
> Regards,
>
> Sixto
>
>
> "Jerry" <jerryb@pccms.com> wrote in message
>news:btuqji$mtr$1@news.codecharge.com...
> > CCS 2, php, MySql, Windows Server 2003 web edition. (code built on xp
> > machine)
> > I am having a problem with a truncate function.
> >
> > The code is listed below.
> >
> > My problem:
> > On my index page I have it call a table called "news". However I need
it
> to
> > limit the output to "x" number of letters. (see function code below) I
> > call the first 3 rows in this table. Inside the table are the fields
> > "news_id, date, title, news". In the grid on the index page I call all
of
> > these items. All show correctly except for the "news" field, which is
> where
> > I have my truncate function. It does its job great, except it shows the
> > same record in all three rows of the grid. The ID (which I changed to a
> > link to view the full article), title, and date all show the correct
> > information, but the news always shows what is in the first "news" row
of
> > the database.
> >
> > Anyone have any ideas? I have tried everything I could think of.
> Including
> > moving the function to cover the whole grid rather then just the "news"
> > field. The function currently runs "before show" in the "news" label.
> This
> > function is on the page once in two separate grids.
> >
> >
>
> --------------------------------------------------------------------------
> --
> > -------------------
> > Here is the function:
> >
> > in common.php:
> > function smart_truncate ($str2cut,$trig_value=200")
> > {$newstr="";
> >
> > if(strlen($str2cut)<=$trig_val)
> > return $str2cut;
> >
> > $newlen=strrpos(substr($str2cut,0,$trig_val),"");
> >
> > $newstr=substr($str2cut,0,$newlen);
> > else
> > $newstr=substr($str2cut,0,@trig_val);
> >
> > return $newstr"...<i>Click here to view full article</i>";
> > }
> >
> > ***NOTE: for some reason in that last line <i> is the only HTML tag I
can
> > get to work.. I would like to change the color on this too, but for
some
> > reason it wont let me.. any ideas why??? ***
>
> --------------------------------------------------------------------------
> --
> > --------------------
> >
> > This part goes on the page in the before show
> >
> > Global $index_box_4
> > $full_story=CCDlookup("info","index_box_4", "id>0",
> > $DBConnection1=new clsDBConnection1);
> >
> > $snip_story = smart_truncate($full_story);
> > $index_box_4 -->info-->SetValue($snip_story);
> >
>
> --------------------------------------------------------------------------
> --
> > -------------------------
> >
> > Thanks for any help,
> > Jerry
> >
> >
> >
>
>

Sixto Luis Santos
Posted: 01/14/2004, 12:43 PM

Look again. I'm not doing a second lookup to get the information. Why are
you using a DLookup and not assigning the field directly on the grid... ?

Anyway, looking at your CCDLookup line, I notice that your where condition
is "id>0" so you'll always end up with the first record with an id > 0, most
probably, the first stored record of the table index_box_4. You must set
your where condition to exactly the id of the record you want to fetch up
(e.g. "id=40").

In your grid, is the field where you placed your event code an id? Or is it
the full story?

Regards,

Sixto

"Jerry" <jerryb@pccms.com> wrote in message
news:bu3nil$hcg$1@news.codecharge.com...
> Sorry, I didn't read this close enough. But this is the way I already
have
> it. I have the function set to run just in the field, not the whole grid.
>
> But when I do this it gives me the same info for the "info" field in all
> instances of the grid.
>
> Any ideas?
> Thanks again,
> Jerry
>
>
> "Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
>news:btvch0$ith$1@news.codecharge.com...
> > Jerry,
> >
> > Mind if I ask where did you get that truncate function? It is incredibly
> > similar to one I created for one of my clients... including the function
> > name, the variables and the logic... wow!
> >
> > Anyway... You can try to modify the field directly on the grid. Just
setup
> > your grid to display the full story, then modify the output in the
> > BeforeShow event of the info field. For example, let's say that your
> grid's
> > name is index_box_4 and the story field is info, then do somethig like
> this:
> >
> > //index_box_4_info_BeforeShow @16-3860B259
> > function index_box_4_info_BeforeShow()
> > {
> > $index_box_4_info_BeforeShow = true;
> > //End index_box_4_info_BeforeShow
> >
> > //Custom Code @29-70651C89
> > // -------------------------
> > global $index_box_4;
> >
> > $full_story=$index_box_4->info->GetValue();
> > $index_box_4->info->SetValue(smart_truncate($full_story));
> >
> > // -------------------------
> > //End Custom Code
> >
> > //Close index_box_4_info_BeforeShow @16-CD9AD5A1
> > return $index_box_4_info_BeforeShow;
> > }
> > //End Close index_box_4_info_BeforeShow
> >
> >
> > For the hyperlink to the story, you should add an actual Link control
> under
> > the story field. In this case, the HTML template should look something
> like:
> > {info}<br><a href="{info_link_Src}">{info_link}</a>
> >
> > Regards,
> >
> > Sixto
> >
> >
> > "Jerry" <jerryb@pccms.com> wrote in message
> >news:btuqji$mtr$1@news.codecharge.com...
> > > CCS 2, php, MySql, Windows Server 2003 web edition. (code built on xp
> > > machine)
> > > I am having a problem with a truncate function.
> > >
> > > The code is listed below.
> > >
> > > My problem:
> > > On my index page I have it call a table called "news". However I need
> it
> > to
> > > limit the output to "x" number of letters. (see function code below)
I
> > > call the first 3 rows in this table. Inside the table are the fields
> > > "news_id, date, title, news". In the grid on the index page I call
all
> of
> > > these items. All show correctly except for the "news" field, which is
> > where
> > > I have my truncate function. It does its job great, except it shows
the
> > > same record in all three rows of the grid. The ID (which I changed to
a
> > > link to view the full article), title, and date all show the correct
> > > information, but the news always shows what is in the first "news" row
> of
> > > the database.
> > >
> > > Anyone have any ideas? I have tried everything I could think of.
> > Including
> > > moving the function to cover the whole grid rather then just the
"news"
> > > field. The function currently runs "before show" in the "news" label.
> > This
> > > function is on the page once in two separate grids.
> > >
> > >
> >
>
> --------------------------------------------------------------------------
> > --
> > > -------------------
> > > Here is the function:
> > >
> > > in common.php:
> > > function smart_truncate ($str2cut,$trig_value=200")
> > > {$newstr="";
> > >
> > > if(strlen($str2cut)<=$trig_val)
> > > return $str2cut;
> > >
> > > $newlen=strrpos(substr($str2cut,0,$trig_val),"");
> > >
> > > $newstr=substr($str2cut,0,$newlen);
> > > else
> > > $newstr=substr($str2cut,0,@trig_val);
> > >
> > > return $newstr"...<i>Click here to view full article</i>";
> > > }
> > >
> > > ***NOTE: for some reason in that last line <i> is the only HTML tag I
> can
> > > get to work.. I would like to change the color on this too, but for
> some
> > > reason it wont let me.. any ideas why??? ***
> >
>
> --------------------------------------------------------------------------
> > --
> > > --------------------
> > >
> > > This part goes on the page in the before show
> > >
> > > Global $index_box_4
> > > $full_story=CCDlookup("info","index_box_4", "id>0",
> > > $DBConnection1=new clsDBConnection1);
> > >
> > > $snip_story = smart_truncate($full_story);
> > > $index_box_4 -->info-->SetValue($snip_story);
> > >
> >
>
> --------------------------------------------------------------------------
> > --
> > > -------------------------
> > >
> > > Thanks for any help,
> > > Jerry
> > >
> > >
> > >
> >
> >
>
>

Jerry
Posted: 01/19/2004, 2:14 PM

the even code is the id. Trying to remember why I used id>0 I know there
was a reason. What I need to happen is that it shows the newest records. I
think when I was using the id>0 I was just getting one record. Now I am
getting 3. But that does make sense to why I get the first record every
time. Banging my head on the monitor now.

So how would I change that to say get the newest records?

Thanks
Jerry

"Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
news:bu3qvi$pj9$1@news.codecharge.com...
> Look again. I'm not doing a second lookup to get the information. Why are
> you using a DLookup and not assigning the field directly on the grid... ?
>
> Anyway, looking at your CCDLookup line, I notice that your where condition
> is "id>0" so you'll always end up with the first record with an id > 0,
most
> probably, the first stored record of the table index_box_4. You must set
> your where condition to exactly the id of the record you want to fetch up
> (e.g. "id=40").
>
> In your grid, is the field where you placed your event code an id? Or is
it
> the full story?
>
> Regards,
>
> Sixto
>
> "Jerry" <jerryb@pccms.com> wrote in message
>news:bu3nil$hcg$1@news.codecharge.com...
> > Sorry, I didn't read this close enough. But this is the way I already
> have
> > it. I have the function set to run just in the field, not the whole
grid.
> >
> > But when I do this it gives me the same info for the "info" field in all
> > instances of the grid.
> >
> > Any ideas?
> > Thanks again,
> > Jerry
> >
> >
> > "Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
> >news:btvch0$ith$1@news.codecharge.com...
> > > Jerry,
> > >
> > > Mind if I ask where did you get that truncate function? It is
incredibly
> > > similar to one I created for one of my clients... including the
function
> > > name, the variables and the logic... wow!
> > >
> > > Anyway... You can try to modify the field directly on the grid. Just
> setup
> > > your grid to display the full story, then modify the output in the
> > > BeforeShow event of the info field. For example, let's say that your
> > grid's
> > > name is index_box_4 and the story field is info, then do somethig like
> > this:
> > >
> > > //index_box_4_info_BeforeShow @16-3860B259
> > > function index_box_4_info_BeforeShow()
> > > {
> > > $index_box_4_info_BeforeShow = true;
> > > //End index_box_4_info_BeforeShow
> > >
> > > //Custom Code @29-70651C89
> > > // -------------------------
> > > global $index_box_4;
> > >
> > > $full_story=$index_box_4->info->GetValue();
> > > $index_box_4->info->SetValue(smart_truncate($full_story));
> > >
> > > // -------------------------
> > > //End Custom Code
> > >
> > > //Close index_box_4_info_BeforeShow @16-CD9AD5A1
> > > return $index_box_4_info_BeforeShow;
> > > }
> > > //End Close index_box_4_info_BeforeShow
> > >
> > >
> > > For the hyperlink to the story, you should add an actual Link control
> > under
> > > the story field. In this case, the HTML template should look something
> > like:
> > > {info}<br><a href="{info_link_Src}">{info_link}</a>
> > >
> > > Regards,
> > >
> > > Sixto
> > >
> > >
> > > "Jerry" <jerryb@pccms.com> wrote in message
> > >news:btuqji$mtr$1@news.codecharge.com...
> > > > CCS 2, php, MySql, Windows Server 2003 web edition. (code built on
xp
> > > > machine)
> > > > I am having a problem with a truncate function.
> > > >
> > > > The code is listed below.
> > > >
> > > > My problem:
> > > > On my index page I have it call a table called "news". However I
need
> > it
> > > to
> > > > limit the output to "x" number of letters. (see function code
below)
> I
> > > > call the first 3 rows in this table. Inside the table are the
fields
> > > > "news_id, date, title, news". In the grid on the index page I call
> all
> > of
> > > > these items. All show correctly except for the "news" field, which
is
> > > where
> > > > I have my truncate function. It does its job great, except it shows
> the
> > > > same record in all three rows of the grid. The ID (which I changed
to
> a
> > > > link to view the full article), title, and date all show the correct
> > > > information, but the news always shows what is in the first "news"
row
> > of
> > > > the database.
> > > >
> > > > Anyone have any ideas? I have tried everything I could think of.
> > > Including
> > > > moving the function to cover the whole grid rather then just the
> "news"
> > > > field. The function currently runs "before show" in the "news"
label.
> > > This
> > > > function is on the page once in two separate grids.
> > > >
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > --
> > > > -------------------
> > > > Here is the function:
> > > >
> > > > in common.php:
> > > > function smart_truncate ($str2cut,$trig_value=200")
> > > > {$newstr="";
> > > >
> > > > if(strlen($str2cut)<=$trig_val)
> > > > return $str2cut;
> > > >
> > > > $newlen=strrpos(substr($str2cut,0,$trig_val),"");
> > > >
> > > > $newstr=substr($str2cut,0,$newlen);
> > > > else
> > > > $newstr=substr($str2cut,0,@trig_val);
> > > >
> > > > return $newstr"...<i>Click here to view full article</i>";
> > > > }
> > > >
> > > > ***NOTE: for some reason in that last line <i> is the only HTML tag
I
> > can
> > > > get to work.. I would like to change the color on this too, but for
> > some
> > > > reason it wont let me.. any ideas why??? ***
> > >
> >
>
> --------------------------------------------------------------------------
> > > --
> > > > --------------------
> > > >
> > > > This part goes on the page in the before show
> > > >
> > > > Global $index_box_4
> > > > $full_story=CCDlookup("info","index_box_4", "id>0",
> > > > $DBConnection1=new clsDBConnection1);
> > > >
> > > > $snip_story = smart_truncate($full_story);
> > > > $index_box_4 -->info-->SetValue($snip_story);
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > --
> > > > -------------------------
> > > >
> > > > Thanks for any help,
> > > > Jerry
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>

Sixto Luis Santos
Posted: 01/19/2004, 4:06 PM

For that you would need an ORDER BY in your query. Do you have a date field
in your table?

Anyway, consider using CCGetDBValue instead of CCDLookUp. With CCGetDBValue
you specify a complete query and the database.
In other words, replace this:
$full_story=CCDlookup("info","index_box_4", "id>0",$DBConnection1=new
clsDBConnection1);
With:
$full_story=CCGetDBValue("SELECT info FROM index_box_4 ORDER BY date_field
DESC LIMIT 1",new clsDBConnection1);
or, if you don't have a date field, use the id:
$full_story=CCGetDBValue("SELECT info FROM index_box_4 ORDER BY id DESC
LIMIT 1",new clsDBConnection1);


The key word there is DESC, that would sort the records in descending order,
putting the record with the latest date (or highest id) on the top.

Regards,

Sixto


"Jerry" <jerryb@pccms.com> wrote in message
news:buhkrs$eah$1@news.codecharge.com...
> the even code is the id. Trying to remember why I used id>0 I know there
> was a reason. What I need to happen is that it shows the newest records.
I
> think when I was using the id>0 I was just getting one record. Now I am
> getting 3. But that does make sense to why I get the first record every
> time. Banging my head on the monitor now.
>
> So how would I change that to say get the newest records?
>
> Thanks
> Jerry
>
> "Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
>news:bu3qvi$pj9$1@news.codecharge.com...
> > Look again. I'm not doing a second lookup to get the information. Why
are
> > you using a DLookup and not assigning the field directly on the grid...
?
> >
> > Anyway, looking at your CCDLookup line, I notice that your where
condition
> > is "id>0" so you'll always end up with the first record with an id > 0,
> most
> > probably, the first stored record of the table index_box_4. You must set
> > your where condition to exactly the id of the record you want to fetch
up
> > (e.g. "id=40").
> >
> > In your grid, is the field where you placed your event code an id? Or is
> it
> > the full story?
> >
> > Regards,
> >
> > Sixto
> >
> > "Jerry" <jerryb@pccms.com> wrote in message
> >news:bu3nil$hcg$1@news.codecharge.com...
> > > Sorry, I didn't read this close enough. But this is the way I already
> > have
> > > it. I have the function set to run just in the field, not the whole
> grid.
> > >
> > > But when I do this it gives me the same info for the "info" field in
all
> > > instances of the grid.
> > >
> > > Any ideas?
> > > Thanks again,
> > > Jerry
> > >
> > >
> > > "Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
> > >news:btvch0$ith$1@news.codecharge.com...
> > > > Jerry,
> > > >
> > > > Mind if I ask where did you get that truncate function? It is
> incredibly
> > > > similar to one I created for one of my clients... including the
> function
> > > > name, the variables and the logic... wow!
> > > >
> > > > Anyway... You can try to modify the field directly on the grid. Just
> > setup
> > > > your grid to display the full story, then modify the output in the
> > > > BeforeShow event of the info field. For example, let's say that your
> > > grid's
> > > > name is index_box_4 and the story field is info, then do somethig
like
> > > this:
> > > >
> > > > //index_box_4_info_BeforeShow @16-3860B259
> > > > function index_box_4_info_BeforeShow()
> > > > {
> > > > $index_box_4_info_BeforeShow = true;
> > > > //End index_box_4_info_BeforeShow
> > > >
> > > > //Custom Code @29-70651C89
> > > > // -------------------------
> > > > global $index_box_4;
> > > >
> > > > $full_story=$index_box_4->info->GetValue();
> > > > $index_box_4->info->SetValue(smart_truncate($full_story));
> > > >
> > > > // -------------------------
> > > > //End Custom Code
> > > >
> > > > //Close index_box_4_info_BeforeShow @16-CD9AD5A1
> > > > return $index_box_4_info_BeforeShow;
> > > > }
> > > > //End Close index_box_4_info_BeforeShow
> > > >
> > > >
> > > > For the hyperlink to the story, you should add an actual Link
control
> > > under
> > > > the story field. In this case, the HTML template should look
something
> > > like:
> > > > {info}<br><a href="{info_link_Src}">{info_link}</a>
> > > >
> > > > Regards,
> > > >
> > > > Sixto
> > > >
> > > >
> > > > "Jerry" <jerryb@pccms.com> wrote in message
> > > >news:btuqji$mtr$1@news.codecharge.com...
> > > > > CCS 2, php, MySql, Windows Server 2003 web edition. (code built on
> xp
> > > > > machine)
> > > > > I am having a problem with a truncate function.
> > > > >
> > > > > The code is listed below.
> > > > >
> > > > > My problem:
> > > > > On my index page I have it call a table called "news". However I
> need
> > > it
> > > > to
> > > > > limit the output to "x" number of letters. (see function code
> below)
> > I
> > > > > call the first 3 rows in this table. Inside the table are the
> fields
> > > > > "news_id, date, title, news". In the grid on the index page I
call
> > all
> > > of
> > > > > these items. All show correctly except for the "news" field,
which
> is
> > > > where
> > > > > I have my truncate function. It does its job great, except it
shows
> > the
> > > > > same record in all three rows of the grid. The ID (which I
changed
> to
> > a
> > > > > link to view the full article), title, and date all show the
correct
> > > > > information, but the news always shows what is in the first "news"
> row
> > > of
> > > > > the database.
> > > > >
> > > > > Anyone have any ideas? I have tried everything I could think of.
> > > > Including
> > > > > moving the function to cover the whole grid rather then just the
> > "news"
> > > > > field. The function currently runs "before show" in the "news"
> label.
> > > > This
> > > > > function is on the page once in two separate grids.
> > > > >
> > > > >
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > > --
> > > > > -------------------
> > > > > Here is the function:
> > > > >
> > > > > in common.php:
> > > > > function smart_truncate ($str2cut,$trig_value=200")
> > > > > {$newstr="";
> > > > >
> > > > > if(strlen($str2cut)<=$trig_val)
> > > > > return $str2cut;
> > > > >
> > > > > $newlen=strrpos(substr($str2cut,0,$trig_val),"");
> > > > >
> > > > > $newstr=substr($str2cut,0,$newlen);
> > > > > else
> > > > > $newstr=substr($str2cut,0,@trig_val);
> > > > >
> > > > > return $newstr"...<i>Click here to view full article</i>";
> > > > > }
> > > > >
> > > > > ***NOTE: for some reason in that last line <i> is the only HTML
tag
> I
> > > can
> > > > > get to work.. I would like to change the color on this too, but
for
> > > some
> > > > > reason it wont let me.. any ideas why??? ***
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > > --
> > > > > --------------------
> > > > >
> > > > > This part goes on the page in the before show
> > > > >
> > > > > Global $index_box_4
> > > > > $full_story=CCDlookup("info","index_box_4", "id>0",
> > > > > $DBConnection1=new clsDBConnection1);
> > > > >
> > > > > $snip_story = smart_truncate($full_story);
> > > > > $index_box_4 -->info-->SetValue($snip_story);
> > > > >
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > > --
> > > > > -------------------------
> > > > >
> > > > > Thanks for any help,
> > > > > Jerry
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>

Jerry
Posted: 01/20/2004, 7:10 AM

When I try the code you suggest, looks like this:

global $news;
$full_story=CCGetDBValue("SELECT news FROM news ORDER BY news_id DESC
LIMIT 1",new clsDBKGBN);
$snip_story=smart_truncate($full_story);
$news->news->SetValue($snip_story);

(Yes this is a different DB then from what I talked about in the beginning)

When I put the code in the before show for the whole grid, I get all of
the correct data, but the truncate function does not work, when I put it in
the before show of the news field, I get truncated, but the same problem as
before, it always shows the same "news" in all 3 records. I do have a date
field in the table, but I prefer to use the news_id for sorting. I don't
want to rely on the people entering the data to enter the correct date if I
can avoid it.

I don't know about CCCGetDBValue, but I did try to change it around a
little, but didn't have any luck.

Have you been able to get this code to work?

Thanks a million for the help,
Jerry


"Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
news:buhrea$umg$1@news.codecharge.com...
> For that you would need an ORDER BY in your query. Do you have a date
field
> in your table?
>
> Anyway, consider using CCGetDBValue instead of CCDLookUp. With
CCGetDBValue
> you specify a complete query and the database.
> In other words, replace this:
> $full_story=CCDlookup("info","index_box_4", "id>0",$DBConnection1=new
> clsDBConnection1);
> With:
> $full_story=CCGetDBValue("SELECT info FROM index_box_4 ORDER BY date_field
> DESC LIMIT 1",new clsDBConnection1);
> or, if you don't have a date field, use the id:
> $full_story=CCGetDBValue("SELECT info FROM index_box_4 ORDER BY id DESC
> LIMIT 1",new clsDBConnection1);
>
>
> The key word there is DESC, that would sort the records in descending
order,
> putting the record with the latest date (or highest id) on the top.
>
> Regards,
>
> Sixto
>
>
> "Jerry" <jerryb@pccms.com> wrote in message
>news:buhkrs$eah$1@news.codecharge.com...
> > the even code is the id. Trying to remember why I used id>0 I know
there
> > was a reason. What I need to happen is that it shows the newest
records.
> I
> > think when I was using the id>0 I was just getting one record. Now I am
> > getting 3. But that does make sense to why I get the first record every
> > time. Banging my head on the monitor now.
> >
> > So how would I change that to say get the newest records?
> >
> > Thanks
> > Jerry
> >
> > "Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
> >news:bu3qvi$pj9$1@news.codecharge.com...
> > > Look again. I'm not doing a second lookup to get the information. Why
> are
> > > you using a DLookup and not assigning the field directly on the
grid...
> ?
> > >
> > > Anyway, looking at your CCDLookup line, I notice that your where
> condition
> > > is "id>0" so you'll always end up with the first record with an id >
0,
> > most
> > > probably, the first stored record of the table index_box_4. You must
set
> > > your where condition to exactly the id of the record you want to fetch
> up
> > > (e.g. "id=40").
> > >
> > > In your grid, is the field where you placed your event code an id? Or
is
> > it
> > > the full story?
> > >
> > > Regards,
> > >
> > > Sixto
> > >
> > > "Jerry" <jerryb@pccms.com> wrote in message
> > >news:bu3nil$hcg$1@news.codecharge.com...
> > > > Sorry, I didn't read this close enough. But this is the way I
already
> > > have
> > > > it. I have the function set to run just in the field, not the whole
> > grid.
> > > >
> > > > But when I do this it gives me the same info for the "info" field in
> all
> > > > instances of the grid.
> > > >
> > > > Any ideas?
> > > > Thanks again,
> > > > Jerry
> > > >
> > > >
> > > > "Sixto Luis Santos" <sixto@tecnoapoyo.com> wrote in message
> > > >news:btvch0$ith$1@news.codecharge.com...
> > > > > Jerry,
> > > > >
> > > > > Mind if I ask where did you get that truncate function? It is
> > incredibly
> > > > > similar to one I created for one of my clients... including the
> > function
> > > > > name, the variables and the logic... wow!
> > > > >
> > > > > Anyway... You can try to modify the field directly on the grid.
Just
> > > setup
> > > > > your grid to display the full story, then modify the output in the
> > > > > BeforeShow event of the info field. For example, let's say that
your
> > > > grid's
> > > > > name is index_box_4 and the story field is info, then do somethig
> like
> > > > this:
> > > > >
> > > > > //index_box_4_info_BeforeShow @16-3860B259
> > > > > function index_box_4_info_BeforeShow()
> > > > > {
> > > > > $index_box_4_info_BeforeShow = true;
> > > > > //End index_box_4_info_BeforeShow
> > > > >
> > > > > //Custom Code @29-70651C89
> > > > > // -------------------------
> > > > > global $index_box_4;
> > > > >
> > > > > $full_story=$index_box_4->info->GetValue();
> > > > > $index_box_4->info->SetValue(smart_truncate($full_story));
> > > > >
> > > > > // -------------------------
> > > > > //End Custom Code
> > > > >
> > > > > //Close index_box_4_info_BeforeShow @16-CD9AD5A1
> > > > > return $index_box_4_info_BeforeShow;
> > > > > }
> > > > > //End Close index_box_4_info_BeforeShow
> > > > >
> > > > >
> > > > > For the hyperlink to the story, you should add an actual Link
> control
> > > > under
> > > > > the story field. In this case, the HTML template should look
> something
> > > > like:
> > > > > {info}<br><a href="{info_link_Src}">{info_link}</a>
> > > > >
> > > > > Regards,
> > > > >
> > > > > Sixto
> > > > >
> > > > >
> > > > > "Jerry" <jerryb@pccms.com> wrote in message
> > > > >news:btuqji$mtr$1@news.codecharge.com...
> > > > > > CCS 2, php, MySql, Windows Server 2003 web edition. (code built
on
> > xp
> > > > > > machine)
> > > > > > I am having a problem with a truncate function.
> > > > > >
> > > > > > The code is listed below.
> > > > > >
> > > > > > My problem:
> > > > > > On my index page I have it call a table called "news". However
I
> > need
> > > > it
> > > > > to
> > > > > > limit the output to "x" number of letters. (see function code
> > below)
> > > I
> > > > > > call the first 3 rows in this table. Inside the table are the
> > fields
> > > > > > "news_id, date, title, news". In the grid on the index page I
> call
> > > all
> > > > of
> > > > > > these items. All show correctly except for the "news" field,
> which
> > is
> > > > > where
> > > > > > I have my truncate function. It does its job great, except it
> shows
> > > the
> > > > > > same record in all three rows of the grid. The ID (which I
> changed
> > to
> > > a
> > > > > > link to view the full article), title, and date all show the
> correct
> > > > > > information, but the news always shows what is in the first
"news"
> > row
> > > > of
> > > > > > the database.
> > > > > >
> > > > > > Anyone have any ideas? I have tried everything I could think
of.
> > > > > Including
> > > > > > moving the function to cover the whole grid rather then just the
> > > "news"
> > > > > > field. The function currently runs "before show" in the "news"
> > label.
> > > > > This
> > > > > > function is on the page once in two separate grids.
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > > > --
> > > > > > -------------------
> > > > > > Here is the function:
> > > > > >
> > > > > > in common.php:
> > > > > > function smart_truncate ($str2cut,$trig_value=200")
> > > > > > {$newstr="";
> > > > > >
> > > > > > if(strlen($str2cut)<=$trig_val)
> > > > > > return $str2cut;
> > > > > >
> > > > > > $newlen=strrpos(substr($str2cut,0,$trig_val),"");
> > > > > >
> > > > > > $newstr=substr($str2cut,0,$newlen);
> > > > > > else
> > > > > > $newstr=substr($str2cut,0,@trig_val);
> > > > > >
> > > > > > return $newstr"...<i>Click here to view full article</i>";
> > > > > > }
> > > > > >
> > > > > > ***NOTE: for some reason in that last line <i> is the only HTML

> tag
> > I
> > > > can
> > > > > > get to work.. I would like to change the color on this too, but
> for
> > > > some
> > > > > > reason it wont let me.. any ideas why??? ***
> > > > >
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > > > --
> > > > > > --------------------
> > > > > >
> > > > > > This part goes on the page in the before show
> > > > > >
> > > > > > Global $index_box_4
> > > > > > $full_story=CCDlookup("info","index_box_4", "id>0",
> > > > > > $DBConnection1=new clsDBConnection1);
> > > > > >
> > > > > > $snip_story = smart_truncate($full_story);
> > > > > > $index_box_4 -->info-->SetValue($snip_story);
> > > > > >
> > > > >
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > > > --
> > > > > > -------------------------
> > > > > >
> > > > > > Thanks for any help,
> > > > > > Jerry
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.