It is currently Tue Jul 22, 2025 2:29 am



Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Making a PHP blog? 
Author Message
Minor Diety
User avatar

Joined: Fri Apr 11, 2003 5:09 pm
Posts: 4004
Location: Walsall, West Mids, UK
Reply with quote
Post 
Alright, got it working, thanks ;)

Could you do me a favour, I know this will probably make you think "i can't be arsed" but could you explain to me, what exactly it is you are doing to the line of code that gives the out put?

Sort of, outline the transition between my crappy version, and your better version.

EDIT: Screw the above question. I looked at it, and I think I understand it.

The question I'd like to know, is what command do I put inplace of

Code:
$author=mysql_result($result, 0 ,"author");


To display the LAST entry, not the first. The problem is last is dynamic, it will be changing many times. Is there a predetermind term for "last"? Because if so, displaying the last 3 would be easy I guess. Just "last - 1" and so on.

_________________
Games to complete:
GTA IV [100%] (For Multiplayer next!)
Fallout 3 [50%]
Rock Band [35%]
http://www.cafepress.com/SmeepProducts


Fri Aug 12, 2005 4:55 pm
Profile WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16701
Location: On a slope
Reply with quote
Post 
you talking about the last record returned?

couple ways I can think to do it. First way (what you'll probably use. :P)

$number_of_records = mysql_num_rows($result);

this gives you the number of records returned by your query.

$author = mysql_result($result,$number_of_records,"author");

that will return the "author" field of hte last row. I didn't actually know you could do that with mysql_result...I always thought the field had to be field number, I didn't realize it could be the name. Neat.

As for what I did...it's a good idea to get good coding habits set up, so let me explain. What you did was (basically):

echo ("Blah and $blah");

the () are unnecessary, so I dropped them. Secondly, when you have an echo surrounded by " (double quotes) you're tellilng PHP that it needs to parse the string. That means it looks all through there for special characters and variables and shit. That is slow. Using single quotes tells it not to parse the string, ie

echo 'blah and $blah';

of course now, it doesn't parse the $blah so it actually returns $blah instead of whatever variable $blah is. The fix for that would be

echo 'blah';
echo $blah;

using cocatenation, you can turn that into

echo 'blah' .$blah;

Then I just strung that together for your full statement.

There's nothing technically wrong with the way you did it, but if you want code that executes quickly and with a minimum of overhead, I suggest you do it my way. As an aside, you may notice concatenation being used in the SQL statement defintion in your code.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Fri Aug 12, 2005 5:19 pm
Profile WWW
Minor Diety
User avatar

Joined: Fri Apr 11, 2003 5:09 pm
Posts: 4004
Location: Walsall, West Mids, UK
Reply with quote
Post 
Thanks for the input.

Well, Over the past few hours, i've gotten my self a log-in-able blog, that shows the last three records!

Not majorly secure, I know, but it's good enough for tonight.

One question - When I enter in a review, if I type in an apastrophe, it complains about syntax error - like it's parsing the stuff I enter as php or something?

Any idea what sort of stuff you can do to stop that?

_________________
Games to complete:
GTA IV [100%] (For Multiplayer next!)
Fallout 3 [50%]
Rock Band [35%]
http://www.cafepress.com/SmeepProducts


Sat Aug 13, 2005 6:40 pm
Profile WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16701
Location: On a slope
Reply with quote
Post 
when you convert you $_POST to a regular variable, addslashes on it...ie

$text=addslashes($_POST[text]);

you're running into those hacks we're talking about.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Sun Aug 14, 2005 11:27 am
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
If you have the ability to edit your php.ini. you should turn magic_quotes on.


Sun Aug 14, 2005 11:36 am
Profile YIM WWW
Minor Diety
User avatar

Joined: Fri Apr 11, 2003 5:09 pm
Posts: 4004
Location: Walsall, West Mids, UK
Reply with quote
Post 
hmm, I dunno if i do have permision to edit the server php.ini - but I can get them to do it for me.

Satis: Can I add more than one thing to the POST part? Because I already have htmlentities there. (hehe, tities)

_________________
Games to complete:
GTA IV [100%] (For Multiplayer next!)
Fallout 3 [50%]
Rock Band [35%]
http://www.cafepress.com/SmeepProducts


Sun Aug 14, 2005 2:00 pm
Profile WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16701
Location: On a slope
Reply with quote
Post 
if you're asking if you can run more than one function on the $_POST, yes, you can run as many as you want.

ie:

$text = addslashes(htmlentities($_POST[text]));

you can wrap as many together as you want. I think my record is 4 or 5. Pig probably has twice as many.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Mon Aug 15, 2005 7:54 am
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
The only time I every wrapped more than 4 or 5 function calls like that, was because I didn't know what I was doing. I think I was using str_replace, and didn't realize you could use an array as the search parameter.

If you can get magic_quotes turned on, you should. Just realize that using add_slashes is redundant, and you should not do both. Just one or the other.

I often use a script I wrote called purge_text() that I feed all user input through. It checks if magic_quotes is on, and adds them manually if it is not. It also does strip_tags, htmlspecialchars, trim, and maybe another function or two.


Mon Aug 15, 2005 8:48 am
Profile YIM WWW
Minor Diety
User avatar

Joined: Fri Apr 11, 2003 5:09 pm
Posts: 4004
Location: Walsall, West Mids, UK
Reply with quote
Post 
thanks guys :D

_________________
Games to complete:
GTA IV [100%] (For Multiplayer next!)
Fallout 3 [50%]
Rock Band [35%]
http://www.cafepress.com/SmeepProducts


Mon Aug 15, 2005 11:27 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 24 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.