RE: [PHP] Newbie Question re substr

2005-03-08 Thread Kim Madsen
From: Jackson Linux [mailto:[EMAIL PROTECTED] 
Sent: 8. marts 2005 04:23

First of all, echo the output to see if You get, what Tou expect in a debug 
situation:

if (!empty($where)) {

echo 
 ul;
  $article = mysql_fetch_assoc($result);
} else {
  while ($article = mysql_fetch_assoc($result)) {
// humanize data
$article_id = $article['article_id'];
$title = $article['title'];
$content = substr($article['content'], 0 200); // get first 200 chars 
// print and see if we get, what we expect
Print id=$article_idbrtitle=$titlebrcontent=$contentp;
// now make the real stuff
print lia href='{ . $_SERVER['PHP_SELF'] . 
}?a={$article_id}'}title='{$title}'{$article['title']}/abr 
/\n$content/li;
  }
}

echo 
 /ul;

I´ve put the  in front of title since the link otherwise would be a 
href=a=1234title=sometext, which is not what You want I guess.

And I substituted the 

  $article['content'] = substr($article['content'], 0 200);/li; } }

with

  $content/li;

since I believe You want to print the content and not just assign it? Otherwise 
the br / makes no sense :-)

 Can anyone help ?

I hop that did the trick for You :-)

-- 
Med venlig hilsen / best regards
ComX Networks A/S
Kim Madsen 
Systemudvikler
Naverland 31

