Page 1 of 1

Newbie: textarea & latest X submited?

Posted: Sat Jul 20, 2002 1:58 pm
by spear1976
Hi,

I hope someone can help a mySQL/PHP newbie.

This is what I'm trying to do:
I've bought a books on PHP/mySQL, but it was onlye very "fresh user" related, and withing two hours i wanted to do more then the book told me.

1: I have managed to create a very simple joke DB, with categories etc. Howverer i would like to joke field to insert the correct paragraph and linebreak in the joke.
E.g I type something like (in a textarea):
Line1
Line 2

Line 4

When the joke is displayed, it returns everything on a single line. Can someone help me with how to do this, or point me to an article describing it?

2:
I would also like to add something like "The latest X jokes", can someone help me with the extraction from mySQL on this?

Really hope someone will take the time to help out.

Best regards, Spear

Posted: Sat Jul 20, 2002 2:48 pm
by fatalcure
Well, when your displaying the joke and dont want it to all appear on one line do this:

Code: Select all

$joke = nl2br($rowї"joketext"]);
now when you display the text, it'll have all the line breaks :)

And for the latest X jokes the query is:

Code: Select all

$x = 10;
$query="SELECT * FROM jokestable ORDER BY dateadded LIMIT 0,$x";
Then to display the code u just do:

Code: Select all

echo "Latest $x Jokes:<br>";
while ($row = mysql_fetch_array($result)) &#123;
     $title = $row&#1111;"title"];
     $author = $row&#1111;"author"];
     ...ect.
 
     echo "$title - $author <br>";
&#125;
:)

Thank you..

Posted: Sat Jul 20, 2002 3:18 pm
by spear1976
Hi,
fatalcure wrote:Well, when your displaying the joke and dont want it to all appear on one line do this...
Thank you very much for your help! Now everything is almost the way i want it. I have one last question... Or to be honest.. Two questions :)

1: Could you or anyone else recomend a good "howto" book that is advanced enough not to leave me pondering after a few hours, but easy enough for a newbie?

2: Lets say i wanted to add a 10 jokes per page, and include a "Next/Previous" button in the categories if it contained more then 10 jokes. Difficult?

Best regards, Spear

Posted: Sat Jul 20, 2002 4:10 pm
by fatalcure
1. I dunno about any books, i just learn over the WEB.

2. look at this post for the prev-next links: http://liberty.dnsprotect.com/~devnetwo ... 3c304#7163

hope it helps :)