Jump to content

Exploding data and putting it through an IF loop...


Jim R

Recommended Posts

I have a list of colleges, and I've exploded the data to create a list.  The player will inevitably commit ($line['commit']) to a college, which will be reflected in a few places, but I also want an * next to that college in the list. 

 

(I've already echoed $line['commit'] just above the code below to note it's getting it properly.)

// Turn CSV into unordered list
					$college = $line['list'];
					$college = explode(",",$college);
					asort($college);
					foreach ($college as $collegeList) {
					echo '<tr><td>' . $collegeList;
						if ($collegeList == $line['commit']) {
						 echo '*';
						}
					echo '</td></tr>';	

if ($collegeList == $line['commit']) {

                         echo '*';

 

...that doesn't echo any *.  

 

 

if ($collegeList = $line['commit']) {

                         echo '*';

 

...puts an * by each item on the list. 

 

 

Link to comment
Share on other sites

One = is for assignment, two ==s is for comparison. You want a comparison.

 

If the star isn't showing up then that means one or both of the values that you think should be equal, aren't.

 

Working with a CSV? How did you load the lines of the file? Is either the "list" or "commit" values the last one on the line?

Link to comment
Share on other sites

Commit is just one value:  

 

Michigan State

 

List is:  

 

Butler, Xavier, Illinois, Michigan State, Ohio State

 

 

(written as is, no other punctuation)

 

Is it possible it's reading Michigan State with a space ahead of it?  

 

 

EDIT:  That's what it was!  It was comparing Michigan State to _Michigan State.  

 

These are the bittersweet moments of being a novice coder.   :stoopid:  :happy-04:

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.