Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error I can't find!

    Hi please does anyone know why I am getting an encapsulated t string error on line 17 with this code? I cant find the problem

    Code:
    <?php
    
    $default_sort = 'CustomerID';
    $allowed_order = array ('CustomerID','Name', 'Address','Postcode','Telephone','Email');
    
    if (!isset ($_GET['order']) || 
        !in_array ($_GET['order'], $allowed_order)) {
        $order = $default_sort;
    } else {
        $order = $_GET['order'];
    }
    
    
    mysql_connect ('localhost','user','pass');
    mysql_select_db ('database');
    
    
    $ad = (isset($_GET['ad']) && $_GET['ad'] == 'desc') 'desc' : 'asc';
    $query = "SELECT * FROM table ORDER BY $order $ad";
    $result = mysql_query ($query);
    
    
    $numrows = mysql_num_rows($result);
    if ($numrows == 0) {
        echo "No data to display!";
        exit;
    }
    
    
    $row = mysql_fetch_assoc ($result);
    echo "<TABLE border=1>Click on a column heading to sort the column assendingly <p> \n";
    echo "<TR>\n";
    foreach ($row as $heading=>$column) {
            echo "<TD>";
        if (in_array ($heading, $allowed_order)) {
    		$tad = ($ad == 'asc' && $order == $heading) ? 'desc' : 'asc';
            echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&ad=$tad\">$heading[/url]";
        } else {
            echo $heading;
        }                
        echo "</TD>\n";
    }
    echo "</TR>\n";
    
    mysql_data_seek ($result, 0);
    while ($row = mysql_fetch_assoc ($result)) {
        echo "<TR>\n";
        foreach ($row as $column) {
            echo "<TD>$column</TD>\n";
        }
        echo "</TR>\n";
    }
    echo "</TABLE>\n";
    
    ?>

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    I don't use the ternary operator very often, but I think the question mark is required.

    PHP Code:
    $ad = (isset($_GET['ad']) && $_GET['ad'] == 'desc') ? 'desc' 'asc'

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Spot on, quick one though - do you know why only the first letter from the heading is being displayed and not the whole heading as was happening before I edited the code to sort assending and desending?

    Many thanks

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Nothing jumps out at me as something that would cause that specific problem. I would do a view source to verify the HTML is right or wrong. Then verify your SQL statement is returning exactly what you expect. Then you can limit it to your PHP causing the issue.

    This line seems a bit off:
    PHP Code:
    echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading&ad=$tad\">$heading[/url]"
    The closing url should probably be an </a>.

    I don't use the curly brackets. That's not to say it won't work but that's something I can't verify off the top of my head either.


  •  

    Posting Permissions

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