homepage Welcome to WebmasterWorld Guest from 54.196.168.78
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How to Limit Display and Force Click
Click here to read more...
asas111




msg:3788546
 5:45 am on Nov 18, 2008 (gmt 0)

Here is what I am trying to do, and I given my little PHP knowledge, I have already gotten so much done.

1-I run PHPmyfaq on my website (a script to crate and display FAQs on your website)

2-I have created a simple script that randomly displays a different FAQ record, everytime you load the home page.

3-Problem is, the whole FAQ article is displayed, and I don't want that. I simply want to dislpay the title of the record, then first 10 words of the article, and then a link for people to click and read the entire article. Like the following:

#*$!: A webmasters and Developers forum, where you can discuss.... (click to read more)

That is it. No more, no less.

Now for the code, this is what I have, but unfortunately, I am missing the code that will limit how many words are displayed, as well as the link to the entire article.

<?php

// Create the connection and select the DB
$link = mysql_connect("host","user","password");

if ($link) {
mysql_selectdb("db",$link);

// Select records from the DB
$query = "SELECT content FROM pmf_faqdata ORDER BY Rand() LIMIT 1";
$result = mysql_query($query);

// Display records from the table
echo "<table border='1'>";
while ($row = mysql_fetch_array($result, MYSQL_NUM))

{
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[1]</td></tr>";
}
echo "</table>";

} else {
echo "Can't connect to the database!";
}

?>

I would really appreciate if someone can help me in achieving this?

 

daveginorge




msg:3788613
 8:01 am on Nov 18, 2008 (gmt 0)

How about using substr and limiting the output to the desired length.
[no.php.net ]

I also just read this on this forum from a day or two ago..
[webmasterworld.com ]

asas111




msg:3789060
 7:23 pm on Nov 18, 2008 (gmt 0)

Thanks a lot guys,

I got the first thing done.

The only thing left, is to hyperlink it, so people can click on the topic and read it in full

Article: This is an article about something...(click here to read more)

I would appreciate if someone can finish this for me please?

// Create the connection and select the DB
$link = mysql_connect("host","name","password");

if ($link) {
mysql_selectdb("password",$link);

// Select records from the DB
$query = "SELECT content,thema FROM pmf_faqdata ORDER BY Rand() LIMIT 1";
$result = mysql_query($query);

// Display records from the table
echo "<table border='1'>";
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<tr><td>".substr($row[1],0,50).substr($row[0],0,75)."...</td></tr>";
}
echo "</table>";
} else {
echo "Can't connect to the database!";
}

ngrant




msg:3789339
 1:46 am on Nov 19, 2008 (gmt 0)

well how does your faq create pages? I.E. when you click the link is it page.php?id=1 or is it page.php?title=this_and_that or maybe somesite/faq/this_and_that

asas111




msg:3794886
 8:43 pm on Nov 26, 2008 (gmt 0)

A typical FAQ record on this section looks like this:

http://www.example.com/faq/index.php?action=artikel&cat=3&id=5&artlang=en

thanks for any help

[edited by: dreamcatcher at 11:17 pm (utc) on Nov. 26, 2008]
[edit reason] use example.com. Thanks. [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved