Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [PHP]modyfikacja skryptu
Forum PHP.pl > Forum > Przedszkole
yacko
Witam. Z PHP styczno¶æ mam od nie dawna. Nie umiem wiele, a wrecz prawie nic. Ale do rzeczy.
Chce zedytowaæ pewien skrypt RPG. Nawet dobrze mi idzie, ale napotka³em problem.
To jest oryginalny kod:


  1. <?php
  2. /*
  3. MCCodes Lite
  4. itemuse.php Rev 1.0.0
  5. Copyright (C) 2006 Dabomstew
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Software
  19. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. require "global_func.php";
  22. if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
  23. $userid=$_SESSION['userid'];
  24. require "header.php";
  25. $h = new headers;
  26. $h->startheaders();
  27. include "mysql.php";
  28. global $c;
  29. $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid W
    HERE u.userid=$userid"
    ,$c) or die(mysql_error());
  30. check_level();
  31. $fm=money_formatter($ir['money']);
  32. $lv=date('F j, Y, g:i a',$ir['laston']);
  33. $h->userdata($ir,$lv,$fm);
  34. $h->menuarea();
  35. $_GET['ID'] = abs((int) $_GET['ID']);
  36. //Medical
  37. if(!$_GET['ID'])
  38. {
  39. print "Invalid use of file";
  40. }
  41. else
  42. {
  43. $i=mysql_query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i
    .itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid"
    ,$c);
  44. if(mysql_num_rows($i) == 0)
  45. {
  46. print "Invalid item ID";
  47. }
  48. else
  49. {
  50. if($r['itmtypename'] == 'Medical')
  51. {
  52. $f=mysql_query("SELECT * FROM medical WHERE item_id={$r['itmid']}",$c);
  53. mysql_query("UPDATE inventory SET inv_qty=inv_qty-1 WHERE inv_id={$_GET['ID']}",$c);
  54. mysql_query("DELETE FROM inventory WHERE inv_qty=0",$c);
  55. mysql_query("UPDATE users SET hp=hp+{$fr['hp']} WHERE userid=$userid");
  56. mysql_query("UPDATE users SET hp=maxhp WHERE hp > maxhp");
  57. print "You cram a {$r['itmname']} into your mouth. You feel a bit of energy coming back to you.";
  58. }
  59.  
  60.  
  61. else
  62. {
  63. print "You cannot use this item.";
  64. }
  65. }
  66. }
  67. $h->endpage();
  68. ?>

Tutaj chodzi o regeneracje hp przez medicine. I dodam, ze tutaj wszystko dziala bez problemów. Ja chcia³bym dodaæ regenracje energii przez jedzenie (food). Na podstawie urywku tego kodu stworzy³em cos takiego:

  1. <?php
  2. //Food
  3. if(!$_GET['ID'])
  4. {
  5. print "Invalid use of file";
  6. }
  7. else
  8. {
  9. $i=mysql_query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i
    .itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid"
    ,$c);
  10. if(mysql_num_rows($i) == 0)
  11. {
  12. print "Invalid item ID";
  13. }
  14. else
  15. {
  16. if($r['itmtypename'] == 'Food')
  17. {
  18. $f=mysql_query("SELECT * FROM food WHERE item_id={$r['itmid']}",$c);
  19. mysql_query("UPDATE inventory SET inv_qty=inv_qty-1 WHERE inv_id={$_GET['ID']}",$c);
  20. mysql_query("DELETE FROM inventory WHERE inv_qty=0",$c);
  21. mysql_query("UPDATE users SET energy=energy+{$fr['energy']} WHERE userid=$userid");
  22. mysql_query("UPDATE users SET energy=maxenergy WHERE energy > maxenergy");
  23. print "You cram a {$r['itmname']} into your mouth. You feel a bit of energy coming back to you.";
  24. }
  25. ?>

Po prostu wszystkie Medical pozmienia³em na food i wszystkie hp na energy. To równiez dzia³a jezeli zamienie ten urywek z tamtym. Ale jezeli po³±cze ten drugi pod ten pierwszy w jedym kodzie nie dzia³a. Tak to wyglada po moim po³aczeniu:



  1. <?php
  2. /*
  3. MCCodes Lite
  4. itemuse.php Rev 1.0.0
  5. Copyright (C) 2006 Dabomstew
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Software
  19. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. require "global_func.php";
  22. if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
  23. $userid=$_SESSION['userid'];
  24. require "header.php";
  25. $h = new headers;
  26. $h->startheaders();
  27. include "mysql.php";
  28. global $c;
  29. $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid W
    HERE u.userid=$userid"
    ,$c) or die(mysql_error());
  30. check_level();
  31. $fm=money_formatter($ir['money']);
  32. $lv=date('F j, Y, g:i a',$ir['laston']);
  33. $h->userdata($ir,$lv,$fm);
  34. $h->menuarea();
  35. $_GET['ID'] = abs((int) $_GET['ID']);
  36. //Medical
  37. if(!$_GET['ID'])
  38. {
  39. print "Invalid use of file";
  40. }
  41. else
  42. {
  43. $i=mysql_query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i
    .itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid"
    ,$c);
  44. if(mysql_num_rows($i) == 0)
  45. {
  46. print "Invalid item ID";
  47. }
  48. else
  49. {
  50. if($r['itmtypename'] == 'Medical')
  51. {
  52. $f=mysql_query("SELECT * FROM medical WHERE item_id={$r['itmid']}",$c);
  53. mysql_query("UPDATE inventory SET inv_qty=inv_qty-1 WHERE inv_id={$_GET['ID']}",$c);
  54. mysql_query("DELETE FROM inventory WHERE inv_qty=0",$c);
  55. mysql_query("UPDATE users SET hp=hp+{$fr['hp']} WHERE userid=$userid");
  56. mysql_query("UPDATE users SET hp=maxhp WHERE hp > maxhp");
  57. print "You cram a {$r['itmname']} into your mouth. You feel a bit of energy coming back to you.";
  58. }
  59.  
  60. //Food
  61. if(!$_GET['ID'])
  62. {
  63. print "Invalid use of file";
  64. }
  65. else
  66. {
  67. $i=mysql_query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i
    .itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid"
    ,$c);
  68. if(mysql_num_rows($i) == 0)
  69. {
  70. print "Invalid item ID";
  71. }
  72. else
  73. {
  74. if($r['itmtypename'] == 'Food')
  75. {
  76. $f=mysql_query("SELECT * FROM food WHERE item_id={$r['itmid']}",$c);
  77. mysql_query("UPDATE inventory SET inv_qty=inv_qty-1 WHERE inv_id={$_GET['ID']}",$c);
  78. mysql_query("DELETE FROM inventory WHERE inv_qty=0",$c);
  79. mysql_query("UPDATE users SET energy=energy+{$fr['energy']} WHERE userid=$userid");
  80. mysql_query("UPDATE users SET energy=maxenergy WHERE energy > maxenergy");
  81. print "You cram a {$r['itmname']} into your mouth. You feel a bit of energy coming back to you.";
  82. }
  83.  
  84. else
  85. {
  86. print "You cannot use this item.";
  87. }
  88. }
  89. }
  90. $h->endpage();
  91. ?>


Wyskakuje cos tam z unexpected $end. Moze mi ktos pomóc to dobrze po³±czyc?
Maxik
Na której linii, zobacz czy masz domkniête wszystkie klamry
Go¶æ
Nie mozliwe ze jakakolwiek linia jest otwarta poniewaz bo "oryginalny" kod. Te dwa urywki wstawione osobno do tego kodu dzialaja poprawnie, spelniaja swoje zadania, ale jak wstawie obydwa do tego pliku, jeden pod drugim to nie dziala. Podobny problem mam tutaj:

  1. <?php
  2. /*
  3. MCCodes Lite
  4. inventory.php Rev 1.0.0
  5. Copyright (C) 2006 Dabomstew
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. require "global_func.php";
  19. if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
  20. $userid=$_SESSION['userid'];
  21. require "header.php";
  22. $h = new headers;
  23. $h->startheaders();
  24. include "mysql.php";
  25. global $c;
  26. $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid W
    HERE u.userid=$userid"
    ,$c) or die(mysql_error());
  27. check_level();
  28. $fm=money_formatter($ir['money']);
  29. $lv=date('F j, Y, g:i a',$ir['laston']);
  30. $h->userdata($ir,$lv,$fm);
  31. $h->menuarea();
  32.  
  33. $inv=mysql_query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i
    .itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_userid={$use
    rid} ORDER BY i.itmtype ASC, i.itmname ASC"
    ,$c);
  34. if (mysql_num_rows($inv) == 0)
  35. {
  36. print "<b>You have no items!</b>";
  37. }
  38. else
  39. {
  40. print "<b>Twoje przedmioty:</b><br />
  41. <table width=100%><tr style='background-color:gray;'><th>Przedmiot</th><th>Cena sprzedarzy</th><th>Calkowita wartosc</th><th>Wiecej</th></tr>";
  42. $lt="";
  43. while($i=mysql_fetch_array($inv))
  44. {
  45. if($lt!=$i['itmtypename'])
  46. {
  47. $lt=$i['itmtypename'];
  48. print "\n<tr style='background: gray;'><th colspan=4>{$lt}</th></tr>";
  49. }
  50. print "<tr><td>{$i['itmname']}";
  51. if ($i['inv_qty'] > 1)
  52. {
  53. print " x{$i['inv_qty']}";
  54. }
  55. print "</td><td>${$i['itmsellprice']}</td><td>";
  56. print "$".($i['itmsellprice']*$i['inv_qty']);
  57. print "</td><td>[<a href='iteminfo.php?ID={$i['itmid']}'>Info</a>] [<a href='itemsend.php?ID={$i['inv_id']}'>Send</a>] [<a href='itemsell.php?ID={$i['inv_id']}'>Sell</a>] ";
  58. [b]if($i['itmtypename'] == 'Food') {
  59. print " [<a href='itemuse.php?ID={$i['inv_id']}'>Use</a>]";[/b]
  60.  
  61. print "</td></tr>";
  62. }
  63. print "</table>";
  64. }
  65. $h->endpage();
  66. ?>

To jest kod oryginalny. Gdy chce wstawic dodadkowa linie:
  1. <?php
  2. [b]if($i['itmtypename'] == 'Medical') {
  3. print " [<a href='itemuse.php?ID={$i['inv_id']}'>Use</a>]";[/b]
  4. ?>

pod taka sama ale dla innego przedmiotu mam ten sam blad. W polaczeniu u mnie wyglada to tak:
  1. <?php
  2. /*
  3. MCCodes Lite
  4. inventory.php Rev 1.0.0
  5. Copyright (C) 2006 Dabomstew
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. require "global_func.php";
  19. if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
  20. $userid=$_SESSION['userid'];
  21. require "header.php";
  22. $h = new headers;
  23. $h->startheaders();
  24. include "mysql.php";
  25. global $c;
  26. $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid W
    HERE u.userid=$userid"
    ,$c) or die(mysql_error());
  27. check_level();
  28. $fm=money_formatter($ir['money']);
  29. $lv=date('F j, Y, g:i a',$ir['laston']);
  30. $h->userdata($ir,$lv,$fm);
  31. $h->menuarea();
  32.  
  33. $inv=mysql_query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i
    .itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_userid={$use
    rid} ORDER BY i.itmtype ASC, i.itmname ASC"
    ,$c);
  34. if (mysql_num_rows($inv) == 0)
  35. {
  36. print "<b>You have no items!</b>";
  37. }
  38. else
  39. {
  40. print "<b>Twoje przedmioty:</b><br />
  41. <table width=100%><tr style='background-color:gray;'><th>Przedmiot</th><th>Cena sprzedarzy</th><th>Calkowita wartosc</th><th>Wiecej</th></tr>";
  42. $lt="";
  43. while($i=mysql_fetch_array($inv))
  44. {
  45. if($lt!=$i['itmtypename'])
  46. {
  47. $lt=$i['itmtypename'];
  48. print "\n<tr style='background: gray;'><th colspan=4>{$lt}</th></tr>";
  49. }
  50. print "<tr><td>{$i['itmname']}";
  51. if ($i['inv_qty'] > 1)
  52. {
  53. print " x{$i['inv_qty']}";
  54. }
  55. print "</td><td>${$i['itmsellprice']}</td><td>";
  56. print "$".($i['itmsellprice']*$i['inv_qty']);
  57. print "</td><td>[<a href='iteminfo.php?ID={$i['itmid']}'>Info</a>] [<a href='itemsend.php?ID={$i['inv_id']}'>Send</a>] [<a href='itemsell.php?ID={$i['inv_id']}'>Sell</a>] ";
  58. [b]if($i['itmtypename'] == 'Food') {
  59. print " [<a href='itemuse.php?ID={$i['inv_id']}'>Use</a>]";
  60. if($i['itmtypename'] == 'Medical') {
  61. print " [<a href='itemuse.php?ID={$i['inv_id']}'>Use</a>]";[/b]
  62.  
  63. print "</td></tr>";
  64. }
  65. print "</table>";
  66. }
  67. $h->endpage();
  68. ?>


I jest ten sam b³ad.
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.