Be a Supporter!

While loops (Last Post)

  • 568 Views
  • 13 Replies
New Topic Respond to this Topic
Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
While loops (Last Post) 2006-12-02 22:26:19 Reply

I'm making a forum, and for some odd reason, the LAST POST part of the forum, isn't working
(forum located here)

The problem is, that the last person who posted, is displayed as "last poster" on every topic.....

http://pastebin.ca/265236 [Last Post Script]

That's the link to the LAST POST part...and here's the link to the whole page..

http://pastebin.ca/265238 [Full Script]

Can anyone fix this?


Hello, from the past!
[ PHP: Main ]

BBS Signature
usanamed
usanamed
  • Member since: Jul. 12, 2006
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to While loops (Last Post) 2006-12-03 20:37:40 Reply

Again, due to the stupid no code thing, you'll have to add "a's" when I tell you to.

HTML

A marquee
Code:
<marquee direction="up">WOW! An up marquee!!!!!</marquee>
Appears: This html is disabled on retrogade.

JavaScript

This one is to make a go back button.
Code:<[a here] href='javascript:history.go(-1)'>Go back</[a here]>
Appears:Go back

This one you can use to add your website to peoples favorites.
Code:
<[a here] href="javascript:window.external.AddFavorite( 'http://www.retrogade.com', 'http://www.CodedFX.com')" alt="Save As Fav">ADD TO FAVOURITES</[a here]>
Appears: I can't really show you how it would come out, but if it doesn't work feel free to IM me.

Easy pop-ups. This makes it so you can choose what size you want the pop-ups to be.
Code:<[a here] href="javascript:void(0)"
onclick="window.open('URL-OF-POP-UP-HERE',
'miniwin',
'toolbar=0,
location=0,
directories=0,
status=0,
menubar=0,
scrollbars=0,resizable=0
,width=470,
height=205')">TEXT-YOU-WANT-TO-DISPLAY-HERE</ [a here]>
Appears: Again, I can't show you, but if you have any comments feel free to PM me.

That's all I have time for now, but I may post some later.

Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to While loops (Last Post) 2006-12-03 20:59:02 Reply

Dude??!?! Do you even know what topic you're posting in?

Oh and the link to the forum is broken...it's actually at http://bs.byethost11.com/bsc/forum.php?id=1


Hello, from the past!
[ PHP: Main ]

BBS Signature
Jessii
Jessii
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 36
Movie Buff
Response to While loops (Last Post) 2006-12-03 21:02:32 Reply

At 12/3/06 08:59 PM, Momo-the-Monkey wrote: Dude??!?! Do you even know what topic you're posting in?

I don't think he does

Oh and the link to the forum is broken...it's actually at http://bs.byethost11.com/bsc/forum.php?id=1

It still doesn't seem to work.

Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to While loops (Last Post) 2006-12-03 21:22:20 Reply

Ok, I don't know what i typed wrong, but here's the Copy and Paste version of the link

http://bs.byethost11.com/bsc/forum.php?id=1


Hello, from the past!
[ PHP: Main ]

BBS Signature
Afro-Ninja
Afro-Ninja
  • Member since: Mar. 2, 2002
  • Offline.
Forum Stats
Moderator
Level 44
Game Developer
Response to While loops (Last Post) 2006-12-03 21:38:06 Reply

I'm having a look through it, but it pains me at the amount of optimization you could be doing here :(

first of all for starters- you check the $_GET['id'] to make sure it exists and that it's numeric, then you transfer it to $id and escape it with mysql_real_escape_string

That's good- but you don't need to keep referencing GET. whenever you want that id just use $id, don't keep taking it from $_GET. and you only need to escape it once, not every time you want to use it.


BBS Signature
Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to While loops (Last Post) 2006-12-03 21:51:20 Reply

At 12/3/06 09:38 PM, Afro-Ninja wrote: I'm having a look through it, but it pains me at the amount of optimization you could be doing here :(

first of all for starters- you check the $_GET['id'] to make sure it exists and that it's numeric, then you transfer it to $id and escape it with mysql_real_escape_string

That's good- but you don't need to keep referencing GET. whenever you want that id just use $id, don't keep taking it from $_GET. and you only need to escape it once, not every time you want to use it.

Yes, I know i don't have to keep referring it...but If i don't...It doesn't use it for some odd reason. It like just delete's the variables everytime I start an If-statement...

Also, I know it's simple...but I can't think right now..

How do I use an if-statement to check to see if the ID exists in the database? So people can't enter a invalid ID (eg 123456789000102543851) and it just shows the blank template.


Hello, from the past!
[ PHP: Main ]

BBS Signature
WoogieNoogie
WoogieNoogie
  • Member since: Jun. 26, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to While loops (Last Post) 2006-12-03 21:54:40 Reply

At 12/3/06 09:51 PM, Momo-the-Monkey wrote: How do I use an if-statement to check to see if the ID exists in the database? So people can't enter a invalid ID (eg 123456789000102543851) and it just shows the blank template.

$variable = mysql_query("SELECT * FROM db WHERE ID = '$id'");
$count = mysql_num_rows($variable);
if(empty($count)) {
die("empty");
}

Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to While loops (Last Post) 2006-12-03 21:58:33 Reply

At 12/3/06 09:54 PM, WoogieNoogie wrote:
$variable = mysql_query("SELECT * FROM db WHERE ID = '$id'");
$count = mysql_num_rows($variable);
if(empty($count)) {
die("empty");
}

Wow....lol....Thanks!


Hello, from the past!
[ PHP: Main ]

BBS Signature
Afro-Ninja
Afro-Ninja
  • Member since: Mar. 2, 2002
  • Offline.
Forum Stats
Moderator
Level 44
Game Developer
Response to While loops (Last Post) 2006-12-03 22:11:42 Reply

At 12/3/06 09:54 PM, WoogieNoogie wrote:
At 12/3/06 09:51 PM, Momo-the-Monkey wrote: How do I use an if-statement to check to see if the ID exists in the database? So people can't enter a invalid ID (eg 123456789000102543851) and it just shows the blank template.
$variable = mysql_query("SELECT * FROM db WHERE ID = '$id'");
$count = mysql_num_rows($variable);
if(empty($count)) {
die("empty");
}

it's quicker to do a count paired with mysql_result, because then you're not actually selecting anything out

$variable =mysql_query("SELECT COUNT(id) FROM table WHERE id=$id");
if(mysql_result($variable,0,0)==0)die('this id does not exist');


BBS Signature
WoogieNoogie
WoogieNoogie
  • Member since: Jun. 26, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to While loops (Last Post) 2006-12-03 22:23:48 Reply

At 12/3/06 10:11 PM, Afro-Ninja wrote: it's quicker to do a count paired with mysql_result, because then you're not actually selecting anything out

I thought that at first, but you can use the method I put up along with the current query you have for displaying posts.

Afro-Ninja
Afro-Ninja
  • Member since: Mar. 2, 2002
  • Offline.
Forum Stats
Moderator
Level 44
Game Developer
Response to While loops (Last Post) 2006-12-03 22:34:27 Reply

At 12/3/06 10:23 PM, WoogieNoogie wrote:
At 12/3/06 10:11 PM, Afro-Ninja wrote: it's quicker to do a count paired with mysql_result, because then you're not actually selecting anything out
I thought that at first, but you can use the method I put up along with the current query you have for displaying posts.

in that case yeah, you can just stick with your select query and don't bother with extra count


BBS Signature
Momo-the-Monkey
Momo-the-Monkey
  • Member since: Oct. 15, 2005
  • Offline.
Forum Stats
Member
Level 45
Musician
Response to While loops (Last Post) 2006-12-04 16:38:52 Reply

It's not working...

It keeps giving me the error that it's empty. Yet it's not.

http://bs.byethost11.com/bsc/forum.php?id=1

Click on any link....it obviously is in the Database....it's just giving me that stupid error!

I even changed empty($number) to $number != '1'. But it sitll didn't work!


Hello, from the past!
[ PHP: Main ]

BBS Signature
elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to While loops (Last Post) 2006-12-04 16:49:37 Reply

At 12/3/06 09:54 PM, WoogieNoogie wrote:
At 12/3/06 09:51 PM, Momo-the-Monkey wrote: How do I use an if-statement to check to see if the ID exists in the database? So people can't enter a invalid ID (eg 123456789000102543851) and it just shows the blank template.
$variable = mysql_query("SELECT * FROM db WHERE ID = '$id'");
$count = mysql_num_rows($variable);
if(empty($count)) {
die("empty");
}

$variable = mysql_query("SELECT * FROM db WHERE ID = '$id'");
$count = mysql_num_rows($variable);
if($count == 0) {
die("empty");
}

Should be more correct, no?


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature