Resend my activation email : Register : Log in 
BCF: Bike Chat Forums


PHP help

Reply to topic
Bike Chat Forums Index -> The Geek Zone
View previous topic : View next topic  
Author Message

Gazdaman
I did a trackday!!!



Joined: 12 Aug 2004
Karma :

PostPosted: 17:45 - 02 Dec 2006    Post subject: PHP help Reply with quote

Code:
while (($data = fgetcsv($handle, 1000, ",")) !==FALSE) { //fgetcsv returns FALSE on error, including end of file.
   $num = count($data);
   for ($c=0; $c < $num; $c++) {


      if ($data[$c] == $items) {
print "FOUND THE PICTURE IN THE DATA ARRAY! POSITION [b]$c[/b] !!!! See $data[$c] == $items<br />\n";

      }

   }


Ok right, $data[] is an array containing A filename, a description, and a price, a filename, a description and a price...etc etc etc

$items is a filename, and there is code elsewhere, that makes it loop through various different filenames.

So basically, I'm looping through $data[] to find an record that matches $item, then I want to access the record after it, and the one after that. But to do that, I need to access the position.

Anyway, the above code works, but the bold $c always returns 0 when it's actually printed when it literally /can't/ be zero, because in my examples it prints it 3 times, and each time it's a different position in the array. So anyone have any ideas why $c = 0 each time?

Gaz

EDIT: The $c in question isn't in bold, but has bold tags around it.
 Back to top
View user's profile Send private message Send e-mail Visit poster's website You must be logged in to rate posts

bazza
World Chat Champion



Joined: 27 Aug 2004
Karma :

PostPosted: 18:10 - 02 Dec 2006    Post subject: Reply with quote

Looks like $c never increments, just the while loop enclosing it, so $c gets reset back to 0 every time the while loop iterates.
____________________
"That's it. You people have stood in my way long enough. I'm going to clown college."
'98 Ducati 750SS, '08 Suzuki GSX650F ©2004-2014, Bazza's Harmless Banter
 Back to top
View user's profile Send private message You must be logged in to rate posts

Gazdaman
I did a trackday!!!



Joined: 12 Aug 2004
Karma :

PostPosted: 18:32 - 02 Dec 2006    Post subject: Reply with quote

I tested it, and c loops between 0 and 2. And the values change each time. There are only 3 values per line in the file it's coming from. So I think it reads the first line into the array (3 values) then the new line starts over again.

So I found a way around that.

Next thing.

$items = IMG_2543.JPG
$filenames[]="$items";

Should just add the value of $items to the array $filenames. But instead it makes each letter of $items a new field inside the $filenames array.

So the array looks

array[0] I
array[1] M
array[2] G
etc...

Gaz
 Back to top
View user's profile Send private message Send e-mail Visit poster's website You must be logged in to rate posts
Old Thread Alert!

The last post was made 19 years, 219 days ago. Instead of replying here, would creating a new thread be more useful?
  Display posts from previous:   
This page may contain affiliate links, which means we may earn a small commission if a visitor clicks through and makes a purchase. By clicking on an affiliate link, you accept that third-party cookies will be set.

Post new topic   Reply to topic    Bike Chat Forums Index -> The Geek Zone All times are GMT + 1 Hour
Page 1 of 1

 
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Read the Terms of Use! - Powered by phpBB © phpBB Group
 

Debug Mode: ON - Server: birks (www) - Page Generation Time: 0.11 Sec - Server Load: 0.82 - MySQL Queries: 13 - Page Size: 37.24 Kb