Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Loop is being very confusing...
Old 06-18-2011, 03:04 PM PHP Loop is being very confusing...
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Hello,

I have a very simple loop, with a very simple if statement in it. However, my script is returning "text is not text". WTF?

Here is the code, and the sample from the database it is using:

Database:
Code:
How are you?|text
Are you well?|dropdown>Yes:No
Rate this survey!|rating>1:10
PHP:
PHP Code:
        //... other stuff //
        
$entities=explode("\n",*Database stuff in above box*); //Explodes the database content above by newlines
        
$i=0//counter
        
while($e=$entities[$i++]) {
            
$parts=explode("|",$e);
                        
//Assings names to the variables created with the split above 
            
list($question,$type)=$parts;

            echo 
"<h3>$question</h3>";
            
                        
//Annoying part that just returns an oxymoron...
            
if ($type=="text") {
                echo 
"This is text!";
            }
            else {
                echo 
"$type is not text";
            }
            
            echo 
"<br /><br />";
        } 
Can somebody please explain why this is happening? I've also used a foreach statement, but that didn't work either.

Thanks!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 06-18-2011 at 03:07 PM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-18-2011, 03:45 PM Re: PHP Loop is being very confusing...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Try:
PHP Code:
if(trim($type) == 'text'
I'm guessing the problem is that there is still a return character ( \r ) remaining after you split the string.

Just curious, is there a reason you're not using a proper database?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-18-2011, 04:30 PM Re: PHP Loop is being very confusing...
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Wow, thanks Null! You've solved one of my age-old problems!

I'm not using a proper database because the amount of each line would vary far too much to use database integration. Each variable is variable, so to speak.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 06-18-2011, 06:19 PM Re: PHP Loop is being very confusing...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Physicsguy View Post
I'm not using a proper database because the amount of each line would vary far too much to use database integration. Each variable is variable, so to speak.
Can't say I understand your meaning, but if you're set on using a flat file you may want to consider a better format for storing the data such as XML or json. You'll be less likely to run into problems like the one above.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-18-2011, 08:05 PM Re: PHP Loop is being very confusing...
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
That's true, thanks!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Loop is being very confusing...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.69927 seconds with 12 queries