PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 3rd, 2009, 06:09 AM
liamdawe's Avatar
liamdawe liamdawe is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2006
Location: England
Posts: 514 liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 14 h 1 m 24 sec
Reputation Power: 16
Send a message via MSN to liamdawe Send a message via Google Talk to liamdawe
Major problems on looping through an array

Hi all currently i am looping through sql and setting the findings into an array and then later using a foreach loop to output what it has.

It nearly works but a major problem is that it seems to double up sometimes with the wrong info?

This is how i set the array:
PHP Code:
while ($get_posts $db->fetch_array($pagination_query))
{
    
$this->post_array[] = $get_posts;



Then i loop through it later on using this:
PHP Code:
foreach ($this->post_array as $post


I need to do it like this as i get other information and echo out before the loop is done like so:

(this sets the title in the header of the document from the array gathered ealier)
PHP Code:
 $title_header " >> {$lang['viewtopic']} >> {$this->post_array[0]['title']}"


I know i am probably making some stupid mistake?

You can see how annoying the error is here:
http://www.prxa.info/forum/viewtopic.php?tid=97
(as you can see there it shows the first one fine but then makes me have a reply for each other persons reply lol).

Reply With Quote
  #2  
Old July 3rd, 2009, 07:45 AM
Mark Baker Mark Baker is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Nov 2001
Location: North West UK
Posts: 1,137 Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level)Mark Baker User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 18 h 43 m 39 sec
Reputation Power: 391
Most database fetch calls (e.g. mysql_fetch_array) allow you to define how you want the data returned.
An optional result_type parameter allows you to identify how you want to specify the keys in your returned result. In the case of MySQL, MYSQL_ASSOC will return each column from the record, in an array indexed by the column name; MYSQL_NUM will return each column from the record, in an array indexed by a numeric value (the order of the column in the result set; MYSQL_BOTH will return two entries for each column in the record, one entry in the array indexed by the column name, the second entry by the numeric value.

The default is MYSQL_BOTH
Comments on this post
Arty Ziff agrees!
__________________
9 out of 10 PHP problems can be resolved by setting
PHP Code:
 error_reporting(E_ALL);
ini_set('display_errors'1); 
php -l <filename> will identify 9 out of the remaining 10 problems
Remember, the command line is your friend

Development Projects:
PHPExcel
PHPPowerPoint

Reply With Quote
  #3  
Old July 3rd, 2009, 07:48 AM
liamdawe's Avatar
liamdawe liamdawe is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2006
Location: England
Posts: 514 liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 14 h 1 m 24 sec
Reputation Power: 16
Send a message via MSN to liamdawe Send a message via Google Talk to liamdawe
I have figured out that i don't think that is the problem.

I have actually found out the problem does lie in the array set the the sql, it seems to add the extra posts into it there so i don't think the problem actually is the foreach loop.

Look at this post for example:
http://www.prxa.info/area51/viewtopic.php?tid=1

Number 3 in the array shouldn't be there. And so it is echod out in the foreach loop, which is right since it is in the array, but the array is wrong. So is it a problem with the way i grab it with the sql?

Reply With Quote
  #4  
Old July 3rd, 2009, 09:59 AM
simshaun's Avatar
simshaun simshaun is offline
$x=104;echo chr($x++),chr($x);
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Location: North Carolina
Posts: 1,658 simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)simshaun User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 18142 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 4 Days 2 h 18 m 38 sec
Reputation Power: 1384
It depends..

1. what does your sql look like?
2. are you sure $db->fetch_array is not buggy?

Reply With Quote
  #5  
Old July 3rd, 2009, 05:19 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Dec 2004
Posts: 3,227 E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 3 Weeks 17 h 45 m 15 sec
Reputation Power: 2061
If you're doing a JOIN incorrectly in your SQL query this could easily happen. My guess is that's where the problem lies.

Reply With Quote
  #6  
Old July 4th, 2009, 02:21 PM
liamdawe's Avatar
liamdawe liamdawe is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2006
Location: England
Posts: 514 liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level)liamdawe User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 14 h 1 m 24 sec
Reputation Power: 16
Send a message via MSN to liamdawe Send a message via Google Talk to liamdawe
E-Oreo was correctly it was a wrong join query, thanks all.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Major problems on looping through an array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT