Jump to content

arif_shariati

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

arif_shariati's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I need easy framework just like codeigniter but they have changed it. I need pure framework. What stuffs and code pattern needed for mvc ?
  2. can any body let me know tutorial for making mvc or other php framework. I need it badly.
  3. Yes.But does facebook do the same ?
  4. I want to work with sessions in my web application using simple php to lessen the connectivity with the database. I am confused where to start session. I mean from which page to start my session? Like wise facebook when we get logged in, after that we can see our profile etc all. My idea about this is "Once we get logged in all the necessary data is pulled out from the database and put in session variables. and when we log out, sessions variables are unset". Please let me know, am i right ?
  5. I am trying to make a board game. such as chess with all AI logic back there. But in php i am getting problems of syntax and logic. these are my steps for the game. 1-Initialize the board (with sheeps and lions at certain position) // this is done 2-scan board (for empty cells, lions position and sheep position) 3-user wants to move sheep from a state(cell) to other. // here i am getting problem 4-system will move lion based on AI principles. This continues till end of game. Hope you have got an idea what i am gonna do. If you need codes, I will send you. May be you can help me on this project.
  6. hey buddy i am messed up. I am not able to fix this.
  7. Nopes it is not working. Think my flow of calling functions are not ok. Please have a look at them. If possible please try code on your machine and if possible fix it. That would be generous of you. include_once("init_board1.php"); $board_i=new board(); $board_i->init_board(); $board_i->show_board(); $board_i->show_form(); $board_i->move($_REQUEST['from1'],$_REQUEST['to1']);
  8. That is fine but i can not update the public variable in the class such as $board_value['19']="S"; i can not update this.
  9. Thanks it did work. But how can i use form values in class functions ?? <?php class board { public $num_sheep_init=20; public $num_lion_init=2; public $board_value=array(0=>'', 1=>'', 2=>'', 3=>'', 4=>'', 5=>'', 6=>'', 7=>'', 8=>'', 9=>'', 10=>'', 11=>'', 12=>'', 13=>'', 14=>'', 15=>'', 16=>'', 17=>'', 18=>'', 19=>'', 20=>'', 21=>'', 22=>'', 23=>'', 24=>''); public $random_array_value=array (0,1,2,3,4,5,7,9,10,11,13,14,15,17,19,20,21,22,23,24); public $selected_index=array(); public $randd=array(); public $countt=0; function __construct () { } function init_board () { $this->board_value['6']="S"; $this->board_value['8']="S"; $this->board_value['16']="S"; $this->board_value['18']="S"; while ($this->countt!=2) { $v=array_rand($this->random_array_value); array_push ($this->randd,$v);//find random value from the array array_push($this->selected_index,$v); // push the random vlue in the selected array //echo "now pushed ".$v."<br>"; $this->random_array_value=array_diff($this->random_array_value,$this->randd);// delete the random selected array from the array $this->countt++; } for ($k=0;$k<sizeof($this->selected_index);$k++) { $this->board_value[$this->selected_index[$k]]="L"; //insert the positions of lions } } function show_board () { echo "<table border='1' bordercolor='#CCCCCC' id='board'>"; echo "<tr>"; echo "<td id='td0'><center>".$this->board_value['0']."</center></td>"; echo "<td id='td1'><center> ".$this->board_value['1']."</center></td>"; echo "<td id='td2'><center> ".$this->board_value['2']."</center></td>"; echo "<td id='td3'><center>".$this->board_value['3']."</center></td>"; echo "<td id='td4'><center>".$this->board_value['4']."</center></td>"; echo "</tr>"; echo "<tr>"; echo "<td id='td5'><center>".$this->board_value['5']."</center></td>"; echo "<td id='td6'><center>".$this->board_value['6']."</center></td>"; echo "<td id='td7'><center> ".$this->board_value['7']."</center></td>"; echo "<td id='td8'> <center>".$this->board_value['8']."</center></td>"; echo "<td id='td9'> <center>".$this->board_value['9']."</center></td>"; echo "</tr>"; echo "<tr>"; echo "<td id='td10'> <center>".$this->board_value['10']."</center></td>"; echo "<td id='td11'> <center>".$this->board_value['11']."</center></td>"; echo "<td id='td12'> <center>".$this->board_value['12']."</center></td>"; echo "<td id='td13'><center> ".$this->board_value['13']."</center></td>"; echo "<td id='td14'> <center>".$this->board_value['14']."</center></td>"; echo "</tr>"; echo "<tr>"; echo "<td id='td15'><center> ".$this->board_value['15']."</center></td>"; echo "<td id='td16'> <center>".$this->board_value['16']."</center></td>"; echo "<td id='td17'><center> ".$this->board_value['17']."</center></td>"; echo "<td id='td18'> <center>".$this->board_value['18']."</center></td>"; echo "<td id='td19'> <center>".$this->board_value['19']."</center></td>"; echo "</tr>"; echo "<tr>"; echo "<td id='td20'> <center>".$this->board_value['20']."</center></td>"; echo "<td id='td21'> <center>".$this->board_value['21']."</center></td>"; echo "<td id='td22'><center> ".$this->board_value['22']."</center></td>"; echo "<td id='td23'> <center>".$this->board_value['23']."</center></td>"; echo "<td id='td24'> <center>".$this->board_value['24']."</center></td>"; echo "</tr>"; echo "</table>"; } function show_form () { echo "<form method='post' action='init_board1.php'>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<label for='from'>Move sheep From : </label>"; echo "</td>"; echo "<td>"; echo "<input name='from1' type='text' />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "<label for='to'>Move sheep To : </label>"; echo "</td>"; echo "<td>"; echo "<input name='to1' type='text' />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td></td>"; echo "<td><input type='submit' value='Go' /></td>"; echo "</tr>"; echo "</form>"; echo "</table>"; } function scan_board () { public $empty_cell=array(); public $lion_position=array(); public $sheep_position=array(); for ($i=0;$i<25;$i++) { if ($this->board_value[$i]==="") { array_push($empty_cell,$i); } else if ($this->board_value[$i]==="L") { array_push($lion_position,$i); } else if ($this->board_value[$i]==="S") { array_push($sheep_position,$i); } else echo "The index was out of bound"; } } function move($from,$to) { $this->board_value[$to]="S"; } } ?> Suppose here in the "function show_form ()" user submits the form and i want form values to be used in the last function "function move()". How to do that ?
  10. I am having problem with calling class member from with the function in that class. <?php class board { function __construct () { $num_sheep_init=20; $num_lion_init=2; $board_value=array(0=>'', 1=>'', 2=>'', 3=>'', 4=>'', 5=>'', 6=>'', 7=>'', 8=>'', 9=>'', 10=>'', 11=>'', 12=>'', 13=>'', 14=>'', 15=>'', 16=>'', 17=>'', 18=>'', 19=>'', 20=>'', 21=>'', 22=>'', 23=>'', 24=>''); $random_array_value=array (0,1,2,3,4,5,7,9,10,11,13,14,15,17,19,20,21,22,23,24); $selected_index=array(); $randd=array(); $countt=0; } function init_board () { $this->board_value['6']="S"; Above is part of the code where i am having problem. It says that it can not access empty property //$this->board_value['6']="S";
  11. I found the answer to the above my question. that was i was using $this->$var but the correct syntax is $this->var. But unfortunately i am getting series of errors. class board { public $num_sheep_init=20; public $num_lion_init=2; public static $board_value=array(0=>'', 1=>'', 2=>'', 3=>'', 4=>'', 5=>'', 6=>'', 7=>'', 8=>'', 9=>'', 10=>'', 11=>'', 12=>'', 13=>'', 14=>'', 15=>'', 16=>'', 17=>'', 18=>'', 19=>'', 20=>'', 21=>'', 22=>'', 23=>'', 24=>''); public static $random_array_value=array (0,1,2,3,4,5,7,9,10,11,13,14,15,17,19,20,21,22,23,24); public $selected_index=array(); public $randd=array(); public $count=0; function __construct () {} function init_board () { $this->board_value['6']="S"; $this->board_value['8']="S"; $this->board_value['16']="S"; $this->board_value['18']="S"; while ($this->count!=2) { $v=array_rand($this->random_array_value); // ERROR is " Undefined property:board::$random_array_value" This is the part of code.
  12. should i include the file in every function ? I have not worked on $_post yet.
  13. Now i tried to work with classes. But i am having error. This is my code. <?php class board { public $num_sheep_init=20; public $num_lion_init=2; public $board_value=array(0=>'', 1=>'', 2=>'', 3=>'', 4=>'', 5=>'', 6=>'', 7=>'', 8=>'', 9=>'', 10=>'', 11=>'', 12=>'', 13=>'', 14=>'', 15=>'', 16=>'', 17=>'', 18=>'', 19=>'', 20=>'', 21=>'', 22=>'', 23=>'', 24=>''); public $random_array_value=array (0,1,2,3,4,5,7,9,10,11,13,14,15,17,19,20,21,22,23,24); public $selected_index=array(); public $rand=array(); public $count=0; function __construct () {} function init_board () { $this->$board_value['6']="S"; $this->$board_value['8']="S"; $this->$board_value['16']="S"; $this->$board_value['18']="S"; while ($count!=2) { $v=array_rand($this->$random_array_value); array_push ($this->$rand,$v);//find random value from the array array_push($this->$selected_index,$v); // push the random vlue in the selected array //echo "now pushed ".$v."<br>"; $this->$random_array_value=array_diff($this->$random_array_value,$this->$rand);// delete the random selected array from the array $this->$count++; } for ($k=0;$k<sizeof($this->$selected_index);$k++) { $this->$board_value[$this->$selected_index[$k]]="L"; //insert the positions of lions } } function show_board () { echo "<table border='1' bordercolor='#CCCCCC' id='board'>"; echo "<tr>"; echo "<td id='td0'><center>".$this->$board_value['0']."</center></td>"; echo "<td id='td1'><center> ".$this->$board_value['1']."</center></td>"; echo "<td id='td2'><center> ".$this->$board_value['2']."</center></td>"; echo "<td id='td3'><center>".$this->$board_value['3']."</center></td>"; echo "<td id='td4'><center>".$this->$board_value['4']."</center></td>"; echo "</tr>"; echo "<tr>"; echo "<td id='td5'><center>".$this->$board_value['5']."</center></td>"; echo "<td id='td6'><center>".$this->$board_value['6']."</center></td>"; echo "<td id='td7'><center> ".$this->$board_value['7']."</center></td>"; echo "<td id='td8'> <center>".$this->$board_value['8']."</center></td>"; echo "<td id='td9'> <center>".$this->$board_value['9']."</center></td>"; echo "</tr>"; echo "<tr>"; echo "<td id='td10'> <center>".$this->$board_value['10']."</center></td>"; echo "<td id='td11'> <center>".$this->$board_value['11']."</center></td>"; echo "<td id='td12'> <center>".$this->$board_value['12']."</center></td>"; echo "<td id='td13'><center> ".$this->$board_value['13']."</center></td>"; echo "<td id='td14'> <center>".$this->$board_value['14']."</center></td>"; echo "</tr>"; echo "<tr>"; echo "<td id='td15'><center> ".$this->$board_value['15']."</center></td>"; echo "<td id='td16'> <center>".$this->$board_value['16']."</center></td>"; echo "<td id='td17'><center> ".$this->$board_value['17']."</center></td>"; echo "<td id='td18'> <center>".$this->$board_value['18']."</center></td>"; echo "<td id='td19'> <center>".$this->$board_value['19']."</center></td>"; echo "</tr>"; echo "<tr>"; echo "<td id='td20'> <center>".$this->$board_value['20']."</center></td>"; echo "<td id='td21'> <center>".$this->$board_value['21']."</center></td>"; echo "<td id='td22'><center> ".$this->$board_value['22']."</center></td>"; echo "<td id='td23'> <center>".$this->$board_value['23']."</center></td>"; echo "<td id='td24'> <center>".$this->$board_value['24']."</center></td>"; echo "</tr>"; echo "</table>"; } } ?> and this is the index.php <?php include_once("init_board1.php"); /*include_once("board.php"); include_once("form.php"); init_board(); show_board(); show_form(); */ $board=new board(); $board->init_board(); $board->show_board(); ?> I am having the following error /////////////////////////////////////////// Notice: Undefined variable: board_value in C:\wamp\www\init_board1.php on line 39 Fatal error: Cannot access empty property in C:\wamp\www\init_board1.php on line 39
  14. THis is my variable.php file <?php // Variables $num_sheep_init=20; $num_lion_init=2; // Initial Array $board_value=array(0=>'', 1=>'', 2=>'', 3=>'', 4=>'', 5=>'', 6=>'', 7=>'', 8=>'', 9=>'', 10=>'', 11=>'', 12=>'', 13=>'', 14=>'', 15=>'', 16=>'', 17=>'', 18=>'', 19=>'', 20=>'', 21=>'', 22=>'', 23=>'', 24=>''); ?> and this is my temp.php file <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Lion and sheep</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <?php global $board_value; //include_once("init_board.php"); if (!include_once("variable.php")) { echo "variable.php was not included !"; } if (!include_once("board.php")) { echo "board.php was not included !"; } if (!isset($board_value)) { echo "This file does not know what us $board_value !"; } //global $board_value; show_board(); ?> </body> </html> Here in temp.php when i am trying to access $board_value array, it is not accessed.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.