I hope you will take some time from your busy day to answer my question. Thank you in advance.
I am new to php programming, so hope my question doesn't bore you.
I am helping to develop an online directory. The database is set up with some of the data entries as "prime". These are the people who have also placed an ad or paid to have their entry listed among the first results. In the table, there is a column called "remarks". If the listing is prime, their level of prime-ness is recorded there. For the sake of the query, we only need to know if there is anything written for them or not in the remarks column. The goal is to show all the results of the search query, but to sort them first by non null (prime) results ascending, then show the null (prime) results ascending. To complicate this (at least for me) I need to label and change the style of the results (like background color or something). The first with label (heading) will be Prime and second will be Basic.
So here is my code and a link to see it displayed. I am also attaching the document here.
<?php
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 25;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Figure out the total number of results in DB:
//$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM stbl_company where category_id='$_GET[category_id]' order by company asc"),0);
$qryCounts = "SELECT COUNT(*) as Num FROM stbl_company where category_id='$_GET[category_id]' order by remarks desc, company asc";
$rsCounts = mysql_query("$qryCounts");
$total_results = mysql_result($rsCounts,0);
//$total_results = $noComps;
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Perform MySQL query on only the current page number's results
//$sql = mysql_query("SELECT * FROM pages LIMIT $from, $max_results");
$sql = mysql_query("select * from stbl_company where category_id='$category_id' order by remarks desc, company asc limit $from, $max_results");
echo ("<table width=100% border=0 cellpadding=2 cellspacing=0 class=bg_yellow><tr><td class=text>Page <b>$page</b> of <b>$total_pages</b>; Total Results <b>$total_results</b><br /><br /></td></tr>");
while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
echo ("<tr>
<td class=text><span class=text2>$row[company]</span><br />$row[address], $row[city], $row[state], $row[postal]<br /> <img src="" /> (");
echo substr($row['workph'],0,3);
echo (') ');
echo substr($row['workph'],3,3);
echo ('-');
echo substr($row['workph'],6,7);
echo ("</td>
</tr>
<tr><td><hr /></td></tr>");
}
//...this went on to do previous, next etc. so i only pasted the parts that pertain to the problem
http://www.aabdinc.com/new/companies.php?category_id=11&txtFind=&radioSearch=&txtCity=&lstState=&page=2
Thank you so much.// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 25;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Figure out the total number of results in DB:
//$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM stbl_company where category_id='$_GET[category_id]' order by company asc"),0);
$qryCounts = "SELECT COUNT(*) as Num FROM stbl_company where category_id='$_GET[category_id]' order by remarks desc, company asc";
$rsCounts = mysql_query("$qryCounts");
$total_results = mysql_result($rsCounts,0);
//$total_results = $noComps;
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Perform MySQL query on only the current page number's results
//$sql = mysql_query("SELECT * FROM pages LIMIT $from, $max_results");
$sql = mysql_query("select * from stbl_company where category_id='$category_id' order by remarks desc, company asc limit $from, $max_results");
echo ("<table width=100% border=0 cellpadding=2 cellspacing=0 class=bg_yellow><tr><td class=text>Page <b>$page</b> of <b>$total_pages</b>; Total Results <b>$total_results</b><br /><br /></td></tr>");
while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
echo ("<tr>
<td class=text><span class=text2>$row[company]</span><br />$row[address], $row[city], $row[state], $row[postal]<br /> <img src="" /> (");
echo substr($row['workph'],0,3);
echo (') ');
echo substr($row['workph'],3,3);
echo ('-');
echo substr($row['workph'],6,7);
echo ("</td>
</tr>
<tr><td><hr /></td></tr>");
}
//...this went on to do previous, next etc. so i only pasted the parts that pertain to the problem
http://www.aabdinc.com/new/companies.php?category_id=11&txtFind=&radioSearch=&txtCity=&lstState=&page=2
--
Tasneem
coming soon....... tasneemqadeer.com
Attachment:
companies.php
Description: application/php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php