Jump to content

[SOLVED] if not working


graham23s

Recommended Posts

Hi Guys,

 

i thought this was pretty simple but alas it's not working lol, i'm trying to display the users year they have selected if it matched the years in array it gets "selected" but its not for doing it

 

code:

 

<?php
#################################################
# editcredits.php
#################################################

  ## edit id
  $editid = $_GET['id'];
  
  ## vars
  $years = range(1930,2007);
  
  ## grab the relevant details from mysql
  $queryedit = "SELECT * FROM `userscredits` WHERE `id`='$editid'";
  $resultedit = mysql_query($queryedit);
  $row = mysql_fetch_array($resultedit);
  
  ## vars
  $year = $row['year'];
  
  echo $year; // 1948
  echo $years; // array
  
    echo ('<br /><div style="border: 1px solid black;padding:10px; background: #e8f1fa; width: 50%; color: #000000; font-size: 12px;"><b>Edit your exhisting credit on this page.</b></div><br />');
    echo ('<form action="credits.php" method="post">');
    echo ("<table class=\"sub_table\" align=\"left\" width=\"500\" border=\"1\" bordercolor=\"#000000\" cellpadding=\"5\" cellspacing=\"0\">");
    echo ("<tr>");
    echo ("<td colspan=\"2\" class=\"header_boxes\" align=\"left\"><span class=\"prof_head\">Edit Credits</span></td>");
    echo ("</tr>");
    echo ("<tr>");
    echo ("<td align=\"right\"><b>Year</b></td><td align=\"left\"><select name=\"year\">");
    foreach ($years as $value) {    
    echo "<option value=\"{$value}\"";   
    if($years == $year) {   
     echo 'selected';    
    }
     echo ">{$value}</option>";     
    }
    echo ("</select>");
    echo ("</tr>");
    echo ("</td>");
    echo ("</table>");
?>

 

i can't see anything wrong, the year echoes out at 1948 fine but does't get selected in the if statement

 

can anyone see the problem at all?

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/77362-solved-if-not-working/
Share on other sites

Hi Mate,

 

really? thats weird iv used this code numerous other times with out the in_array() function , this is the first time iv had problems lol

 

still never worked, instead of 1930 (where the range starts) it displayed 2007 where the range ends for some reason.

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/77362-solved-if-not-working/#findComment-391659
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.