Page 4 of 4 FirstFirst ... 234
Results 31 to 38 of 38

Thread: reordering content

  1. #31
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ohh I see thanks!

  2. #32
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Can you tell me why it doesn't work please? Thanks.

  3. #33
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Define "doesn't work". Personally, I think you should go and look over http://php.net and http://www.php-mysql-tutorial.com so that you can learn PHP/MySQL coding. If you need help on a specific item, come back and ask about that issue; but don't have us do all the work for you. Just my two cents.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #34
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    When I click on the "A-Z" or "Z-A" or the others, it does not reorder.

  5. #35
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    In the code you posted, I don't see anywhere that you called a query to the database (other than assigning $q as the query to be sent). The content will not sort the way you have the page set up because you have it hardcoded into the page instead of pulling that data from the db.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #36
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Umm, well I changed it. And I put quotes around them. Here's the code. I changed the actual database access just for security.

    HTML Code:
    <?php
        $link = mysql_connect("localhost","USERNAME_USERNAME","PASSWORD");
        mysql_select_db("USERNAME_DATABASE);
        $type = ((isset($_GET["sorttype"])?$_GET["sorttype"]:"1") == "1")?"DESC":"ASC";
        /*
            this is really the equivelant of
            $type = "";
            if(isset($_GET["sorttype"]))
                $type = $_GET["sorttype"];
            else
                $type = "1";
            $type_cmp = $type;
    
            if($type_cmp == "1")
                $type = "DESC";
            else 
                $type = "ASC";
            unset($type_cmp);
            
        */
        $col = ($_GET["sortname"]);
        $q = "SELECT * FROM records ORDER BY `$col` $type";
    ?> 
    
    <?php require('_drawrating.php'); ?>
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript" language="javascript" src="js/behavior.js"></script>
    <script type="text/javascript" language="javascript" src="js/rating.js"></script>
    <link rel="stylesheet" type="text/css" href="css/rating.css" />
    </head>
    
    <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>Sorth by: <a href="sortexample.php?sorttype=1&amp;sortname=Name">Z to A</a>
    <a href="sortexample.php?sorttype=0&amp;sortname=Name">A to Z</a>
    <a href="sortexample.php?sorttype=1&amp;sortname=Rating">Top rated to Least</a>
    <a href="sortexample.php?sorttype=0&amp;sortname=Rating">Least rated to Top</a></td>
      </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="14%"><p>funny picture </p>
          <p>CONTENT</p></td>
        <td width="86%">Rating: <?php echo rating_bar('8xxa','5'); ?>
          <p>&nbsp;</p></td>
      </tr>
      <tr>
        <td><p>cool picture </p>
          <p>CONTENT</p></td>
        <td>Rating: <?php echo rating_bar('8x41','5'); ?></td>
      </tr>
      <tr>
        <td><p>test picture</p>
        <p>CONTENT</p></td>
        <td>Rating: <?php echo rating_bar('84854','5'); ?></td>
      </tr>
      <tr>
        <td><p>test 1 picture</p>
        <p>CONTENT</p></td>
        <td>Rating: <?php echo rating_bar('8454','5'); ?></td>
      </tr>
      <tr>
        <td><p>5 cool picture</p>
        <p>CONTENT</p></td>
        <td>Rating: <?php echo rating_bar('8454654a','5'); ?></td>
      </tr>
      <tr>
        <td><p>number test</p>
        <p>CONTENT</p></td>
        <td>Rating: <?php echo rating_bar('154545','5'); ?></td>
      </tr>
      <tr>
        <td># character testCONTENT</td>
        <td>Rating: <?php echo rating_bar('8xxa','5'); ?></td>
      </tr>
      <tr>
        <td><p>hello test </p>
          <p>CONTENT</p></td>
        <td>Rating: <?php echo rating_bar('815454','5'); ?></td>
      </tr>
      <tr>
        <td><p>1 test</p>
        <p> CONTENT</p></td>
        <td>Rating: <?php echo rating_bar('822a','5'); ?></td>
      </tr>
      <tr>
        <td><p>z test</p>
        <p> CONTENT</p></td>
        <td>Rating: <?php echo rating_bar('454xa','5'); ?></td>
      </tr>
    </table>
    </body>
    </html>

  7. #37
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok, let me try to explain again. You are logging into the database, but you are not getting any content from that database. Your code should look something like this instead of what you have above:

    Code:
    <?php
        $link = mysql_connect("localhost","USERNAME_USERNAME","PASSWORD");
        mysql_select_db("USERNAME_DATABASE);
        $type = ((isset($_GET["sorttype"])?$_GET["sorttype"]:"1") == "1")?"DESC":"ASC";
        /*
            this is really the equivelant of
            $type = "";
            if(isset($_GET["sorttype"]))
                $type = $_GET["sorttype"];
            else
                $type = "1";
            $type_cmp = $type;
    
            if($type_cmp == "1")
                $type = "DESC";
            else 
                $type = "ASC";
            unset($type_cmp);
            
        */
        $col = ($_GET["sortname"]);
        $q = "SELECT * FROM records ORDER BY `$col` $type";
    ?> 
    
    <?php require('_drawrating.php'); ?>
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript" language="javascript" src="js/behavior.js"></script>
    <script type="text/javascript" language="javascript" src="js/rating.js"></script>
    <link rel="stylesheet" type="text/css" href="css/rating.css" />
    </head>
    
    <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>Sorth by: <a href="sortexample.php?sorttype=1&amp;sortname=Name">Z to A</a>
    <a href="sortexample.php?sorttype=0&amp;sortname=Name">A to Z</a>
    <a href="sortexample.php?sorttype=1&amp;sortname=Rating">Top rated to Least</a>
    <a href="sortexample.php?sorttype=0&amp;sortname=Rating">Least rated to Top</a></td>
      </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <?php
      $result = mysql_query($q);
      if (!mysql_num_rows($result)) {
    ?>
     <tr>
      <td colspan="2"><h4> No Results Found! </h4></td>
     </tr>
    <?php
      }
      else {
        while ($info = mysql_fetch_array($result)) {
    ?>
     <tr>
      <td><?php echo $info['Name'];?></td>
      <td><?php echo $info['Rating'];?></td>
     </tr>
    <?php
        }
      }
    ?>
    </table>
    </body>
    </html>
    Hope this helps.
    Last edited by thetestingsite; 01-25-2008 at 07:39 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #38
    Join Date
    Nov 2007
    Posts
    346
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, I get this now. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/athletes/public_html/sortexample.php on line 48
    No Results Found!

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
  •