Jump to content

if / else question


flemingmike

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097170
Share on other sites

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 '='

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097178
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097182
Share on other sites

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'); 

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097188
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097195
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097200
Share on other sites

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>';

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097209
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/210250-if-else-question/#findComment-1097211
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.