Welcome to WebmasterWorld Guest from 54.166.55.74

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to Limit Display and Force Click

Click here to read more...

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

10+ Year Member



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?

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

5+ Year Member



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 ]

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

10+ Year Member



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!";
}

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

5+ Year Member



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
8:43 pm on Nov 26, 2008 (gmt 0)

10+ Year Member



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]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month