Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] - update checkboxa / update id
Forum PHP.pl > Forum > Przedszkole
andy84
hej mam dwa skrypty pierwszy
edit.php
do wprowadzania zmian do rekordu
dziala dobrze dla wszystkich pol poza chceckbox oraz ID - ID chce updatowac aby moc przesowac rekordy w kolejnosci - chyba ze ktos zna leprzy sposob chetnie sie naucze czegos nowego smile.gif
co do checkbox ustawilem go tak zeby zapisywal sie w bazie gdy jest zaznaczony jako '1' gdy jest nie zaznaczony wprowadza '0'
drugi
update.php


edit.php
  1. <?php
  2. include('header.php');
  3. include('../top.php'); 
  4. $id=$_GET['id'];
  5. include("../../../config.inc.php");
  6. mysql_connect($host,$user,$password);
  7. @mysql_select_db($database) or die ("Unable to select database");
  8. $query="SELECT * FROM portfolio WHERE id='$id'";
  9. $result=mysql_query($query);
  10. $num=mysql_num_rows($result);
  11. $i=0;
  12. while ($i < $num) {
  13. $id = mysql_result($result,$i,"id");
  14. $name = mysql_result($result,$i,"name");
  15. $path = mysql_result($result,$i,"path");
  16. $description = mysql_result($result,$i,"description");
  17. $string = mysql_result($result,$i,"string");
  18. $port_url = mysql_result($result,$i,"port_url");
  19. if($string=='1')
  20. {
  21. $string='CHECKED';
  22. }
  23. else{
  24. $string='';
  25. }
  26.  
  27.  
  28. ?>
  29. <div align="center">
  30. <form method="post" action="update.php">
  31. <table width="95%" border="1" id="tabelka-frame">
  32. <tr>
  33. <td width="22%" valign="top"><a href="../../control.php?location=listportfolio" class="link">List all entrees</a></td>
  34. <td><div id="panelcont" align="right">URL:</div></td>
  35. <td><div id="panelcont" align="left"><input name="port_url" type="text" value="<? echo "$port_url"; ?>" size="45" maxlength="50" class="box" />
  36. ID: <input name="up_id" type="text" value="<? echo "$id"; ?>" size="5" maxlength="50" class="box" /></div></td>
  37. </tr>
  38. <tr>
  39. <td valign="top"><img src="../../../graphic/portfolio/<? echo "$name"; ?>" /></td>
  40. <td width="6%" valign="top"><div id="panelcont">short description:</div></td>
  41. <td><textarea name="description" cols="45" rows="12" class="box" ><? echo "$description"; ?></textarea></td>
  42. </tr>
  43. <tr>
  44. <td valign="top"><br /></td>
  45. <td colspan="2"><br /><br />
  46. <div id="panelcont">
  47. <input type="checkbox" name="tablica[0]" value="1" <? echo "$string"; ?> />
  48. - Mark it to make this portfolio visable on website</div></td>
  49. </tr>
  50. <tr>
  51. <td>&nbsp;</td>
  52. <td colspan="2"><input name="upload" type="submit" class="box" id="upload" value=" Submit " /></td>
  53. </tr>
  54. </table>
  55. </form>
  56. </div>
  57.  
  58.  
  59. <?php
  60. $i++;
  61. }
  62. include('bottom.php');
  63. include('../../footer.php');
  64. ?>

update.php
  1. <?php
  2. $up_id = $_POST['up_id'];
  3. $description = $_POST['description'];
  4. $port_url = $_POST['port_url'];
  5.  
  6. include ("../../../config.inc.php");
  7. $linka = mysql_connect($host,$user,$password);
  8. @mysql_select_db($database, $linka) or die( "Unable to select database");
  9.  
  10. $array = $_POST['tablica'];
  11. $string = NULL;
  12. for( $i = 0; 
  13. $i <= 0; $i++ ) 
  14. {
  15. if( ! isset ( $array[ $i ] ) )
  16. $string .= 0;
  17. else
  18. $string .= $array[ $i ];
  19. }
  20. $query = "UPDATE portfolio SET id='$up_id',description='$description',port_url='$port_url',string='$string' WHERE id='$id'";
  21. mysql_query($query);
  22. echo "Data updated succesfuly !";
  23. ?>
sagittariuspl
update id, który jest kluczem? ciekawe... zrób sobie jeszcze jedną kolumnę, która bedzie zawierała numer pozycji w menu i w zapytaniu sortuj według tego wyniki
andy84
Cytat(sagittariuspl @ 20.05.2007, 10:39:46 ) *
update id, który jest kluczem? ciekawe...

no wlasnie tez mi sie to nie trzymalo kupy za bardzo smile.gif
Cytat
zrób sobie jeszcze jedną kolumnę, która bedzie zawierała numer pozycji w menu i w zapytaniu sortuj według tego wyniki

to pomoglo dzieki

jak ktos bedzie mial okazje zucic okiem na tego checkboxa jeszce dzieki
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.