Current location: Hot Scripts Forums » Programming Languages » PHP » Strange script behavior attached


Strange script behavior attached

Reply
  #1 (permalink)  
Old 07-13-04, 12:01 AM
kjmatthews kjmatthews is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: Boston, MA
Posts: 134
Thanks: 0
Thanked 0 Times in 0 Posts
Strange script behavior attached

I wrote the attached script to take the ten most recent weblog entries in a database, and return them with the most recent first. When two entries occur on the same date, I only want the date listed once. This script will indeed do that, but with a strange side effect. The second post, when $i=1, appears twice in a row (once as I would like it, without a date, and once with). The final post, when $i=4 (there are currently only 5 entries in the database), does not appear at all.

I added echo $i; to see if that would shed any light on the situation, but it does not. The output looks like this:

$i=0
Post 1

$i=1
Post 2

$i=2
Post 2 (again)

$i=3
Post 3

$i=4
Post 4

Post 5 never appears. Comment out lines 16-19 (all mention of $date2), and the script displays all 5 posts, but the date appears on all of them. See the first 5 posts at this address for an example of how this displays: http://www.digitalovertone.com/weblog/http://www.digitalovertone.com/weblog/
Any thoughts?
Attached Files
File Type: txt compare_date.txt (1.6 KB, 145 views)
Reply With Quote
  #2 (permalink)  
Old 07-13-04, 01:25 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

Had a look at your script.

These two lines:

PHP Code:

$date1 mysql_result($entries$i'date');    //date of current post (e.g. postid=00004)

        
$date2 mysql_result($entries$j'date');    //date of previously listed, i.e. NEXT chronological post (e.g. postid=00005) 
On the first line, you jump to $i-th row (i.e. current), but then you jump back to $j-th row (previous). This causes the internal cursor (pointer, or whatever it may be called) to always point to the ($i - 1)th row after the first ($i = 0) row.

Note that you haven't changed $i, so it gets incremented each time by for() loop no matter what, and hence it doesn't look that bad. If you had something like $j = --$i; then you should get the same row all the way down after the second row.

Now you know what the problem is. Good luck.
__________________
Blavv =|
Reply With Quote
  #3 (permalink)  
Old 07-13-04, 11:00 AM
kjmatthews kjmatthews is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: Boston, MA
Posts: 134
Thanks: 0
Thanked 0 Times in 0 Posts
Ah yes

Thank you very much, blaw. That makes perfect sense.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM
need script quick SR_Ben PHP 1 07-11-04 12:11 PM
Artist pages script needed SR_Ben Script Requests 0 07-09-04 02:30 PM
will pay. php script needed. upload, resize, & email jamjammo Script Requests 4 02-29-04 08:30 PM
Affiliate script (PHP) whtiebear Job Offers & Assistance 2 12-21-03 12:12 AM


All times are GMT -5. The time now is 05:11 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.