Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 38

Thread: reordering content

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

    Default

    Let's say that my password, username, database and everything is test. Is the code right if it is like this? And also the connections are right.


    <?php
    $link = mysql_connect("localhost",$test_test,$test);
    mysql_select_db("test_test");
    $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>
    Last edited by afe; 01-12-2008 at 10:35 PM.

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

    Default

    So? Is that code right or wrong?

  3. #23
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    No, you need to define them somewhere outside the function.

    PHP Code:
    $db_user "test_test";
    $db_pass "test";
    $db_table "test"
    Then use $db_user instead of $test_test, etc...
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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

    Default

    Sorry, but I'm not understanding... For the spots where it says $db_user, $db_pass do I put my database info? Also what's $db_table? Please and thank you.

  5. #25
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    this:

    Code:
    $link = mysql_connect("localhost",$test_test,$test);
    mysql_select_db("test_test");
    Is saying variable "link" is equal to connecting to SQL database where database location is localhost, user on database is $test-test, and password is $test. open the database named test_test.

    Anything with the $ in front is a variable. If the variable isn't defined, it doesn't know what to put there. So you have to define them before it will work.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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

    Default

    My database info does not contain anything with "$" so would I still have to put a $ infront of it?

  7. #27
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    okay, allow me to try again...

    in PHP there are variables. Variables are defined by a preceding $.

    So If I say:

    PHP Code:
    $name "BLiZZ"
    I am telling php that anytime from now on in this script that is sees "$name" to use "BLiZZ" instead.

    So If I write:

    PHP Code:
    echo' $name; 
    The screen will show:

    PHP Code:
    BLiZZ 
    If I write:

    PHP Code:
    Echo' 'My name is $nameI like my name $nameMy mother gave me the name $name'; 
    I would show on the page:

    PHP Code:
    My name is BLiZZI like my name BLiZZMy mother gave me the name BLiZZ 
    So, in your case...

    PHP Code:
    $link mysql_connect("localhost",$test_test,$test); 
    It is looking for what exactly $test_test and $test are = to. You haven't defined $test_test so there is nothing it is = to.

    If your database username is "Mike" and the password is "house" the you would do seomthing like this:

    PHP Code:
    $test_test "Mike";
    $test "house";
    $link mysql_connect("localhost",$test_test,$test); 
    THEN the script can have something to replace the variable with.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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

    Default

    Cant I just get rid of the "$" and just type in the exact database information?

  9. #29
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    yes you can
    Code:
    $link = mysql_connect("host","user","pass");
    Last edited by Master_script_maker; 01-13-2008 at 06:33 PM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  10. #30
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Of course I only said that about 11 posts ago..

    Quote Originally Posted by BLiZZaRD View Post
    One of 2 ways...

    Either define $user and $pass and $database with the terms:

    PHP Code:
    $user "username"
    etc.. 
    Or, just like you have it above just remove the $'s for those 3 spots.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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
  •