flemingmike Posted August 9, 2010 Share Posted August 9, 2010 hi, im trying to say if field ARTIST = Eminem then do the following. here is my current code $hmm = simplexml_load_file('http://localhost/1.0/?method=player.getPlayQueue'); foreach($hmm->tracks->track as $tracks) { $artist = $tracks->artist; $title = $tracks->title; $album = $tracks->album; $index = $tracks->index; $id = $tracks->id; //If we submitted the form if('.$artist.'="eminem") { echo '<table border="0" width="70%" align="center">'; echo '<tr>'; i just need to know how to do the if(***) part. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/ Share on other sites More sharing options...
hcdarkmage Posted August 9, 2010 Share Posted August 9, 2010 You where close: if($artist == "eminem"){ //Do code stuffs } else { //Do other stuffs } Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097165 Share on other sites More sharing options...
flemingmike Posted August 9, 2010 Author Share Posted August 9, 2010 perfect. now if i want if 1 variable equals another, i tried this, but i think i screwed up in getting my variable for $index1 $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getActiveIndex'); foreach($hmm->player-command as $inde) { $pc = 'player-command' $index1 = $inde->value; $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getPlayQueue'); foreach($hmm->tracks->track as $tracks) { $artist = $tracks->artist; $title = $tracks->title; $album = $tracks->album; $index = $tracks->index; $id = $tracks->id; //If we submitted the form if($value = $index1) Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097170 Share on other sites More sharing options...
hcdarkmage Posted August 9, 2010 Share Posted August 9, 2010 To check if you got $index1 properly you could do something like: echo "This is Index1: ".$index1; anywhere after it has been defined. Plus you are not using the ==: $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getActiveIndex'); foreach($hmm->player-command as $inde) { $pc = 'player-command' $index1 = $inde->value; echo "This is Index1: ".$index1; //<--- Added for error checking $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getPlayQueue'); foreach($hmm->tracks->track as $tracks) { $artist = $tracks->artist; $title = $tracks->title; $album = $tracks->album; $index = $tracks->index; $id = $tracks->id; //If we submitted the form if($value = $index1) //<--- Here. Should be '==' not '=' Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097178 Share on other sites More sharing options...
flemingmike Posted August 9, 2010 Author Share Posted August 9, 2010 nope, error. i have a feeling its something small im missing Parse error: syntax error, unexpected T_VARIABLE in E:\Website\test\queue.php on line 24 <?PHP include("style.php"); $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.GetNowPlayingData'); foreach ($hmm->tracks as $tracks) { $ry = 'release-year'; $artist = $tracks->track->artist; $title = $tracks->track->title; $album = $tracks->track->album; $year = $tracks->track->$ry; echo '</br><font size="8" color="FFFF1A">Current Play Queue</font>'; echo '</br>Now Playing: <u><b><i>'.$artist.' - '.$title.' from '.$album.' ('.$year.')'; } $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getActiveIndex'); foreach($hmm->player-command as $inde) { $pc = 'player-command' $index1 = $inde->value; echo "This is Index1: "'.$index1.'; $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getPlayQueue'); foreach($hmm->tracks->track as $tracks) { $artist = $tracks->artist; $title = $tracks->title; $album = $tracks->album; $index = $tracks->index; $id = $tracks->id; //If we submitted the form if($value == $index1) { echo '<table border="0" width="70%" align="center">'; echo '<tr>'; echo '<td width="2%"><font color="FFFF1A"><u><i>'.$index.'.</td>'; echo '<td width="33%"><font color="FFFF1A"><u><i>'.$artist.'</td>'; echo '<td width="33%"><font color="FFFF1A"><u><i>'.$title.'</td>'; echo '<td width="32%"><font color="FFFF1A"><u><i>'.$album.'</td>'; echo '</tr>'; echo '<tr>'; echo '<td colspan="4"><hr></td>'; echo '</tr>'; echo '</table>'; } //If we haven't submitted the form else { echo '<table border="0" width="70%" align="center">'; echo '<tr>'; echo '<td width="2%">'.$index.'.</td>'; echo '<td width="33%">'.$artist.'</td>'; echo '<td width="33%">'.$title.'</td>'; echo '<td width="32%">'.$album.''.$index1.'</td>'; echo '</tr>'; echo '<tr>'; echo '<td colspan="4"><hr></td>'; echo '</tr>'; echo '</table>'; } } } ?> <iframe name="control" width="1" height="1" scrolling="no" frameBorder="0" src="http://www.google.ca"></iframe> Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097182 Share on other sites More sharing options...
hcdarkmage Posted August 9, 2010 Share Posted August 9, 2010 Well, you forgot a couple of things in your code: foreach($hmm->player-command as $inde) { $pc = 'player-command'; //<--- Forgot the semicolon $index1 = $inde->value; echo "This is Index1: ".$index1; //<--- Do not need the extra ' ' $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getPlayQueue'); Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097188 Share on other sites More sharing options...
flemingmike Posted August 9, 2010 Author Share Posted August 9, 2010 i made the adjustnemts, no more error, just doesnt display anthing from the (echo "This is Index1: ".$index1;) onward. <?PHP include("style.php"); $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.GetNowPlayingData'); foreach ($hmm->tracks as $tracks) { $ry = 'release-year'; $artist = $tracks->track->artist; $title = $tracks->track->title; $album = $tracks->track->album; $year = $tracks->track->$ry; echo '</br><font size="8" color="FFFF1A">Current Play Queue</font>'; echo '</br>Now Playing: <u><b><i>'.$artist.' - '.$title.' from '.$album.' ('.$year.')'; } $hmm1 = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getActiveIndex'); foreach($hmm1->$pc as $inde) { $pc = 'player-command'; $index1 = $inde->value; echo "This is Index1: ".$index1; $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getPlayQueue'); foreach($hmm->tracks->track as $tracks) { $artist = $tracks->artist; $title = $tracks->title; $album = $tracks->album; $index = $tracks->index; $id = $tracks->id; //If we submitted the form if($value == $index1) { echo '<table border="0" width="70%" align="center">'; echo '<tr>'; echo '<td width="2%"><font color="FFFF1A"><u><i>'.$index.'.</td>'; echo '<td width="33%"><font color="FFFF1A"><u><i>'.$artist.'</td>'; echo '<td width="33%"><font color="FFFF1A"><u><i>'.$title.'</td>'; echo '<td width="32%"><font color="FFFF1A"><u><i>'.$album.'</td>'; echo '</tr>'; echo '<tr>'; echo '<td colspan="4"><hr></td>'; echo '</tr>'; echo '</table>'; } //If we haven't submitted the form else { echo '<table border="0" width="70%" align="center">'; echo '<tr>'; echo '<td width="2%">'.$index.'.</td>'; echo '<td width="33%">'.$artist.'</td>'; echo '<td width="33%">'.$title.'</td>'; echo '<td width="32%">'.$album.''.$index1.'</td>'; echo '</tr>'; echo '<tr>'; echo '<td colspan="4"><hr></td>'; echo '</tr>'; echo '</table>'; } } } ?> <iframe name="control" width="1" height="1" scrolling="no" frameBorder="0" src="http://www.google.ca"></iframe> Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097195 Share on other sites More sharing options...
hcdarkmage Posted August 9, 2010 Share Posted August 9, 2010 I think it may be that you are not defining the $pc before you call it: foreach($hmm1->$pc as $inde) { $pc = 'player-command'; $index1 = $inde->value; You may want to try this: $pc = 'player-command'; foreach($hmm1->$pc as $inde) { $index1 = $inde->value; or foreach($hmm1->player-command as $inde) { $index1 = $inde->value; Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097200 Share on other sites More sharing options...
flemingmike Posted August 9, 2010 Author Share Posted August 9, 2010 yep, thats exactly what what was. i got that sorted out now, but its not displaying the way i hoped. i wanted it to change the color of the array row that $index = $index1 Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097205 Share on other sites More sharing options...
hcdarkmage Posted August 9, 2010 Share Posted August 9, 2010 you forgot to close your style tags: if($value == $index1) { echo '<table border="0" width="70%" align="center">'; echo '<tr>'; echo '<td width="2%"><font color="FFFF1A"><u><i>'.$index.'</i></u></font></td>'; //<--- Here echo '<td width="33%"><font color="FFFF1A"><u><i>'.$artist.'</i></u></font></td>'; //<--- Here echo '<td width="33%"><font color="FFFF1A"><u><i>'.$title.'</i></u></font></td>'; //<--- Here echo '<td width="32%"><font color="FFFF1A"><u><i>'.$album.'</i></u></font></td>'; //<--- And Here echo '</tr>'; echo '<tr>'; echo '<td colspan="4"><hr></td>'; echo '</tr>'; echo '</table>'; Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097209 Share on other sites More sharing options...
flemingmike Posted August 9, 2010 Author Share Posted August 9, 2010 nope, no go. here my new code: <?PHP include("style.php"); $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.GetNowPlayingData'); foreach ($hmm->tracks as $tracks) { $ry = 'release-year'; $artist = $tracks->track->artist; $title = $tracks->track->title; $album = $tracks->track->album; $year = $tracks->track->$ry; echo '</br><font size="8" color="FFFF1A">Current Play Queue</font>'; echo '</br><font size ="4">Now Playing: <u><b><i>'.$artist.' - '.$title.' ('.$year.')'; } $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getActiveIndex'); $pc = 'player-command'; foreach($hmm->$pc as $inde) { $index1 = $inde->value; } $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.getPlayQueue'); foreach($hmm->tracks->track as $tracks) { $artist = $tracks->artist; $title = $tracks->title; $album = $tracks->album; $index = $tracks->index; $id = $tracks->id; if($index == $index1) { echo '<table border="0" width="70%" align="center">'; echo '<tr>'; echo '<td width="2%"><font color="FFFF1A"><u><i>'.$index.'</i></u></font></td>'; echo '<td width="33%"><font color="FFFF1A"><u><i>'.$artist.'</i></u></font></td>'; echo '<td width="33%"><font color="FFFF1A"><u><i>'.$title.'</i></u></font></td>'; echo '<td width="32%"><font color="FFFF1A"><u><i>'.$album.'</i></u></font></td>'; echo '<td width="2%"><a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.playFileAtIndex&index='.$index.'">Play</a> </td>'; echo '</tr>'; echo '<tr>'; echo '<td colspan="5"><hr></td>'; echo '</tr>'; echo '</table>'; } else { echo '<table border="0" width="70%" align="center">'; echo '<tr>'; echo '<td width="2%">'.$index.'.</td>'; echo '<td width="32%">'.$artist.'</td>'; echo '<td width="32%">'.$title.'</td>'; echo '<td width="32%">'.$album.'</td>'; echo '<td width="2%"><a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.playFileAtIndex&index='.$index.'">Play</a> </td>'; echo '</tr>'; echo '<tr>'; echo '<td colspan="5"><hr></td>'; echo '</tr>'; echo '</table>'; } } ?> <iframe name="control" width="1" height="1" scrolling="no" frameBorder="0" src="http://www.google.ca"></iframe> Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097211 Share on other sites More sharing options...
flemingmike Posted August 9, 2010 Author Share Posted August 9, 2010 now im frustrated.... it works with saying if ($index == 2), but it doesnt work when saying if($index == $index1) when $index1 is equal to 2. Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097222 Share on other sites More sharing options...
samshel Posted August 9, 2010 Share Posted August 9, 2010 try type casting them to integer: if((int) $index == (int) $index1) Quote Link to comment https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097232 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.