Jump to content

hahaitwork

Members
  • Posts

    98
  • Joined

  • Last visited

Posts posted by hahaitwork

  1. ah.. i see, well I tried to add that now and got this..

    Warning: mysqli::mysqli(): (42000/1044): Access denied for user 'loff_production'@'%' to database 'high_scores_avoidthecars' in /customers/a/3/f/loff-production.com/httpd.www/avoidthecars/highscore.php on line 9 Warning: mysqli::query(): Couldn't fetch mysqli in /customers/a/3/f/loff-production.com/httpd.www/avoidthecars/highscore.php on line 21 Fatal error: Call to a member function fetch_assoc() on a non-object in /customers/a/3/f/loff-production.com/httpd.www/avoidthecars/highscore.php on line 22

     

    Just to update you guys.. It's just the sorting that needs to be done, check out http://forums.phpfreaks.com/topic/271954-loading-only-tables-that-contain-text/ for an update, will close this in a few days. It's easier to follow the other threat

  2. It works pretty much the same way in all languages. Most importantly, MySQL and PHP are identical in this area (except for NULL values).

    The MySQL manual also has all the information you need on this, though may be a bit harder to read.

     

    So I tried that "WHERE" thingy.. not 100% where to put it but I thougth and I guessed Behind OR in front of "ORDER by" and got errors :( hmm..

     

    $result = mysql_query("SELECT name, score FROM high_scores_avoidthecars ORDER BY score DESC WHERE name != '' ");

  3. Okey, my script is working mostly as I want. I need a line that picks top 50, and only choose those who submitted with name, if the name plate is blank.. the score should not come up.

    Here is the line I guess you have to change:

     

    $result = mysql_query("SELECT name, score FROM high_scores_avoidthecars ORDER BY score DESC ");

     

    Things that should work:

     

    1. Sort out who got the highest score BUT also who submitted it first (checks highest/lowest id) (The lowest id number is also the one that sumbitted first*)

    2. Top 50 scores only

    3. Only show scores that have a Name submitted as well.

     

    The database contain: id, name, score

    id = auto increase

    name = the players submitted name

    score = how much they scored

     

    Extra note:

    I have already a thread that is a bit the same, but will keep both open a little then close the other one.

    Here is the second thread that will be closed in a few days

  4. Sorry about that the mysqli connect is in my included file. You need

     

    $mysqli = new mysqli('host', 'user', 'password', 'database');

     

    before the query.

    ahh.. I just copied what I had to connect.. my bad :) Will try it again!

    Here is what I tried, got error on line 22 this time (which is the marked text)

    Fatal error: Call to a member function fetch_assoc() on a non-object in /customers/a/3/f/loff-production.com/httpd.www/avoidthecars/highscore.php on line 22

     

    <html>
    
    <head>
    
    <link href="styleofc.css" rel="stylesheet" type="text/css">
    </head>
    
    <?php
    $mysqli = new mysqli("x","x","x");
    
    $sql="SELECT
    @rownum := @rownum + 1 AS Rank
    , name as Name
    , score as Score
    , id as ID
    FROM high_scores_avoidthecars
    JOIN (SELECT @rownum := 0) as initialise
    ORDER BY score DESC, id
    LIMIT 50";
    
    $res = $mysqli->query($sql);
    $row = $res->fetch_assoc();		   <-------------- LINE 22! <-------------------------------
    echo "<table border='1'><tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n";
    do {
    echo "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n";
    } while ($row = $res->fetch_assoc()) ;
    echo "</table>\n" ;
    $res->free();
    ?>
    </html>

  5. Is this what you wanted

    <?php
    include("testDBconnect.php");
    
    $sql="SELECT
    @rownum := @rownum + 1 AS Rank
    , name as Name
    , score as Score
    , id as ID
    FROM high_scores_avoidthecars
    JOIN (SELECT @rownum := 0) as initialise
    ORDER BY score DESC, id
    LIMIT 50";
    
    $res = $mysqli->query($sql);
    $row = $res->fetch_assoc();
    echo "<table border='1'><tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n";
    do {
    echo "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n";
    } while ($row = $res->fetch_assoc()) ;
    echo "</table>\n" ;
    $res->free();
    ?>

     

    Error:

    Fatal error: Call to a member function query() on a non-object in /customers/a/3/f/loff-production.com/httpd.www/avoidthecars/highscore.php on line 25

     

    Line 25:

    $res = $mysqli->query($sql);

  6. You can do that through the query, but it is easier, in my opinion, to just do that through the display logic

    $position = 0;
    while($row = mysql_fetch_assoc($result))
    {
    $position++; //Use this value as the number to the left of the player name
    
    //Code to display the record follows
    }

     

     

    The image you linked to shows the records sorted by best score. Since you don't show the date, there is no way to determine if it is sorting by date as you want. Do your records have a date field? If so, use that. Otherwise you could use the ID field IF that is an auto-increment field AND you only create records and do not edit them. If you don't think the records are in the appropriate order provide:

     

    1. A similar image as you posted, but add the ID and/or date field that you are using for sorting

    2. The actual query that you are currently using.

     

    I do not have a date but I do have "ids" so, the lowest id will be the first that was submitted anyhow.

    I know how I want it, the problem is i'm not sure how to write the script .. =)

  7. If you post an example of what you got, along with how you'd want the end result to look, I'm sure someone can help you out.

     

    http://loff-production.com/highscores/avoid-the-cars.html

    Here is what I got at the moment.

    1. I need numbers next to the players name (hopefully in a own little table) left of the name.

    2. I need them sorted after best score, but ALSO after who submitted first of those with the same score.

  8. Ehm, how come it got so silence? was it because my answer was totally wrong, or because people got unsure about what it could be?

    if it is a easy edit some how, any idea how I could make it say like ?

    | 1 | *name* | *score* |

    | 2 | *name* | *score* |

    | 3 | *name* | *score* |

    | 4 | *name* | *score* |

     

    That means, somehow add 1-50 on the side of the name and score :)

  9. IF id=13 should sort before id=34, then you want ASC for id (or leave out ASC as it's the default)

     

    ORDER BY score DESC, id LIMIT 50

    None of them worked actually.. could be because it doesn't select id.. let me retry.

     

    $result = mysql_query("SELECT id, name, score FROM high_scores_avoidthecars ORDER BY score DESC, id LIMIT 50 ");
    

     

    Tried this.. still not working as it should >_<

  10. BY score DESC, id ASC

    Yep, it's that simple. ;)

     

    Though, you really should strip those &nbsp's from your code, and use CSS paddings/margins instead. Not only are you abusing the non-breaking space character to create your layout, which should be controlled by the stylesheet, but you've also done it wrong. :P

     

    I know that coders will wrist in pain when they see it but for me it works perfectly and I'm not going to change it for this "project" :)

    Your code made NO change actually :(

    What is "ASC" by the way?

  11. I need the script to sort it after score, but also after id, because the person on top should be the first person that submitted the score.

    like if someone got id 13, score 15 and someone later gets id 34 and score 15, it should be the person with id 13 that is on Top.

    Any ideas? I think it could be something like "BY score, id" or so? tride that but then it ended up the showing the ID and score the wrong way.

     

    $result = mysql_query("SELECT name, score FROM X ORDER BY score DESC LIMIT 50");
    
    echo "<table border='20' width='450px'>
    <tr>
    <th>Name</th>
    <th>Score</th>
    </tr>";
    while($row = mysql_fetch_array($result))
     {
    
     echo "<tr>";
     echo "<td>" .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp'. $row['name'] .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp'. "</td>";
     echo "<td>" .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp'. $row['score'] .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp'. "</td>";
     echo "</tr>";
     }
    echo "</table>";
    mysql_close($con);
    ?>
    </html>
    

  12. Hello, I need the script to be able to only pick the 50 best scores, and not every score that is submitted.

    Any idea? It has to be the 50 best of course, not just randomly 50.

    Is it something that can be fixed with > or is it abit more advance code?

     

    <html>
    <head>
    <link href="styleofc.css" rel="stylesheet" type="text/css">
    </head>
    <center>
    <div style="position:absolute; margin-left:450px; margin-top:0px; TOP:100px; color:#D8D8D8;" border="2" >
    <?php
    $con = mysql_connect("loff-production.com.mysql","loff_production","v4rANidp");
    if (!$con)
     {
     die('Could not connect: ' . mysql_error());
     }
    mysql_select_db("loff_production", $con);
    $result = mysql_query("SELECT name, score FROM high_scores_avoidthecars ORDER BY score DESC");
    
    echo "<table border='20'>
    <tr>
    <th>Name</th>
    <th>Score</th>
    </tr>";
    while($row = mysql_fetch_array($result))
     {
    
     echo "<tr>";
     echo "<td>" .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp'. $row['name'] .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp'. "</td>";
     echo "<td>" .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp'. $row['score'] .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp'. "</td>";
     echo "</tr>";
     }
    echo "</table>";
    
    mysql_close($con);
    ?>
    </div>
    </center>
    </html>
    

  13. change your query to this :

    SELECT name, score FROM members ORDER BY name ASC, score DESC

    asssming you primarily want to alphabetize your members first and then order by score, if you just want to purely order by score alone then just use

    SELECT name, score FROM members ORDER BY score DESC

     

    and PLEASE use code tags!!

     

    Thanks I did find a script to sort it actually but it sorted the wrong way :) so thanks for your script!

    ehm, true.. sry I forgot about the code tags.

  14. Hello,

     

    I'm loading data from my database but now I need them sorted as well, after "score".

    I need the highest score to be on the top, and let's say it shows a total of 50.

    that means if someone have 100 score, and rest is 99-10 and the last is 1.. I want 100 on top, 1 on buttom and 99-10 between.. bet you understood it :)

     

    Any ideas? my script is this so far:

     

    <?php

    $con = mysql_connect("localhost","root","");

    if (!$con)

    {

    die('Could not connect: ' . mysql_error());

    }

     

    mysql_select_db("my_db", $con);

     

    $result = mysql_query("SELECT * FROM members");

     

    echo "<table border='1'>

    <tr>

    <th>Name</th>

    <th>Score</th>

    </tr>";

     

    while($row = mysql_fetch_array($result))

    {

     

    echo "<tr>";

    echo "<td>" . $row['name'] . "</td>";

    echo "<td>" . $row['score'] . "</td>";

    echo "</tr>";

    }

    echo "</table>";

     

     

     

    mysql_close($con);

    ?>

  15. Ok, for real, read this:

     

    In order to perform an action without refreshing the page, you must use javascript. If said action interacts with the server, you must use AJAX.

     

    Go read it again to be sure you understand it.

     

    Now that you get that: You can use named anchor tags and hash marks in your URLs so that, when you refresh the page, the page automatically scrolls back down to a specific target. This solves what you're complaining about ("page scrolls up") without forcing you to learn and implement ajax.

     

    Okey.. I understood it better now, but I'm not sure how to fix it as my script is like this:

     

    This is mainly the parts with + and - and remove.

    Tried a few things but ending up with errors, it's mostlying trying to set <a name="x"></a> and call it insted of using the $page

     

    if (isset ($_GET['add'])) {
    $quantity = mysql_query ('SELECT id, quantity FROM products WHERE id=' .mysql_real_escape_string ((int) $_GET ['add']));
    while ($quantity_row = mysql_fetch_assoc ($quantity)) {
    if ($quantity_row['quantity'] !=$_SESSION['cart_'.(int)$_GET['add']]) {
    $_SESSION['cart_'.(int)$_GET['add']]+='1';
    
    }
    }
    header('Location: '.$page);
    }
    if (isset($_GET['remove'])) {
    $_SESSION['cart_'.(int)$_GET['remove']]--;
    header('Location: '.$page);
    }
    if (isset($_GET['delete'])) {
    $_SESSION['cart_'.(int)$_GET['delete']]='0';
    header('Location: '.$page);
    }
    

     

     

    echo
    "<p style='width:250px; float:left;'>".
    					 '<table border="1" >'.'<tr>'.'<td WIDTH="250px" HEIGHT="80px" float:left; ">'.'<center>'.$get_row['name'].'<br />'.$get_row['description'].'</center>'.'</td>'.'</tr>'.'<td WIDTH="60%" HEIGHT="50px" ">'.'<center>'.' x '.$ids[$get_row['id']].' * €'.number_format ($get_row['price'],0).' = €'.number_format($sub, 0).
    				 '</td>'.'</tr>'.'<tr>'.'</center>'.'<tr>'.'<td WIDTH="200px" HEIGHT="0px"'.'<center>'
     .'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
     <a href="cart.php?remove='.$get_row['id'].'"><img src="subtract.png" border="0" style="height: 20px; width: 35px" ></a> &nbsp&nbsp
    
    					 <a href="cart.php?add='.$get_row['id'].'"><img src="pluss.png" border="0" style="height: 20px; width: 35px" ></a> &nbsp&nbsp
    
    					 <a href="cart.php?delete='.$get_row['id'].'"><img src="delete.png" border="0" style="height: 20px; width: 50px" ></a></p>'
     .'</center>'
     .'</td>'
     .'</tr>'
    
     .'</td>'.'</tr>'.'</table>';
    

×
×
  • 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.