TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-26-2008, 02:24 PM   #1 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default Problem with Arrays

Im having a small problem with arrays, this code used to work, but now i get something like

Code:
Notice: Undefined offset: 1 on line 69

Notice: Undefined offset: 2 on line 77

Notice: Undefined offset: 3 on line 85
you can view the errors here

Heres the code, in short it gets the categories from the db, and splits them into 4 columns. Im pretty sure the error is because im trying to pull from an empty array. The errors only occur when the amount of categories are not directly divisable by 4.

Last edited by CoryMathews : 02-27-2008 at 02:05 PM.
CoryMathews is offline  
Reply With Quote
Old 02-26-2008, 04:17 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

That's a crazy bit of PHP code. What the hell is going on? And why are you doing it like that? And what does it achieve?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-26-2008, 07:42 PM   #3 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

lol it takes a list of categories returned from a db query. Then i am arranging it in 4 columns. But i want them in alpha order going down instead of across. So i had to come up with this crazy work around. I couldnt figure out another way to do it.

But the problem is when it trys to push on an empty value on these lines

Code:
for ($x=0;$x<$tot_rows;$x++) { array_push($byFours1, $subs[$y]); $y++; }
there is nothing left in $subs[] to add. I have tried isset, i have tried seeing if $y is higher then the number of rows returned but still no luck.

I hope thats a little more clear.
CoryMathews is offline  
Reply With Quote
Old 02-26-2008, 09:13 PM   #4 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

Do you have your server set to E_STRICT? and ++$var us faster then then $var++
TlcAndres is offline  
Reply With Quote
Old 02-26-2008, 09:53 PM   #5 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Like TlcAndress just said, maybe you should try using error_reporting( E_ALL ^ E_NOTICE ); for your debugging.

So, what you want to do is retrieve a 1D (one dimensional array as we call it at work) and filter every value depending on the row name. For example;
PHP Code:
$queryFinal $queryRow[['fieldcat']['fieldname']] = $queryRow['queryvalue']; 
If I am right, this is what you are trying to accomplish?

Else, from another perspective, you want to sort every value? Or push it into 4 different arrays?
You should take a look at PHP: Arrays - Manual. That might solve some of your issues. I advise you to read them carefully since I use a lot of them for different tasks.

I hope this helps.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 02-26-2008, 11:47 PM   #6 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Use a query to fetch the data already ordered, put all that data into one big array, then use array_slice to "cut" the big array into 4 pieces...this is a less trickier way to achieve what I believe you want to achieve. There are other ways, but I'm too tired to come up with a more efficient solution right now...
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 02-27-2008, 02:04 PM   #7 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

Well i finally figured it out. I ended up just adding '' to the array if there were not any more values to add. Thanks for the suggestions though.
CoryMathews is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


All times are GMT. The time now is 10:26 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design