View Full Version : Question on how to Alphabetize - PHP & MySQL

02-24-2007, 04:20 AM
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/company.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


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)


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

02-24-2007, 04:38 AM
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 -

$sites = $conn->selectRows("select sites.* from sites where company_id=?", $id);To get these ordered alphabetically, change this to -

$sites = $conn->selectRows("select sites.* from sites where company_id=? order by name", $id);

02-24-2007, 05:18 AM
OMG... I love you and want to have your babies!!! Well, not really, but thanks so much!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum