Problem with selected subcategory when editing Category items

Posted by jasmine on Stack Overflow See other posts from Stack Overflow or by jasmine
Published on 2010-04-03T11:17:32Z Indexed on 2010/04/03 11:23 UTC
Read the original article Hit count: 193

Filed under:

I want to item's subcatory selected when editing category:

<?php
  function categoryFormEdit()
 {
  $ID = $_GET['id'];
  $query = "SELECT * FROM category WHERE id= $ID";
  $result = mysql_query($query);
  $row = mysql_fetch_array($result);
  $subcat = $row['subcat'];
  $text = '<div class="form">
        <h2>Add new category</h2>
          <form method="post" action="?page=editCategory">
              <ul>
                  <li><label>Kategori</label></li>
                  <li><input type="text" class="inp" name="cname" value="' . $row['name'] . '"></li>
                  <li><label> Aç&#305;klama</label></li>
                  <li><textarea class="inx" rows="10" cols="40" name="kabst">' . $row['description'] . '</textarea></li>
                  <li>
                    <select class="ins" name="kselect">
                      <option value="1">Aktif</option>
                      <option value="0">Pasif</option>
                    </select>
                  </li>
                  <li>Üst kategorisi</li>
                  <li>
                    <select class="ins" name="subsl">';
                        $s = "SELECT * FROM category";
                        $q = mysql_query($s);
                        while ($r = mysql_fetch_assoc($q)) {
                            $text .= '<option value="' . $r['id'] . '" ' . sQuery() . '>' . $r['name'] . '</option>';
                        }
                    $text .= '</select>
                 </li>

                     <li>Home page:</li> 
                     <li>
                       <input type="radio" value="1" name="kradio"> Active
                       <input type="radio" value="0" name="kradio"> YPassive
                     </li>
                     <li><input type="submit" class="int" value="ekle" name="ksubmit"></li>
                </ul>
            </form>
        </div>';
  return $text;
 }

 function sQuery()
 {
    if ($r['id'] == $subcat) {
      $t = "selected";
    } 
    else {

      $t = "";
    }
   return $t;
  }
?>

With above code there is not selected item. What is wrong in my script? Thanks in advance

© Stack Overflow or respective owner

Related posts about php