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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question on how to Alphabetize - PHP & MySQL

    So we paid someone to build us a site (http://www.ultimatefreebielist.net) using php & mysql. He did most of it, but left some things undone and we haven't been able to contact him in a long time. I am a complete php/sql newbie, but I am not terribly stupid (at least I don't think so).

    My question is in reference to http://www.ultimatefreebielist.net/c...php?company=32
    As you can see, the sites aren't listed alphabetically and they should be. I am wondering how to get this done. I am pretty sure that the page I need to edit is the CompanyView.php (in the templates folder) page, but I may be wrong. Here is the code that outputs the above page

    PHP Code:
    <h1><?=$company->get('company')?></h1>

       <?php
        
    if( !is_null($company) ) {
            
    $arr = array( 'street''city''state''zip''phone''fax');
            foreach( 
    $arr as $v) {
                if( 
    $company->get($v)) {
                    print 
    $company->get($v) . "<br />";
                }
            } 
        }
        
    ?>

    <h3>Sites by this company</h3>

    <?php foreach($sites as $site): ?>
        <a href="site.php?site=<?=$site['id']?>"><?=$site['name']?></a><br />
    <?php endforeach; ?>
    But just in case I am wrong, here is the code from the company.php page (in the public_html folder.... which I believe outputs the company page - http://www.ultimatefreebielist.net/company.php)

    PHP Code:
    <?php

    require_once 'config.php';
    $coFinder = new CompanyFinder($conn'companys');

    $id get_param('company');

    if( 
    $id ) {
        
        if( !
    preg_match("/^[0-9]{1,32}$/"$id )) {
            
    $err[] = "Invalid company";
        }
        
    //if( !$company = $conn->selectOne("select company from companys where id=?", $id ) ) {
        
    if( !$company $coFinder->find($id)) {        
            
    header"HTTP/1.1 404 Not Found" );
            
    $msg "<h2>Requested company not found</h2>";
            
    $template "Message.php";
            
        } else {
            
            
    $sites $conn->selectRows("select sites.* from sites where company_id=?"$id);
            
    $template 'CompanyView.php';
        }
        
        
    } else {
        
    $sql "select * from companys order by company";
        
    $rows $conn->selectRows($sql);
        if( !
    $rows) { $rows = array(); }
        
    $template "Companies.php";
    }

    if(
    $err) { $template "error.php"; }

    include 
    'main.php';
    ?>


    I have been searching different forums and trying to read up on the subject, but I haven't had any luck. If anyone knows how to do this and could tell me, it would be such a great help! Thanks

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    I think you did a pretty good job of detective work. I am pretty sure that the following line is the query that gets executed when a company=xx is specified -
    PHP Code:
    $sites $conn->selectRows("select sites.* from sites where company_id=?"$id); 
    To get these ordered alphabetically, change this to -
    PHP Code:
    $sites $conn->selectRows("select sites.* from sites where company_id=? order by name"$id); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OMG... I love you and want to have your babies!!! Well, not really, but thanks so much!!!


  •  

    Posting Permissions

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