Jump to content

spider661

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

spider661's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. i have a mysql table with 2 fields one is the player name the other is profile.. in the profile field it holds all info about the player now i can sort this all out and make a new temp table and put all the info in it. player mana hp ac and the new table will now have all that info what i want to do is make like a ranking board where you can look up who is the best on the server based on mana hp or ac and then sort it. and get a nice list.. i know how to do everything but what i don't know how to do is take the info out of the new temp table put it into an array delete the temp table them pull the info from the array when called. this is how i would do it if i was calling the info from the table directly every time but i want to delete the temp table and use an array encase some one else laded the page at the same time i don't want it making a new temp table while someone else is reading from it so i want to put the info in an array and then sort it and delete the table. anyways here is how i do it without the array can someone help me make the array and work it into this? if(isset($_GET['c'])) $c = $_GET['c']; else $c = 0; if(isset($_GET['l'])) $l = $_GET['l']; else $l = '0'; if(isset($_GET['o'])) $o = $_GET['o']; else $o = '0'; if(isset($_GET['sort'])) $sort = $_GET['sort']; else $sort = 'hp'; $numToDisplay = 20; $c = preg_replace("/;/", "", $c); $l = preg_replace("/;/", "", $l); $o = preg_replace("/;/", "", $o); //$n = preg_replace("/;/", "", $n); mysql_connect($host, $dbuser, $dbpass); mysql_select_db("$db") or die(mysql_error()); if($o != $l) { $c = 0; $o = $l; } if($c == 0 && $l == 0 && $o ==0) { //build temp table } if($l != '0') $sql = "SELECT id, name, hp, mana, ac FROM character_ WHERE character_.class = '$l' ORDER BY $sort LIMIT $c, $numToDisplay;"; else $sql = "SELECT id, name, hp, mana, ac FROM character_ ORDER BY $sort LIMIT $c, $numToDisplay;"; $results = mysql_query("$sql"); $numChars = mysql_num_rows($results); for($i = 0; $i < $numChars; $i++) { $row = mysql_fetch_array($results); $name = $row['name']; $hp = $row['hp']; $mana = $row['mana']; $ac = $row['ac']; echo '<table width="100%" border="1" cellspacing="0" cellpadding="0">'; echo '<tr>'; echo '<th><a href=\"test.php?l=$l&c=$newC&o=$o&sort=name\">Name</a></th>'; echo '<th><a href=\"test.php?l=$l&c=$newC&o=$o&sort=hp\">HP</a></th>'; echo '<th><a href=\"test.php?l=$l&c=$newC&o=$o&sort=mana\">Mana</a></th>'; echo '<th><a href=\"test.php?l=$l&c=$newC&o=$o&sort=ac\">Ac</a></th>'; echo '</tr>'; echo ' <tr>'; echo ' <td><a href=\"magelo.php?char=$name\">$name</a></td>'; echo ' <td>$hp</td>'; echo ' <td>$mana</td>'; echo ' <td>$ac</td>'; echo ' </tr>'; echo '</table>'; } if($l != '0') $sql = "SELECT COUNT(*) FROM character_ WHERE character_.class = '$l';"; else $sql = "SELECT COUNT(*) FROM character_;"; $results = mysql_query("$sql"); $row = mysql_fetch_array($results); $count = $row['COUNT(*)']; $newC = max(0, $c - $numToDisplay); echo "<br><br><a href=\"test.php?l=$l&c=$newC&o=$o&sort=$sort\">Prev</a> "; $newC = min($c + $numToDisplay, max($count - $numToDisplay, 0)); echo "<a href=\"test.php?l=$l&c=$newC&o=$o&sort=$sort\">Next</a>"; this is houw i would code it if i was useing the table directly.. where it says //build temp table i would build the temp table here then read the info.. what i need is to take the info read pout it into an array then list it out in the table and still be able to hit next last links and go to the next/last 20.. but then i also need to be able to sort them by the diff types.. (the <th> is where they click to sort by that type> please help out anyway you can...
  2. i was given this on another forum that deals more with the server im trying to get the info from but there is a bu in it can someone see if they can find the problem. foreach ($ret as $key => $value){ // GM Status if (preg_match("/\*.*\*/", $value, $matches)){ $players[$key][GM] = trim($matches[0], "* "); } // Role/Anon, Level, & Class if (preg_match("/\[.*\]/", $value, $matches)){ $tmp = explode(" ", trim($matches[0], "[] ")); if (!is_numeric($tmp[0])){ $players[$key][Visible] = $tmp[0]; $players[$key][Level] = $tmp[1]; $players[$key]["Class"] = rtrim($tmp[2] . " " . $tmp[3], " "); }else{ $players[$key][Level] = $tmp[0]; $players[$key]["Class"] = rtrim($tmp[1] . " " . $tmp[2], " "); } } // Character's Name if (preg_match("/\].*\(/", $value, $matches)){ $players[$key][Name] = trim($matches[0], "] ("); } // Race if (preg_match("/\(.*\)/", $value, $matches)){ $players[$key][Race] = trim($matches[0], "( )"); } // Zone if (preg_match("/zone:.*AccID:/", $value, $matches)){ $players[$key][ZoneLong] = substr($matches[0], 6, -7); } // Account ID if (preg_match("/AccID:.*AccName:/", $value, $matches)){ $players[$key][AcctID] = substr($matches[0], 7, -9); } // Account Name if (preg_match("/AccName:.*LSID:/", $value, $matches)){ $players[$key][AcctName] = substr($matches[0], 9, -6); } // Login Server ID if (preg_match("/LSID:.*Status:/", $value, $matches)){ $players[$key][LSID] = substr($matches[0], 6, -; } // Status if (preg_match("/Status:.*/", $value, $matches)) { $players[$key][status] = substr($matches[0], 8, 3); } } i called print_r($players); to try to list the array so i could see what the values where to post it all in my table and it gave an error for each player online that sayed Warning: Invalid argument supplied for foreach() in E:\wamp\www\who.php on line 46 line 46 is foreach ($ret as $key => $value){
  3. ok for the life of me I cant figure out y but this works and does exactly what i wanted. is there a better way to do it though or should i just stick with whats working? while (!feof($fp)) { $ret = fgets($fp); if (ereg("zone", $ret)) { $array = explode("status:", $ret); $roster = array(); $i = 1; foreach ($array as $key => $value) { if(preg_match("#\[([0-9]+) ([a-zA-z ]+)\] ([a-zA-Z]+) \(([a-zA-Z ]+)\) zone: ([a-zA-Z]+)#", $value, $out) || preg_match("#\[[a-zA-Z]+ ([0-9]+) ([a-zA-z ]+)\] ([a-zA-Z]+) \(([a-zA-Z ]+)\) zone: ([a-zA-Z]+)#", $value, $out)) { //$roster[$i] = array("name" => $out[3], "level" => $out[1], "class" => $out[2], "race" => $out[4], "zone" => $out[5]); $i++; } } $name = $out[3]; $race = $out[4]; $level = $out[1]; $class = $out[2]; $zone = $out["5"]; it seems part of the problem was the explode /n is not there becuase there is no next line its all output on the same line. so i picked something closer to the end status: as for the array i really don't understand whats going on there so if someone would like to explain it i would love that but if not its cool.. anyways this is what i got.
  4. ok that looks good if i post it like it is above. but again if i put it to my code it does nothing. so maybe im doing something wrong this is my full page code. <?php echo '<!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" dir="{S_CONTENT_DIRECTION}" lang="{S_USER_LANG}" xml:lang="{S_USER_LANG}"> <head> <link rel="stylesheet" href="stylesheet.css" type="text/css" /> <!--[if lte IE 6]><script defer type="text/javascript" src="pngfix.js"></script><![endif]--> <!--[if IE ]><link rel="stylesheet" href="ie.css" type="text/css" /><![endif]--> </head> <body> <div id="container"> <div id="wrapper"> <div id="header"> <a href="http://scarsofamerous.com/"><img src="images/site_logo.png"></a> </div> <div id="content1"> <div id="content2"> <div id="content3"> <br><br><br><br><br><center><font color="#FF0000" size="4"><strong>Welcome to Scars of Amerous!</strong></font></center><br><br><br><br><br><hr class="hr">'; include "datas/config.php"; fConnect($fp,$Server,$Port,$user,$pass); fputs ($fp, "who\r"); usleep(125000); echo '<center><table border="4" cellpadding="4" cellspacing="4" ALIGN="CENTER"> <tr> <th>Name</th> <th>Level</th> <th>Race</th> <th>Class</th> <th>Zone</th> </tr>'; while (!feof($fp)) { $ret = fgets($fp); if (ereg("zone", $ret)) { $array = explode("\n", $ret); $roster = array(); $i = 1; foreach ($array as $key => $value) { if(preg_match("#\[([0-9]+) ([a-zA-z ]+)\] ([a-zA-Z]+) \(([a-zA-Z ]+)\) zone: ([a-zA-Z]+)#", $value, $out) || preg_match("#\[[a-zA-Z]+ ([0-9]+) ([a-zA-z ]+)\] ([a-zA-Z]+) \(([a-zA-Z ]+)\) zone: ([a-zA-Z]+)#", $value, $out)) { $roster[$i] = array("name" => $out[3], "level" => $out[1], "class" => $out[3], "race" => $out[4], "zone" => $out[5]); $i++; } } $name = $roster["name"]; $race = $roster["race"]; $level = $roster["level"]; $class = $roster["class"]; $zone = $roster["zone"]; //$name = substring_between($ret, '] ', ' ('); //$race = substring_between($ret, '(', ')'); //$level = substring_between($ret, '[', ']'); //$zone = substring_between($ret, 'zone: ', ' AccID:'); echo "<tr> <td class='smalltable'> $name </td> <td class='smalltable'> $level </td> <td class='smalltable'> $race </td> <td class='smalltable'> $class </td> <td class='smalltable'> $zone </td> </tr>"; } if (ereg("online", $ret)){ echo "$ret \n"; fclose($fp); break; } } echo '</table> <center> </div> </div> </div> <div id="footer"> <span class="notice"> © 2008 Spider661<br /></span> </div> </div> </div> </body> </html>'; ?>
  5. also wanted to note that $ret = '[72 Stone Fist] Yuari (Iksar) zone: gfaydark AccID: 298 AccName: Flora LSID: 110561 Status: 0 [72 Soothsayer] Kefus (Iksar) zone: qrg AccID: 307 AccName: Nerine LSID: 110954 Status: 0 [74 Wildblood] Tigger (Vah Shir) zone: gukbottom AccID: 244 AccName: harkenus2 LSID: 112355 Status: 0 3 players online'; is not always that.. it changes each time i call it but the format is the same doing the preg_match_all the way you posted it worked but when i loaded it with the ret from my code then i got that output above. i got it working the way i want above i just need to split the level class and take out annon if its there before the level it could look like ether/or and i need it to take out annon and split 75 and Arch Magus or whatever it may be into 2 diff strings i can use in the table [annon 75 Arch Magus] [75 Arch Magus]
  6. dont think it worked but looks close to what i want but i think there all blank this is what it printed out Array ( [0] => Array ( ) [level] => Array ( ) [1] => Array ( ) [class] => Array ( ) [2] => Array ( ) [name] => Array ( ) [3] => Array ( ) [race] => Array ( ) [4] => Array ( ) [zone] => Array ( ) [5] => Array ( ) ) Array ( [0] => Array ( ) [level] => Array ( ) [1] => Array ( ) [class] => Array ( ) [2] => Array ( ) [name] => Array ( ) [3] => Array ( ) [race] => Array ( ) [4] => Array ( ) [zone] => Array ( ) [5] => Array ( ) ) Array ( [0] => Array ( ) [level] => Array ( ) [1] => Array ( ) [class] => Array ( ) [2] => Array ( ) [name] => Array ( ) [3] => Array ( ) [race] => Array ( ) [4] => Array ( ) [zone] => Array ( ) [5] => Array ( ) )
  7. ok i got something working here useing this code function substring_between($haystack,$start,$end) { if (strpos($haystack,$start) === false || strpos($haystack,$end) === false) { return false; } else { $start_position = strpos($haystack,$start)+strlen($start); $end_position = strpos($haystack,$end); return substr($haystack,$start_position,$end_position-$start_position); } } i did this fConnect($fp,$Server,$Port,$user,$pass); fputs ($fp, "who\r"); usleep(125000); echo '<center><table border="4" cellpadding="4" cellspacing="4" ALIGN="CENTER"> <tr> <th>Name</th> <th>Race</th> <th>Level/Class</th> <th>Zone</th> </tr>'; while (!feof($fp)) { $ret = fgets($fp); if (ereg("zone", $ret)) { $name = substring_between($ret, '] ', ' ('); $race = substring_between($ret, '(', ')'); $level = substring_between($ret, '[', ']'); $zone = substring_between($ret, 'zone: ', ' AccID:'); echo "<tr> <td class='smalltable'> $name </td> <td class='smalltable'> $race </td> <td class='smalltable'> $level </td> <td class='smalltable'> $zone </td> </tr>"; //echo "$ret1 \n <br>"; } if (ereg("online", $ret)){ echo "$ret \n"; fclose($fp); break; } } echo '</table><center>'; and it outputs a table that looks like this Name Race Level/Class Zone Irun High Elf 75 Arch Magus delveb Southern Wood Elf ANNON 75 Natureguard butcher 2 players online now thats great but i would like to split up Level/Class and take out annon if its there and then put lvl and class in a diff row. the problem is the function above will not take a space as $start or $end.. anyone got any suggestions?
  8. jsut trying to do my part to help your welcome
  9. <?php $q = "INSERT INTO `home` (content, title) VALUES ('$content', '$title')"; mysql_query($q); ?> will do it you dont have to put in an id now the database will do it auto for you.
  10. is a database function built into them i use mysql myself. go into the property's of the table and set id or the one you want to go up to auto_increment and then when you add your line just leave id blank and the database will put the next highest number in there for you. or when you build the table set it here is how i built a table i used. CREATE TABLE `server_globals` ( `id` int(11) NOT NULL auto_increment, `name` varchar(65) NOT NULL default '', `value` varchar(65) NOT NULL default '?', PRIMARY KEY (`id`), UNIQUE KEY `qname` (`name`,`value`) ) ENGINE=MyISAM AUTO_INCREMENT=1280 DEFAULT CHARSET=latin1; see how i set id to auto_increment and even set a starting value so UPDATE tablename SET `id` int(11) NOT NULL auto_increment should work
  11. i always have a problem manipulating string and i need to do some for a website im working on. so i was wondering if anyone could help me out? i want to take a string and strip parts of it out and then post them parts.. would be helpful if it could make them a new variable usable on other pages also but thats not important i really just need to strip the info out. i have this code to get the string fConnect($fp,$Server,$Port,$user,$pass); fputs ($fp, "who\r"); usleep(125000); while (!feof($fp)) { $ret = fgets($fp); if (ereg("zone", $ret)) { echo "$ret \n <br>"; } if (ereg("online", $ret)){ echo "$ret \n"; fclose($fp); break; } } and it returns a string that looks like this [72 Stone Fist] Yuari (Iksar) zone: gfaydark AccID: 298 AccName: Flora LSID: 110561 Status: 0 [72 Soothsayer] Kefus (Iksar) zone: qrg AccID: 307 AccName: Nerine LSID: 110954 Status: 0 [74 Wildblood] Tigger (Vah Shir) zone: gukbottom AccID: 244 AccName: harkenus2 LSID: 112355 Status: 0 3 players online first part the numbers i need thats there level and needs to go in a table under the title level next part (on first line its) stone fist, i need that its there class and needs to go under class next part is there name yuari and that needs to go under name. next part iskar is there class and needs to go under class. and the final part is gfaydark and its there zone and needs to go under zone. and thats everything i need so when looking at the output on a website i would like it to make a table and read like so Name level class race zone Yuari 72 stone fist iskar gfaydark then the next person and so on till no more. can anyone help me with this?
×
×
  • 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.