SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru godsfshrmn's Avatar
    Join Date
    Mar 2001
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dunno what is wrong with the code. It dosen't return anything. Any idea? The one that is giving me problems is the one with the BETWEEN command in it.

    Code:
     
    if(!$submit) {
    ?>
    <p><font size="2" face="Tahoma">Please select a file below to view it's stats.</font></p>
    <form method="POST" action="<?php echo $PHP_SELF; ?>">
      <div align="center">
        <center>
        <table border="0" height="9" cellpadding="0">
          <tr>
            <td width="100%" height="1"><select size="1" name="delete" style="border-style: solid; border-width: 1">
    
    <?php
    $query = "SELECT * FROM files ORDER BY id DESC ";
    
    $result = MYSQL_QUERY($query);
    
                if ($result) {
                    while ($r = mysql_fetch_array($result)) {
                        $desc = $r["desc1"];
                        $id = $r["id"];
    echo "<option value=\"$id\">$desc</option>";
    
    }
    mysql_free_result($result);
    }
    ?>
    </table><br>
    
              </select></td>
          </tr>
    <tr>
            <td width="100%" height="1"><font size="2" face="Tahoma">View Records
                </font><input type="text" name="rec1"> through <input type="text" name="rec2">
    </td></tr>
          <tr>
            <td width="100%" height="25"><input name="submit" type="submit" value="Submit" style="border-style: solid; border-width: 1"></td>
          </tr>
        </table>
        </center>
      </div>
    </form>
    
    <?php
    }
    
    if($submit) {
    
    $query = "SELECT cnt FROM dtstats  WHERE id = '$id' ORDER BY cnt DESC LIMIT 1";
    $result = MYSQL_QUERY($query);
    $r = mysql_fetch_array($result); 
    $cnt = $r["cnt"];
    
    echo "<font size=\"2\" face=\"Tahoma\">$cnt people have downloaded this file.</font>";
    
    $query = "SELECT * FROM dtstats WHERE id = '$id' ORDER BY id DESC BETWEEN $rec1 and$rec2";
    $result = MYSQL_QUERY($query);
    
                if ($result) {
                    while ($r = mysql_fetch_array($result)) {
                        $name = $r["name"];
                        $email = $r["email"];
                        $ip = $r["ip"];
                        $browser = $r["browser"];
                        $datet = $r["time"];
    
    echo "<table width=50% bgcolor=#C0C0C0 border=1 bordercolor=black cellpadding=0 cellspacing=0>
    <tr><td bgcolor=#203F70><font face=arial size=1><b>User:</b></font></td>
    <td><font color=#000000 face=arial size=1><a href=mailto:$email>$name</a></font></td></tr>
    <tr><td bgcolor=#203F70><font face=arial size=1><b>User IP:</b></font></td>
    <td><font color=#000000 face=arial size=1>$ip&nbsp;</font></td>
    <tr><td bgcolor=#203F70><font face=arial size=1><b>Browser: </b></font></td>
    <td><font color=#000000 face=arial size=1>$browser&nbsp;</font></td></tr>
    <tr><td bgcolor=#203F70><font face=arial size=1><b>Date: </b></font></td>
    <td><font color=#000000 face=arial size=1>$datet&nbsp;</font></td></tr>
    </table><br>";
    }
    mysql_free_result($result); 
    			}
    }
    s c r i p t s f o r y o u . n e t
    ScriptsForYou

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT * FROM dtstats WHERE id = '$id' ORDER BY id DESC BETWEEN $rec1 and $rec2

    This is not going to work. BETWEEN is a comparison operator. Eg;

    y BETWEEN x AND z = TRUE

    This is the same as saying

    ( x <= y AND y <= z ) = TRUE

    The value y falls between the values x and z evaluates to TRUE.

    So BETWEEN doesn't belong in an ORDER BY clause, it belongs in a SELECT or WHERE clause.

    Can you tell us in plain speek what you want this SQL query to do, and I'll try and help

  3. #3
    SitePoint Guru godsfshrmn's Avatar
    Join Date
    Mar 2001
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The user will enter how many records she wants to view. Like view records 9 through 90 or something like that.
    s c r i p t s f o r y o u . n e t
    ScriptsForYou

  4. #4
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you wanna let user see number of records she choose Use LIMIT. It is very nice word in SQL.
    examples:
    select * from table LIMIT offset, numberofcolumns
    select * from table LIMIT 10; # Retrieve first 10 rows
    select * from table LIMIT 9,81; # Retrieve rows 10 to 90

    Hope this is an answer to your question

  5. #5
    SitePoint Guru godsfshrmn's Avatar
    Join Date
    Mar 2001
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, would 2 variables work w/ that? Like LIMIT $num1,$num2?
    s c r i p t s f o r y o u . n e t
    ScriptsForYou

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep - PHP substitutes the value of the variable in the SQL string *before* it is sent to the MySQL server.

  7. #7
    SitePoint Guru godsfshrmn's Avatar
    Join Date
    Mar 2001
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet. It works. Thanks for the help guys.
    s c r i p t s f o r y o u . n e t
    ScriptsForYou


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
  •