Ver Mensaje Individual
  #5 (permalink)  
Antiguo 14/09/2009, 16:44
majony
(Desactivado)
 
Fecha de Ingreso: diciembre-2008
Mensajes: 421
Antigüedad: 15 años, 4 meses
Puntos: 0
Sigo sin poder entender me guie en tu ejemplo pero la idea en q en mi tabka noticias es un campo categorias y al momento de editar pongo tu codigo de ejemplo con algunas modificaciones tengo serio errores cono este
Código php:
Ver original
  1. <td>Categoria:</td>
  2.           <td>
  3.           <?php
  4.           $query1 = mysql_query("SELECT * FROM noticia") or die(mysql_error());
  5.            $row2 = mysql_fetch_assoc($query2);
  6.           while ($row1 = mysql_fetch_assoc($query1)) {
  7.             $s = ($row1["categoria"] == $row2["categoria"] ? "selected" : "");
  8.             echo "<option value='".$row1["categoria"]."' ".$s.">".$row1["categoria"]."</option>";
  9. }
  10.  
  11.          
  12.          
  13.           ?>
  14.           </td>
  15. El error
  16.    
  17. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\proyecto_cisco\modulos\noticias\vistas\editar.html.php on line 51
  18. sub8primerasub8femeninomutualsub20sub15sub12General

No entiendo como deberia ser para que cuando edite alguna noticia en mi select me aparezca o me muestre la categoria con la que habia insertado la noticia y no me muestra directamente la categoria general hice esto: dentro del select
Código php:
Ver original
  1. <?php
  2. include('conectar.php');
  3. $link = Conectarse();
  4. $id = $_GET['id'];
  5. $result=mysql_query("Select * From noticia WHERE id='$id' LIMIT 1");
  6. $row=mysql_fetch_array($result);
  7. ?>
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  11. <title>Insertar Noticias </title>
  12. </head>
  13. <body>
  14. <table border="0" cellspacing="0" cellpadding="0" width="500" align="center">
  15.     <tr>
  16.    
  17.       <form action="index.php?mod=noticias&pag=editar_1" method="post" name="frmNoticia" >
  18.        <input name="id" type="hidden" value="<?php echo $row['id']; ?>" />
  19.      
  20.         <table width="90%" border="1">
  21.        
  22.           <tr>
  23.             <td>Noticia:</td>
  24.             <td><textarea name="txt_textocompleto" cols="30" class="mceEditor"><?php echo $row['texto_completo']; ?> </textarea>
  25.             </td>
  26.           </tr>
  27.          
  28.           <tr>
  29.             <td>Estado de Publicacion:</td>
  30.             <td><input type="checkbox" name="chbx_estado" value="1" <?php if($row['estado']==1){echo "checked=checked"; }?>/>(Si la Noticia será Publicada )
  31.             </td>
  32.           </tr>
  33.           <tr>
  34.           <td>Categoria:</td>
  35.           <td>
  36.           <?php
  37.            
  38.             $query1 = mysql_query("SELECT * FROM noticia") or die(mysql_error());
  39.             $query2 = mysql_query("SELECT * FROM noticia WHERE id = '$id '") or die(mysql_error());
  40.             //$result=mysql_query("Select * From noticia WHERE id='$id' LIMIT 1");
  41.             $row2 = mysql_fetch_assoc($query2);
  42.             while ($row1 = mysql_fetch_assoc($query1)) {
  43.               $s = ($row1["categoria"] == $row2["categoria"] ? "selected" : "");
  44.               echo "<option value='".$row1["categoria"]."' ".$s.">".$row1["categoria"]."</option>";
  45.             }
  46.  
  47.           ?>
  48.           <OPTION VALUE="General">General</OPTION>
  49.          <OPTION VALUE="sub7">Sub 7</OPTION>
  50.          <OPTION VALUE="sub9">Sub 9</OPTION>
  51.          <OPTION VALUE="sub11">Sub 11</OPTION>
  52.          <OPTION VALUE="sub13">Sub 13</OPTION>
  53.          <OPTION VALUE="sub15">Sub 15</OPTION>
  54.          <OPTION VALUE="sub17">Sub 17</OPTION>
  55.          <OPTION VALUE="sub19">Sub 19</OPTION>
  56.          <OPTION VALUE="primera">Primera "A"</OPTION>
  57.          <OPTION VALUE="primerab">Primera "B"</OPTION>
  58.          <OPTION VALUE="primeraAS">Primeras Ascenso</OPTION>
  59.          <OPTION VALUE="segundaAS">Segundas Ascenso</OPTION>
  60.          <OPTION VALUE="femenino">Femenino </OPTION>
  61.          <OPTION VALUE="mutual">Mutual</OPTION>
  62. </SELECT>
  63.           </td>
  64.           </tr>
  65.  
  66. </table>
  67.  
  68. </body>
  69. </html>
Pero lo unico que logro cuando edito una noticia es que me muestra todos los campos correctos pero ahora en la parte del select me sale esto:
sub8primerasub8femeninomutualsub20sub15sub12Genera l General Sub 7 Sub 9 Sub 11 Sub 13 Sub 15 Sub 17 Sub 19 Primera "A" Primera "B" Primeras Ascenso Segundas Ascenso Femenino Mutual

Ya puede hacer todo lo logico para que en mi select option me muestre la categoria que habia seleccionado por medio de este duda:
http://www.forosdelweb.com/f18/edita...eccion-722200/

Pero hice esto
Código php:
Ver original
  1. <td>Categoria:</td>
  2.           <td>
  3.          
  4.          
  5.         <SELECT NAME='categoria'>
  6.         <OPTION value ="General" <?php if ($row['categoria'] == 'General') { echo "selected"; } ?>>General</OPTION>
  7.         <OPTION value ="sub7" <?php if ($row['categoria'] == 'Sub7') { echo "selected"; } ?>>Sub 7</OPTION>
  8.         <OPTION value ="sub9" <?php if ($row['categoria'] == 'Sub9') { echo "selected"; } ?>>Sub 9</OPTION>
  9.         <OPTION value ="sub11"<?php if ($row['categoria'] == 'Sub11') { echo "selected"; } ?>>Sub 11</OPTION>
  10.         </SELECT >
  11.  
  12.        <?php echo $row['categoria']; ?>
  13.           </td>
  14.           </tr>

Cuando hago click en editar me muestra todos los datos de texto y en <?php echo $row['categoria']; ?> me imprime correctamente la categoria que habia sleccionado pero no me muestra dentro de mi select esa categoria ¿En que estoy fallando ?

Última edición por GatorV; 15/09/2009 a las 11:02