DK-2600 Glostrup
www.comx.dk 
Telefon: +45 70 25 74 74
Telefax: +45 70 25 73 74
E-mail: [EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie Question re substr

2005-03-08 Thread Jackson Linux
On 8 Mar 2005, at 11:40, Richard Lynch wrote:
1. $content = substr($article['content'], 0 200); // get first  
200
chars   is choking, and I've looked in docs and can't understand why.
I get

Parse error: parse error, unexpected T_LNUMBER in
/usr/www/users/domain/dynamic/templates/substr.htm on line 57
In this line, PHP is somehow encountering a T_NUMBER (a number) where  
it
*expects* to see something else.

Like a comma.
Look between your 0 and 200 very carefully.

Thanks for taking the time. I had suspected that earlier, but when I  
put it in all sorts of OTHER stuff happened.

Then I saw your post and tried again. I saw that I had made another  
mistake later on. So you've solved that part - thanks!.

ExceptExcept it doesn't pull the content from the db and substr it  
to 200 characters. It pulls the id number and the title no problem, and  
I am sure that $article['content'] points to the right place (or at  
least it's named right) but it's just not getting the content:

if (!empty($where)) {
echo 
 ul;
  $article = mysql_fetch_assoc($result);
} else {
  while ($article = mysql_fetch_assoc($result)) {
// humanize data
$article_id = $article['article_id'];
$title = $article['title'];
$content = substr($article['content'], 0, 400); // get first 200  
chars
// print and see if we get, what we expect
// print id=$article_idbrtitle=$titlebrcontent=$contentp;
// now make the real stuff
$table_of_contents[] = lia  
href='{$_SERVER['PHP_SELF']}? 
a={$article_id}'}title='{$title}'{$article['title']}/abr/ 
$contentbr /a  
href='{$_SERVER['PHP_SELF']}?a={$article['article_id']}'  
title='{$article['title']}' ... [Read article]/a/li/li;
  }
}

echo 
 /ul;
Thanks in advance. . .
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re [PHP] Newbie Question re substr: Solved

2005-03-08 Thread Jackson Linux
Sorry if this posts twice. Thanks everyone for the help.
The missing comma was the problem with the display; the missing  
specification of the column at the start of the sql query was the  
problem with getting the data from the column.

Again, thanks all who replied for the fast and excellent help.
On 8 Mar 2005, at 11:40, Richard Lynch wrote:
1. $content = substr($article['content'], 0 200); // get first  
200
chars   is choking, and I've looked in docs and can't understand why.
I get

Parse error: parse error, unexpected T_LNUMBER in
/usr/www/users/domain/dynamic/templates/substr.htm on line 57
In this line, PHP is somehow encountering a T_NUMBER (a number) where  
it
*expects* to see something else.

Like a comma.
Look between your 0 and 200 very carefully.

Thanks for taking the time. I had suspected that earlier, but when I  
put it in all sorts of OTHER stuff happened.

Then I saw your post and tried again. I saw that I had made another  
mistake later on. So you've solved that part - thanks!.

ExceptExcept it doesn't pull the content from the db and substr it  
to 200 characters. It pulls the id number and the title no problem, and  
I am sure that $article['content'] points to the right place (or at  
least it's named right) but it's just not getting the content:

if (!empty($where)) {
echo 
 ul;
  $article = mysql_fetch_assoc($result);
} else {
  while ($article = mysql_fetch_assoc($result)) {
// humanize data
$article_id = $article['article_id'];
$title = $article['title'];
$content = substr($article['content'], 0, 400); // get first 200  
chars
// print and see if we get, what we expect
// print id=$article_idbrtitle=$titlebrcontent=$contentp;
// now make the real stuff
$table_of_contents[] = lia  
href='{$_SERVER['PHP_SELF']}? 
a={$article_id}'}title='{$title}'{$article['title']}/abr/ 
$contentbr /a  
href='{$_SERVER['PHP_SELF']}?a={$article['article_id']}'  
title='{$article['title']}' ... [Read article]/a/li/li;
  }
}

echo 
 /ul;
Thanks in advance. . .
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Newbie Question re substr

2005-03-08 Thread Richard Lynch




Jackson Linux wrote:
 On 8 Mar 2005, at 11:40, Richard Lynch wrote:

 1. $content = substr($article['content'], 0 200); // get first
 200
 chars   is choking, and I've looked in docs and can't understand why.
 I get

 Parse error: parse error, unexpected T_LNUMBER in
 /usr/www/users/domain/dynamic/templates/substr.htm on line 57

 In this line, PHP is somehow encountering a T_NUMBER (a number) where
 it
 *expects* to see something else.

 Like a comma.

 Look between your 0 and 200 very carefully.



 Thanks for taking the time. I had suspected that earlier, but when I
 put it in all sorts of OTHER stuff happened.

 Then I saw your post and tried again. I saw that I had made another
 mistake later on. So you've solved that part - thanks!.

 ExceptExcept it doesn't pull the content from the db and substr it
 to 200 characters. It pulls the id number and the title no problem, and
 I am sure that $article['content'] points to the right place (or at
 least it's named right) but it's just not getting the content:

Put in a var_dump($article) where you think you have 'content' right.

See what you have.

Make sure 'content' is in your list of fields you are retrieving.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie Question re substr

2005-03-07 Thread Zareef Ahmed
On Mon, 7 Mar 2005 22:23:19 -0500, Jackson Linux
[EMAIL PROTECTED] wrote:
 Hi,
 I'm really new and getting lots of help but need some assistance.
 
 I'm running a script which gets specific articles from a database if
 they're entered in the URL after the ? . For instance if someone asks
 for
 
 www.foo.com/index.htm?a=1234
 
 then the script would look for an database entry with the id of 1234
 and display it in the page.
 
 If there's no number specified (www.foo.com/index.htm) or if the number
 given is to an article which doesn't exist, it gets the titles of all
 the articles available and prints them as links to the proper article
 number.
 
 I'd also like it to grab the first 200 characters of text from the
 $content field of the entry.
 
 With help I have the title link part and I suspect I'm close but I keep
 messing up the syntax
 
 The code is:
 
 snip
 
 if (!empty($where)) {
 
 echo 
  ul;
   $article = mysql_fetch_assoc($result);
 } else {
 while ($article = mysql_fetch_assoc($result)) {
   $table_of_contents[] = 
 lia href='{$_SERVER['PHP_SELF']}?a={$article['article_id']}'

 title='{$article['title']}'{$article['title']}/abr /
 $article['content'] = substr($article['content'], 0 200);/li;

change these two lines to 

title='{$article['title']}'{$article['title']}/abr /.
substr($article['content'], 0, 200)./li;

zareef ahmed 


 }
 }
 
 echo 
  /ul;
 
 /snip
 
 Can anyone help ?
 
 Thanks in advance!
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
Zareef Ahmed :: A PHP Developer in India ( Delhi )
Homepage :: http://www.zareef.net

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newbie Question re substr

2005-03-07 Thread Jackson Linux
Zareef,
Almost
On 7 Mar 2005, at 23:52, Zareef Ahmed wrote:
From: [EMAIL PROTECTED]
Subject:Re: [PHP] Newbie Question re substr
Date:   7 March 2005 23:52:15 GMT-05:00
To:   [EMAIL PROTECTED]
Cc:   php-general@lists.php.net
Reply-To: [EMAIL PROTECTED]
On Mon, 7 Mar 2005 22:23:19 -0500, Jackson Linux
[EMAIL PROTECTED] wrote:
Hi,
I'm really new and getting lots of help but need some assistance.
I'm running a script which gets specific articles from a database if
they're entered in the URL after the ? . For instance if someone asks
for
www.foo.com/index.htm?a=1234
then the script would look for an database entry with the id of 1234
and display it in the page.
If there's no number specified (www.foo.com/index.htm) or if the number
given is to an article which doesn't exist, it gets the titles of all
the articles available and prints them as links to the proper article
number.
I'd also like it to grab the first 200 characters of text from the
$content field of the entry.
With help I have the title link part and I suspect I'm close but I keep
messing up the syntax
The code is:
snip
if (!empty($where)) {
echo 
 ul;
  $article = mysql_fetch_assoc($result);
} else {
while ($article = mysql_fetch_assoc($result)) {
  $table_of_contents[] = 
lia href='{$_SERVER['PHP_SELF']}?a={$article['article_id']}'

title='{$article['title']}'{$article['title']}/abr /
$article['content'] = substr($article['content'], 0 200);/li;
change these two lines to
title='{$article['title']}'{$article['title']}/abr /.
substr($article['content'], 0, 200)./li;
zareef ahmed

I did that and now it reads this:

if (!empty($where)) {
echo 
 ul;
 $article = mysql_fetch_assoc($result);
} else {
while ($article = mysql_fetch_assoc($result)) {
 $table_of_contents[] = 
lia href='{$_SERVER['PHP_SELF']}?a={$article['article_id']}'
lia href='{$_SERVER['PHP_SELF']}?a={$article['article_id']}'
title='{$article['title']}'{$article['title']}/abr /.
substr($article['content'], 0, 200)./li;
}
}
\
Which doesn't kick back errors but also does not pull any 
$article['content'] - it leaves a line break but no text is being 
inserted from the content row.
?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php