Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [mysq]Dodanie kodu do tabeli
Forum PHP.pl > Forum > Przedszkole
fix
  1. DROP TABLE IF EXISTS `premium`;
  2. CREATE TABLE `premium` (
  3. `id` int(11) NOT NULL DEFAULT '0',
  4. `points` int(11) NOT NULL DEFAULT '0'
  5. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;



Jak mam do tego dodaæ 1000 kodów (kody.wapacz.pl) ?
MMX3
  1. INSERT INTO `premium`(`id`,`points`) VALUES ('$id', '$points');


Samo zapytanie...

a mo¿esz sobie zrobiæ jakiego¶ while co bêdzie ci pobieraæ dane z txt, i wk³ada³ w 1 zapytanie
a potem mysql_query i koniec.

np:
  1. <?php
  2. $sql = "INSERT INTO `premium`(`id`,`points`) VALUES ;";
  3. $fuchwyt = fopen("plik.txt", "r");
  4. $tresc = fread($fuchwyt, filesize("plik.txt"));
  5. $tresc = explode($tresc, "n");
  6. for($i=0; $i<count($tresc); $i++) {
  7.  $tmp = explode($tresc[$i], " "); // np. spacja
  8.  $sql .= "('$id', '$points'), ";
  9. }
  10. substr($sql, 0, strlen($sql)-1); // obcinamy ostatni przecinek
  11. mysql_connect("localhost", "root", "droot");
  12. if(mysql_query($sql))
  13. echo("dodano");
  14. else
  15. echo("bula");
  16. ?>

Pozdro
fix
Dam ca³y skrypt smile.gif

  1. <?php
  2. /**
  3.  *  File functions:
  4.  *  Clean city and earn money
  5.  *
  6.  *  @name  : premium.php
  7.  *  @copyright : (C) 2004-2005 EE Team for Vallheru Engine
  8.  *  @author  : Klaus Korner <albitos.snape@gmail.com>
  9.  *  @version : 1.0.7
  10.  *  @since : 30.10.2006
  11.  *
  12.  */
  13.  
  14. //
  15. //
  16. //  This program is free software; you can redistribute it and/or modify
  17. //  it under the terms of the GNU General Public License as published by
  18. //  the Free Software Foundation; either version 2 of the License, or
  19. //  (at your option) any later version.
  20. //
  21. //  This program is distributed in the hope that it will be useful,
  22. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. //  GNU General Public License for more details.
  25. //
  26. //  You should have received a copy of the GNU General Public License
  27. //  along with this program; if not, write to the Free Software
  28. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. //
  30. // 
  31.  
  32. $title = "Punkty premium";
  33. require_once("includes/head.php");
  34.  
  35. /**
  36. * Get the localization for game
  37. */
  38. require_once("languages/".$player -> lang."/premium.php");
  39.  
  40. $arrBonus = array('credits' => 100000, 'energy' => 50, 'platinum' => 1000);
  41. $objBonus = $db -> Execute('SELECT points FROM premium WHERE id='.$player -> id);
  42.  
  43.  
  44. if (!isset($_GET['action'])) 
  45. {
  46. $_GET['action'] = '';
  47. $smarty -> assign(array("Landinfo" => LAND_INFO,
  48. "Landinfo2" => GOLD_COINS,
  49. "Awork" => A_WORK,
  50. "Points" => $objBonus -> fields['points'],
  51. "Times" => TIMES, 
  52. "Codeinfo" => CODE_INFO));
  53. } 
  54. elseif(isset($_GET['action']) && $_GET['action'] == 'work')
  55. {
  56.  
  57. if (!isset($_POST['amount']) || !isset($_POST['what'])) 
  58. {
  59. error(NO_AMOUNT);
  60. }
  61.  
  62. if (!ereg("^[1-9][0-9]*$", $_POST['amount']) || !array_key_exists($_POST['what'], $arrBonus)) 
  63. {
  64. error (ERROR);
  65. }
  66.  
  67. if ($objBonus -> fields['points'] < $_POST['amount']) 
  68. {
  69. error (NO_ENERGY);
  70. }
  71.  
  72. $db -> Execute("UPDATE players SET ".$_POST['what']."=".$_POST['what']."+".$arrBonus[$_POST['what']]*$_POST['amount']." WHERE id=".$player -> id);
  73. $db -> Execute("UPDATE premium SET points=points-".$_POST['amount']." WHERE id=".$player -> id);
  74.  
  75. $smarty -> assign(array("Gain" => $arrBonus[$_POST['what']], 
  76. "Amount" => $_POST['amount'],
  77. "Inwork" => IN_WORK,
  78. "Inwork2" => IN_WORK2,
  79. "Goldcoins" => GOLD_COINS,
  80. "Aback" => A_BACK));
  81. }
  82. elseif(isset($_GET['action']) && $_GET['action'] == 'add')
  83. {
  84. $_POST['code'] = $db -> qstr($_POST['code']);
  85. $objCheck = $db -> Execute('SELECT code FROM codes WHERE code='.$_POST['code']);
  86.  
  87. if(isset($objCheck -> fields['code']))
  88. {
  89. $kop = $db -> Execute('SELECT id FROM premium WHERE id='.$player -> id);
  90. if (!$kop -> fields['id']) 
  91. {
  92. $db -> Execute("INSERT INTO premium (id, points) VALUES(".$player -> id.",10)");
  93. } 
  94. else 
  95. {
  96. $db -> Execute("UPDATE premium SET points=points+10 WHERE id=".$player -> id);
  97. }
  98. $db -> Execute('DELETE FROM codes WHERE code='.$_POST['code']);
  99. error('Wymieni³e¶ kod na punkty premium.');
  100. }
  101. else
  102. {
  103. error(NO_CODE);
  104. }
  105. }
  106.  
  107. /**
  108. * Assign variables to template and display page
  109. */
  110. $smarty -> assign ("Action", $_GET['action']);
  111. $smarty -> display ('premium.tpl');
  112.  
  113. require_once("includes/foot.php");
  114. ?>
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.