Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1197 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  [PHP] decalage d'id

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[PHP] decalage d'id

n°239698
otsem
Posté le 05-11-2002 à 10:43:28  profilanswer
 

bon je debute alors un peu d'indulgence :)
donc j'ai crée une base de donnée sous mysql, et j'ai fait le php avec dreamweaver mx(enfin c plutot dreamweaver qui m'as fait le php  :lol:) le but est d'avoir une liste de nom que je pourrais par la suite modifier par une interface graphique.
Au bout de chaque nom j'ais mis la variable edit.php?pageNum_cv=<?php echo $row_cv['id']; ?> le problème c'est que tout est decalé et pour l'index.php l'id 1 est a 0 (edit.php?pageNum_cv=0) comment faire pour remettre l'id 1 en 1 ?
ca serait cool de maider  :bounce:  :bounce:


Message édité par otsem le 05-11-2002 à 10:43:50
mood
Publicité
Posté le 05-11-2002 à 10:43:28  profilanswer
 

n°239707
Fred999
Rabat-joie
Posté le 05-11-2002 à 10:55:56  profilanswer
 

J'ai pas bien compris, c'est pas trop clair, tu peux détailler stp? [:bresse]

n°239713
otsem
Posté le 05-11-2002 à 11:02:58  profilanswer
 

ben chaque nom a un numéro atribué que j'appelle ici id, mais mon edit.php decale les id, lui il commence a 0 donc quand je veux editer le 1 er nom je tombe sur rien quand je veux editer le 2eme nom je tombe sur le premier etc....

n°239729
Sh@rdar
Ex-PhPéteur
Posté le 05-11-2002 à 11:49:23  profilanswer
 

montre ton code, sinon comment veux-tu qu'on te dise où se trouve l'erreur...


---------------
La musique c'est comme la bouffe, tu te souviens du restaurant dans lequel t'as bien mangé 20 ans plus tôt, mais pas du sandwich d'il y a 5 minutes :o - Plugin pour winamp ©Harkonnen : http://harko.free.fr/soft
n°239813
otsem
Posté le 05-11-2002 à 14:20:48  profilanswer
 

Code :
  1. Index.php 
  2. <?php require_once('Connections/cv.php'); ?>
  3. <?php
  4. mysql_select_db($database_cv, $cv);
  5. $query_cv = "SELECT * FROM cv";
  6. $cv = mysql_query($query_cv, $cv) or die(mysql_error());
  7. $row_cv = mysql_fetch_assoc($cv);
  8. $totalRows_cv = mysql_num_rows($cv);
  9. ?>
  10. <html>
  11. <head>
  12. <title>Document sans titre</title>
  13. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  14. </head>
  15. <body>
  16. <div align="center">
  17. <table border="1">
  18. <tr>
  19. <td>id</td>
  20. <td>nom</td>
  21. <td>email</td>
  22. <td>tel</td>
  23. <td>fax</td>
  24. <td>ad1</td>
  25. <td>ad2</td>
  26. </tr>
  27. <?php do { ?>
  28. <tr>
  29. <td><?php echo $row_cv['id']; ?></td>
  30. <td><?php echo $row_cv['nom']; ?></td>
  31. <td><?php echo $row_cv['email']; ?></td>
  32. <td><?php echo $row_cv['tel']; ?></td>
  33. <td><?php echo $row_cv['fax']; ?></td>
  34. <td><?php echo $row_cv['ad1']; ?><?php echo $row_cv['ad2']; ?></td>
  35. <td><a href="edit.php?pageNum_cv=<?php echo $row_cv['id']; ?>">wesh</a></td>
  36. </tr>
  37. <?php } while ($row_cv = mysql_fetch_assoc($cv)); ?>
  38. </table>
  39. </div>
  40. </body>
  41. </html>
  42. <?php
  43. mysql_free_result($cv);
  44. ?>


Code :
  1. edit.php 
  2. <?php require_once('Connections/cv.php'); ?>
  3. <?php
  4. $currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "" )
  6. {
  7. $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  8. switch ($theType) {
  9. case "text":
  10. $theValue = ($theValue != "" ) ? "'" . $theValue . "'" : "NULL";
  11. break;
  12. case "long":
  13. case "int":
  14. $theValue = ($theValue != "" ) ? intval($theValue) : "NULL";
  15. break;
  16. case "double":
  17. $theValue = ($theValue != "" ) ? "'" . doubleval($theValue) . "'" : "NULL";
  18. break;
  19. case "date":
  20. $theValue = ($theValue != "" ) ? "'" . $theValue . "'" : "NULL";
  21. break;
  22. case "defined":
  23. $theValue = ($theValue != "" ) ? $theDefinedValue : $theNotDefinedValue;
  24. break;
  25. }
  26. return $theValue;
  27. }
  28. $editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
  29. if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  30. $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
  31. }
  32. if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1" )) {
  33. $updateSQL = sprintf("UPDATE cv SET nom=%s, email=%s, tel=%s, fax=%s, ad1=%s, ad2=%s WHERE id=%s",
  34. GetSQLValueString($HTTP_POST_VARS['nom'], "text" ),
  35. GetSQLValueString($HTTP_POST_VARS['email'], "text" ),
  36. GetSQLValueString($HTTP_POST_VARS['tel'], "text" ),
  37. GetSQLValueString($HTTP_POST_VARS['fax'], "text" ),
  38. GetSQLValueString($HTTP_POST_VARS['ad1'], "text" ),
  39. GetSQLValueString($HTTP_POST_VARS['ad2'], "text" ),
  40. GetSQLValueString($HTTP_POST_VARS['id'], "int" ));
  41. mysql_select_db($database_cv, $cv);
  42. $Result1 = mysql_query($updateSQL, $cv) or die(mysql_error());
  43. $updateGoTo = "index.php";
  44. if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  45. $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
  46. $updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  47. }
  48. header(sprintf("Location: %s", $updateGoTo));
  49. }
  50. $maxRows_cv = 1;
  51. $pageNum_cv = 0;
  52. if (isset($HTTP_GET_VARS['pageNum_cv'])) {
  53. $pageNum_cv = $HTTP_GET_VARS['pageNum_cv'];
  54. }
  55. $startRow_cv = $pageNum_cv * $maxRows_cv;
  56. mysql_select_db($database_cv, $cv);
  57. $query_cv = "SELECT * FROM cv";
  58. $query_limit_cv = sprintf("%s LIMIT %d, %d", $query_cv, $startRow_cv, $maxRows_cv);
  59. $cv = mysql_query($query_limit_cv, $cv) or die(mysql_error());
  60. $row_cv = mysql_fetch_assoc($cv);
  61. if (isset($HTTP_GET_VARS['totalRows_cv'])) {
  62. $totalRows_cv = $HTTP_GET_VARS['totalRows_cv'];
  63. } else {
  64. $all_cv = mysql_query($query_cv);
  65. $totalRows_cv = mysql_num_rows($all_cv);
  66. }
  67. $totalPages_cv = ceil($totalRows_cv/$maxRows_cv)-1;
  68. $queryString_cv = "";
  69. if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
  70. $params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
  71. $newParams = array();
  72. foreach ($params as $param) {
  73. if (stristr($param, "pageNum_cv" ) == false &&
  74. stristr($param, "totalRows_cv" ) == false) {
  75. array_push($newParams, $param);
  76. }
  77. }
  78. if (count($newParams) != 0) {
  79. $queryString_cv = "&" . implode("&", $newParams);
  80. }
  81. }
  82. $queryString_cv = sprintf("&totalRows_cv=%d%s", $totalRows_cv, $queryString_cv);
  83. ?>
  84. <html>
  85. <head>
  86. <title>Document sans titre</title>
  87. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  88. </head>
  89. <body>
  90. <div align="center">
  91. <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  92. <table align="center">
  93. <tr valign="baseline">
  94. <td nowrap align="right">Id:</td>
  95. <td><?php echo $row_cv['id']; ?></td>
  96. </tr>
  97. <tr valign="baseline">
  98. <td nowrap align="right">Nom:</td>
  99. <td><input type="text" name="nom" value="<?php echo $row_cv['nom']; ?>" size="32"></td>
  100. </tr>
  101. <tr valign="baseline">
  102. <td nowrap align="right">Email:</td>
  103. <td><input type="text" name="email" value="<?php echo $row_cv['email']; ?>" size="32"></td>
  104. </tr>
  105. <tr valign="baseline">
  106. <td nowrap align="right">Tel:</td>
  107. <td><input type="text" name="tel" value="<?php echo $row_cv['tel']; ?>" size="32"></td>
  108. </tr>
  109. <tr valign="baseline">
  110. <td nowrap align="right">Fax:</td>
  111. <td><input type="text" name="fax" value="<?php echo $row_cv['fax']; ?>" size="32"></td>
  112. </tr>
  113. <tr valign="baseline">
  114. <td nowrap align="right">Ad1:</td>
  115. <td><input type="text" name="ad1" value="<?php echo $row_cv['ad1']; ?>" size="32"></td>
  116. </tr>
  117. <tr valign="baseline">
  118. <td nowrap align="right">Ad2:</td>
  119. <td><input type="text" name="ad2" value="<?php echo $row_cv['ad2']; ?>" size="32"></td>
  120. </tr>
  121. <tr valign="baseline">
  122. <td nowrap align="right"> </td>
  123. <td><input type="submit" value="Mettre à jour l'enregistrement"></td>
  124. </tr>
  125. </table>
  126. <p>
  127. <input type="hidden" name="MM_update" value="form1">
  128. <input type="hidden" name="id" value="<?php echo $row_cv['id']; ?>">
  129. </p>
  130. </p>
  131. </form>
  132. <p> 
  133. <table border="0" width="50%" align="center">
  134. <tr>
  135. <td width="23%" align="center"> <?php if ($pageNum_cv > 0) { // Show if not first page ?>  
  136. <a href="<?php printf("%s?pageNum_cv=%d%s", $currentPage, 0, $queryString_cv); ?>"><img src="First.gif" border=0></a>
  137. <?php } // Show if not first page ?> </td>  
  138. <td width="31%" align="center"> <?php if ($pageNum_cv > 0) { // Show if not first page ?>  
  139. <a href="<?php printf("%s?pageNum_cv=%d%s", $currentPage, max(0, $pageNum_cv - 1), $queryString_cv); ?>"><img src="Previous.gif" border=0></a>
  140. <?php } // Show if not first page ?> </td>  
  141. <td width="23%" align="center"> <?php if ($pageNum_cv < $totalPages_cv) { // Show if not last page ?>  
  142. <a href="<?php printf("%s?pageNum_cv=%d%s", $currentPage, min($totalPages_cv, $pageNum_cv + 1), $queryString_cv); ?>"><img src="Next.gif" border=0></a>
  143. <?php } // Show if not last page ?> </td>  
  144. <td width="23%" align="center"> <?php if ($pageNum_cv < $totalPages_cv) { // Show if not last page ?>  
  145. <a href="<?php printf("%s?pageNum_cv=%d%s", $currentPage, $totalPages_cv, $queryString_cv); ?>"><img src="Last.gif" border=0></a>
  146. <?php } // Show if not last page ?> </td>  
  147. </tr>
  148. </table></p>
  149. </div>
  150. </body>
  151. </html>
  152. <?php
  153. mysql_free_result($cv);
  154. ?>


si quelqu'un a une idée  :bounce:


Message édité par otsem le 05-11-2002 à 14:21:46
n°242725
cyruss
Posté le 10-11-2002 à 18:02:50  profilanswer
 

J'ai pas lu ton code mais asis tu que les tableaux commencent à 0 ?
Cela produit souvent un décalage pour les débutants.
 
++
 
cyruss
http://formation.kaptive.com/php/


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  [PHP] decalage d'id

 

Sujets relatifs
[PHP]musique midi, arrêt[PHP/MySQL]Comment je fais pour récupérer la valeur que sum() créé ?
[PHP]taille de texte[PHP] Nombre d'occurences d'un mot dans une chaine de caractères
[PHP]Installation PHP Nuke chez Free config.php lumieres plz :)[PHP] afficher dans 2 colonne
Besoin d'aide pour mon bout de code PHP[PHP] utiliser une fonction php dans le champ action d'une forme
Comment resizer une photo en PHP ?[PHP]{newbie neuneu} bricoler une table
Plus de sujets relatifs à : [PHP] decalage d'id


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR