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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.