+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: PHP Help

  1. #1
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    PHP Help

    Hey guys,

    Really didn't want to do this... but i'm really confused. xD

    I think i went too in-depth to this.

    Heres my problem.

    I'm trying to make personal Highscores for a RuneScape private server that is SQL/IPB integrated.

    and, i got all the data I need, but I have the levels in experience not in the levels.

    I have the function and stuff to do it, just can't figure out how to implement it.

    Here it is.

    Also, if you could help me try to do this automaticly, like put in a loop or something, that would be great.

    PHP Code:
    <style type="text/css">
    table {
    width: 50%;
    }
    </style>
    <?php
    $c1 
    mysql_connect("localhost""*****""*******");
    mysql_select_db("cali_3"$c1);
    if (isset (
    $_GET['name']))
     {
    $name $_GET['name'];
    $result mysql_query("SELECT * FROM ibf_members WHERE name='$name'") or die(mysql_error());

    while(
    $row mysql_fetch_array($result))
      {
     function 
    experience($L) {
      
    $a=0;
      for(
    $x=1$x<$L$x++) {
       
    $a += floor($x+300*pow(2, ($x/7)));
      }
      return 
    floor($a/4);
     }

    if(
    $playerxp >= 13034430//fix
        
    $playerLevel 99;

      echo 
    "<a href=#search><h3><center><u>Search again?</u></center></h3></a><br /><br />";
      echo 
    "<center><table border=1>";
      
    $stats = array("attack""defence""strength""hitpoints""range""prayer""magic""cooking","woodcutting","fletching","fishing","firemaking","crafting","smithing","mining","herblore","agility","thieving","slayer","farming","runecrafting");

      echo 
    "<tr>";
      echo 
    "<td><strong>" $row['name'] . "</strong></td>";
      echo 
    "<td>Level</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Attack</td>";
      echo 
    "<td>" $row['attack'] . "</td>";
      echo 
    "<td>" $L['$stats'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Defence</td>";
      echo 
    "<td>" $row['defence'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Strength</td>";
      echo 
    "<td>" $row['strength'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Hitpoints</td>";
      echo 
    "<td>" $row['hitpoints'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Ranged</td>";
      echo 
    "<td>" $row['range'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Prayer</td>";
      echo 
    "<td>" $row['prayer'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Magic</td>";
      echo 
    "<td>" $row['magic'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Cooking</td>";
      echo 
    "<td>" $row['cooking'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Woodcutting</td>";
      echo 
    "<td>" $row['woodcutting'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Fletching</td>";
      echo 
    "<td>" $row['fletching'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Fishing</td>";
      echo 
    "<td>" $row['fishing'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Firemaking</td>";
      echo 
    "<td>" $row['firemaking'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Crafting</td>";
      echo 
    "<td>" $row['crafting'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Smithing</td>";
      echo 
    "<td>" $row['smithing'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Mining</td>";
      echo 
    "<td>" $row['mining'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Herblore</td>";
      echo 
    "<td>" $row['herblore'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Agility</td>";
      echo 
    "<td>" $row['agility'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Thieving</td>";
      echo 
    "<td>" $row['thieving'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Slayer</td>";
      echo 
    "<td>" $row['slayer'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>Farming</td>";
      echo 
    "<td>" $row['farming'] . "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td>RuneCrafting</td>";
      echo 
    "<td>" $row['runecrafting'] . "</td>";
      echo 
    "</tr>";
      }
    echo 
    "</table></center>";
    mysql_close($c1);
    }
    else if (!isset (
    $_GET['name'])) {
    echo 
    "Welcome to the CaliScape Sig Shop!";
    echo 
    "<br />";
    echo 
    "Here you can make a custom signiture showing your CaliScape Stats!";
    echo 
    "<br />Enjoy!<br />";
    }
    ?>
    <center><a name="search"></a>
    <form name="psearch" type="get" action="index.php">
    <input type="hidden" name="code" value="Sigs" />
    <input type="text" name="name" /><br />
    <input type="submit" value="Search" />
    </form></center>
    Thanks in advance,

    --Neil
    Last edited by leafypiggy; 11-03-2008 at 06:50 PM.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Help

    try this:
    PHP Code:
    <?php 
    $c1 
    mysql_connect("localhost""*****""*******"); 
    mysql_select_db("cali_3"$c1); 

    function 
    experience($L) { 
      
    $a=0
      
    for($x=1$x<$L$x++)
        
    $a += floor($x+300*pow(2, ($x/7))); 

      return 
    floor($a/4); 


    if (!empty(
    $_GET['name'])) // !empty is like isset, but also checks to see if there's a value w/ it ;)

      
    $name $_GET['name']; 
      
    $result mysql_query("SELECT * FROM ibf_members WHERE name='$name'") or die(mysql_error()); 

      while(
    $row mysql_fetch_array($result)) 
      { 
        if(
    $playerxp >= 13034430//fix 
          
    $playerLevel 99

        echo 
    "<a href=#search><h3><center><u>Search again?</u></center></h3></a><br /><br />"
        echo 
    "<center><table border=1>"
        
    $stats = array("attack""defence""strength""hitpoints""range""prayer""magic""cooking","woodcutting","fletching","fishing","firemaking","crafting","smithing","mining","herblore","agility","thieving","slayer","farming","runecrafting"); 

        echo 
    "<tr>"
        echo 
    "<td><strong>" $row['name'] . "</strong></td>"
        echo 
    "<td>Level</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Attack</td>"
        echo 
    "<td>" $row['attack'] . "</td>"
        echo 
    "<td>" experience($row['$stats']) . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Defence</td>"
        echo 
    "<td>" $row['defence'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Strength</td>"
        echo 
    "<td>" $row['strength'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Hitpoints</td>"
        echo 
    "<td>" $row['hitpoints'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Ranged</td>"
        echo 
    "<td>" $row['range'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Prayer</td>"
        echo 
    "<td>" $row['prayer'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Magic</td>"
        echo 
    "<td>" $row['magic'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Cooking</td>"
        echo 
    "<td>" $row['cooking'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Woodcutting</td>"
        echo 
    "<td>" $row['woodcutting'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Fletching</td>"
        echo 
    "<td>" $row['fletching'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Fishing</td>"
        echo 
    "<td>" $row['fishing'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Firemaking</td>"
        echo 
    "<td>" $row['firemaking'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Crafting</td>"
        echo 
    "<td>" $row['crafting'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Smithing</td>"
        echo 
    "<td>" $row['smithing'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Mining</td>"
        echo 
    "<td>" $row['mining'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Herblore</td>"
        echo 
    "<td>" $row['herblore'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Agility</td>"
        echo 
    "<td>" $row['agility'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Thieving</td>"
        echo 
    "<td>" $row['thieving'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Slayer</td>"
        echo 
    "<td>" $row['slayer'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>Farming</td>"
        echo 
    "<td>" $row['farming'] . "</td>"
        echo 
    "</tr>"
        echo 
    "<tr>"
        echo 
    "<td>RuneCrafting</td>"
        echo 
    "<td>" $row['runecrafting'] . "</td>"
        echo 
    "</tr>"
      } 
      echo 
    "</table></center>"
      
    mysql_close($c1); 

    else
    {
      echo 
    "Welcome to the CaliScape Sig Shop!"
      echo 
    "<br />"
      echo 
    "Here you can make a custom signiture showing your CaliScape Stats!"
      echo 
    "<br />Enjoy!<br />"

    ?>
    you also don't need all those echo commands. It just creates useless overhead. an echo command can span over several lines, and a new line in the command will result in a new line in the source code.
    Last edited by xPlozion; 11-03-2008 at 07:26 PM.

  3. #3
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: PHP Help

    i know. i'm just doin a rough copy.

    but.

    yeah. it doesnt work. takes too long to process. IPB gives me a timeout error
    Edit:
    must be the function.
    Last edited by leafypiggy; 11-03-2008 at 08:13 PM. Reason: Automerged Doublepost
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  4. #4
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Help

    try debugging the function. for instance, do <?php echo experience(5) ?> or whatever you would use for $L. If it's the loop or w/e, you'll find out there ;)

    other than that, as far as digging deep, as a few other members will say, it's kinda hard for me to get involved without having code to work with and test live, as I do numerous debugging options, which really only come to me when I'm testing it :-/
    Last edited by xPlozion; 11-03-2008 at 11:36 PM.

  5. #5
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: PHP Help

    If you're getting a "takes too long" error, try putting LIMIT 0, 10 at the end of your SQL. That will only pull the first 10 entries. I don't know how big your userbase is so this may not be the problem but it's a thought.
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  6. #6
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: PHP Help

    I got it.

    cept i gotta fix how it works. :P

    i made it loop using foreach()

    thanks. might post back
    Edit:
    kk..

    i've got it working with the loop. however the function is outputting 0 as the result. any help?

    PHP Code:
    function experience($L) { 
      
    $a=0
      
    for($x=1$x<$L$x++)
        
    $a += floor($x+300*pow(2, ($x/7))); 

      return 
    floor($a/4); 

    Edit:
    bump
    Last edited by leafypiggy; 11-05-2008 at 05:43 AM. Reason: Automerged Doublepost
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  7. #7
    mattura's Avatar
    mattura is offline x10 Elder mattura is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    563

    Re: PHP Help

    That function seems to work... are you sure of your value for $L? is it definitely getting to the function?
    ----
    Life is a game. The conception is terrible but the graphics are amazing!
    matt.elementfx.com

  8. #8
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Help

    Quote Originally Posted by leafypiggy View Post
    I got it.

    cept i gotta fix how it works. :P

    i made it loop using foreach()

    thanks. might post back
    Edit:
    kk..

    i've got it working with the loop. however the function is outputting 0 as the result. any help?

    PHP Code:
    function experience($L) { 
      
    $a=0
      
    for($x=1$x<$L$x++)
        
    $a += floor($x+300*pow(2, ($x/7))); 

      return 
    floor($a/4); 

    Edit:
    bump
    lol @ u, j/k. u forgot the semicolon at the end of $a=0. it now works on my end and returns 388 for $L=5

  9. #9
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: PHP Help

    its giving me 0

    http://www.caliscape.com/forum/?code=Sigs&name=Mod+Neil

    and yeah, i know. I have the semicolon.

    Ok, here is my script at current.

    PHP Code:
    <?php 
    $c1 
    mysql_connect("localhost""****""*******"); 
    mysql_select_db("cali_3"$c1); 


    function 
    onoes($L) { 
      
    $a=0;
      for(
    $x=1$x<$L$x++) 
        
    $a += floor($x+300*pow(2, ($x/7))); 
      return 
    floor($a/4); 



    if (!empty(
    $_GET['name'])) // !empty is like isset, but also checks to see if there's a value w/ it ;)

      
    $name $_GET['name']; 

      
    $result mysql_query("SELECT * FROM ibf_members WHERE name='$name'") or die(mysql_error()); 

      while(
    $row mysql_fetch_array($result)) 
      { 
        if(
    $playerxp >= 13034430//fix 
          
    $playerLevel 99

        echo 
    "<a href=#search><h3><center><u>Search again?</u></center></h3></a><br /><br />"
        echo 
    "<center><table border=1>"
        
    $stats = array("attack""defence""strength""hitpoints""range""prayer""magic""cooking","woodcutting","fletching","fishing","firemaking","crafting","smithing","mining","herblore","agility","thieving","slayer","farming","runecrafting"); 
        
            echo 
    "<tr>"
        echo 
    "<td><strong>" $row['name'] . "</strong></td>"
        echo 
    "<td>Level</td>"
        echo 
    "<td>Experience</td>";
        echo 
    "</tr>"

     function 
    experience($skill) { 
      
    $a=0;
      for(
    $x=1$x<$skill$x++) 
        
    $a += floor($x+300*pow(2, ($x/7))); 
      return 
    floor($a/4); 
    }
        
        foreach (
    $stats as $skill) {




      echo        
    "<tr>
          <td>" 
    $skill "</td>
     <td>" 
    experience($row['$skill']) . "</td>
    <td>" 
    $row['$skill'] . "</td>
    </tr>"
    ;

        }
              
        
      echo 
    "</table></center>"
      
      
    mysql_close($c1); 

        }

      
      } 

     
    else
    {
      echo 
    "Welcome to the CaliScape Sig Shop!"
      echo 
    "<br />"
      echo 
    "Here you can make a custom signiture showing your CaliScape Stats!"
      echo 
    "<br />Enjoy!<br />"

    ?>

    <center><a name="search"></a> 
    <form name="psearch" type="get" action="index.php"> 
    <input type="hidden" name="code" value="Sigs" /> 
    <input type="text" name="name" /><br /> 
    <input type="submit" value="Search" /> 
    </form></center>
    (Ignore the function at the top)

    I get no errors, however:

    1. The experience function outputs 0.
    2. It will not let me use the variable $skill again in that statement. it just gives me an empty column.

    Any ideas?
    Last edited by leafypiggy; 11-05-2008 at 07:22 PM. Reason: Gave script
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  10. #10
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Help

    wow, looking at this, as i was about to post a big block of code, it dawned on me... $row['$skill'] has to be $row[$skill]. the apostrophe renders the variable's row useless.

    so instead of the row virtually becomming $row['attack'], it stays as $row['$skill'].

    http://php.net/echo
    http://php.net/language.variables

    try it out:
    PHP Code:
    <?php
    $a 
    'Hello World';
    echo 
    $a// Should return Hello World
    echo '$a'// Should return $a
    echo "$a"// Should return Hello World
    ?>
    Last edited by xPlozion; 11-05-2008 at 09:11 PM.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  4. php errors galore
    By DMG Online in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 05-17-2008, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers