Jump to content

jch02140

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by jch02140

  1. I just noticed a few errors of my code earlier.. I have updated the code and now able to display the correct number of records... However, all records display are the last record in the database... <?php for ($i=0; $i<$count_result; $i++) { $output = " <td align=\"center\"><p><img src=\"../images/".$item_rows['item_id'].".gif\" width=\"45\" height=\"45\" /></p> <p>".$item_rows['name']."<br /> Attack: +".$item_rows['attack']."(".$item_rows['damage'].")<br /> <img src=\"../images/credit.gif\" width=\"17\" height=\"17\" />$".$item_rows['sell_price']."</p> <p>[Equipt|Destory]<br /> </p> </td>"; $remainder = $i % 5; echo ($remainder == 0 ? ($i == 0 ? "" : "\n</tr>")."\n$output " : $output); } $colspan = (4 - $remainder); $last_row = $colspan ? " <td ".($colspan? "colspan=$colspan" : "")."></td>" : ""; echo $last_row. " </tr> </table>"; ?>
  2. I am trying to do something like this but the code I have doesn't seem to do what I want... <?php while($item_rows = mysql_fetch_array($item_result)) { $output = " <tr bgcolor=\"#000000\"> <td align=\"center\"><p><img src=\"../images/".$item_rows['item_id'].".gif\" width=\"45\" height=\"45\" /></p> <p>".$item_rows['name']."<br /> Attack: +".$item_rows['attack']."<br /> <img src=\"../images/credit.gif\" width=\"17\" height=\"17\" />$".$item_rows['sell_price']."</p> <p>[Equipt|Destory]<br /> </p> </td>"; $remainder = $i % 5; echo ($remainder == 0 ? ($i == 0 ? "" : "\n</tr>")."\n$output " : $output); } $colspan = (4 - $remainder); $last_row = $colspan ? " <td ".($colspan? "colspan=$colspan" : "")."></td>" : ""; echo $last_row. " </tr> </table>"; ?>
  3. I am able to make the map shift to the direction as intended but I got a few other problems: 1. The player location isn't properly loaded, eventhough it saved to the database successfully (I use locationX and locationY as XY coordinate individually). The X and Y corrdinates shows up on the URL itself like this ".../main.php?x=#&y=#". But if I remove them and then hit enter again the it will reset the position back to the original location of the map. 2. The player tile does not appears in center of the map tiles. Here is the page I uploaded my PHP script: http://student18.gamfe.com.hk/facebook/main.php Here is the map portion of the code: <?php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection'); mysql_query("SET NAMES 'utf-8'"); mysql_select_db($dbname) or die(mysql_error()); $query = "SELECT * FROM game_user WHERE game_id = '00001'"; $result = mysql_query($query) or die(mysql_error()); if ((!empty($_GET["x"])) && (!empty($_GET["y"]))) { $updateString = "UPDATE game_user SET locationX=".$_GET["x"].", locationY=" .$_GET["y"]. " WHERE game_id = '00001'"; mysql_query($updateString); } else { $x = 2; $y = 2; } ?> ... // Phrasing map tiles and player tile code <?php $file = file_get_contents('./images/maps/33/map.txt', true); $entries = explode("\n", $file); for($i=$x-2;$i<=$x+2;$i++){ $data = explode(",", $entries[$i]); for($j=$y-2;$j<=$y+2;$j++){ echo "<td align=\"center\" background=\"images/maps/33/33_"; echo $data[$j]; echo ".gif\" width=\"65\" height=\"65\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"65\" height=\"65\"> <tbody><tr> <td> <center>"; while($rows = mysql_fetch_array($result)) { if(($rows['locationX'] == $_GET["x"]) && ($rows['locationY'] == $_GET["y"])) { echo "<img src=\"../images/player_tile.gif\" title=\"You are here\">"; } } echo "</center> </td> </tr></tbody> </table> </td>"; } echo "</tr><tr>"; } ?>
  4. Thanks for the tips. Much appeciated. jch02140
  5. I am trying to print out rows of images and pieces them to form a bigger map but having a little trouble printing out correctly. I am doing the following... A numbered text file with rows of numbers like these: 33.txt 48,48,49,49,48,47,48,49,48,50,50,48,50,49,48,49,49,49 49,11,4,8,50,11,4,4,8,48,11,4,4,8,48,11,8,50 ... The number represent different area and the number in the text file represent each individual pieces of that particular area. the number of rows and columns are arbitrary. Example: Here is my code at the moment but there is something wrong in it as I can't seems to correctly print everything out... <?php $file = file_get_contents("33.txt"); // can be any numbered text files $entries = explode("\n", $file); echo "Entries <br /><hr />"; for($i=0;$i < sizeof($entries);$i++){ for($j=0;$j < sizeof($entries);$j++){ $data = explode(",", $entries[$j]); echo "<td align=\"center\" background=\"test/33_"; echo $data[$j]; echo ".gif\" width=\"65\" height=\"65\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"65\" height=\"65\"> <tbody><tr> <td> <center></center> </td> </tr></tbody> </table> </td>"; } } ?>
  6. I am not sure about CURL... but I read a little on foscket.. but I am not sure how to implement it...
  7. Hi, I am planning to display remote images with the following code but it seems to return errors. <?php $image_dir = 'http://www.domain.com/images/' ; $dir_handle = opendir( $image_dir ); $count = 0 ; $display = '' ; while( $filename = readdir($dir_handle)){ if( preg_match( '/$[a-z0-9]{4}_th\.jpg$/' , $filename ) ){ $display .= " <img src='$image_dir$filename' /> " ; $count++ ; if( $count % 10 == 0 ){ $count=0; $display .= "<br />"; } } } closedir( $dir_handle ); echo $display ; ?> I am thinking might be the $image_dir cannot use address format.... Errors is as follow
×
×
  • 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.