SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP - Matches Help

    Ok, i'm having some troubles, i can't get this working. Basically, what im trying to do is loop a phrase 6 times.

    The echo should say
    LoA vs Opponent score - score
    but instead its result is
    LoA vs -

    From what i can tell, its not reading the variables or something.
    I'm pretty new to PHP, so hopefully i can get some detailed help.


    * PS: It shows the proper result without the looping, but i need the loop to limit it to echo'ing it 6 times, as without it, it will just echo everything.
    It works when "while ($x < $number) {" is "while ($row = mysql_fetch_array($result)) { ", but otherwise it just won't work!

    PHP Code:
     <?PHP

      
    include "config2.php";

    //Connect to server
    $connection mysql_connect($server $username$mysql_password) or die ("Couldn't connect to server");

    //Select Database
    $db mysql_select_db($database$connection) or die ("Couldn't select Database");

    //mySQL Query
    $sql "SELECT * FROM $table ORDER BY id DESC";

    //Execute Query
    $result mysql_query($sql$connection) or die ("couldn't execute query.");

    $number 6;
    $x 0;
    //Take results of query and display them
    while ($x $number) {
    $id $row["id"];
    $opponent $row["opponent"];
    $final $row["final"];
    $final2 $row["final2"];

      if (
    $final>$final2)
      
    $color2 "g";
      elseif (
    $final2>$final)
      
    $color2 "r";
      elseif (
    $final==$final2)
      
    $color2 "d";

    // to test whether $number is odd you could use the arithmetic
    // operator '%' (modulus) like this
    if( $odd $id%)
    {
      
    // $odd == 1; the remainder of 25/2
      
    $inset2 "b";
    }
    else
    {
      
    // $odd == 0; nothing remains if e.g. $number is 48 instead,
      // as in 48 / 2
      
    $inset2 "a";


    $namenumber $x 1;
    echo 
    "<tr class='latest_inset_$inset2'><td width='160' height='17'>&nbsp;  LoA vs ";
    echo 
    "$opponent";
    echo 
    "</td>
    <td width='46'><span class='matches_
    $color2'>$final - $final2</span></td>
                            </tr>"
    ;
    ++
    $x;
    }

    ?>

  2. #2
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT: Never mind, I missed part of your post.

  3. #3
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use

    PHP Code:
     while ($row mysql_fetch_array($result)) { 
    Just use LIMIT in the database query to limit it to 6 results.

    PHP Code:
      //mySQL Query
     
    $sql "SELECT * FROM $table ORDER BY id DESC LIMIT 6"

  4. #4
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh wow, that was simple.

    thank you very much.

  5. #5
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your welcome.

    Coding is a complex arrangement of many simple things.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •