Jump to content

Recommended Posts

hi all,

 

im after some ideas on how to order a directory of companies, at the moment they are ordered by alphabetical company name A-Z with pagnation of 10 to a page.

 

thing is that doing that, only the companies beginging with A are going to get first page exposure when users are searching the directory

 

can anyone think of a fairer way to do this so all compaines get some exposure?

 

i cant use RAND as im using pagnation on clicking page 2 you would get a completely new random set of companies

 

Thanks for any help i know this is a tough one

Link to comment
https://forums.phpfreaks.com/topic/154318-solved-ordering-a-directory-ideas/
Share on other sites

my code below, if i order by RAND everytime i click page 2 or 3 then another random set or results are gonna be displayed instead of the first queries results

 

<?php session_start();
include($_SERVER['DOCUMENT_ROOT'] . '/includes/directory_header.php');

$Trade = urldecode($_GET["Trade"]);

$max = 10; 
$p = @$_GET['p'];
if(empty($p)){
$p = 1;
}
$limits = ($p - 1) * $max; 

$SQL = mysql_query("SELECT * FROM tblDirectory2 WHERE Sect1_2 LIKE '%$Trade%' ORDER BY Sect1_4 ASC LIMIT ".$limits.",$max") or die (mysql_error());

$totalres = mysql_result(mysql_query("SELECT COUNT(CompanyID) AS tot FROM tblDirectory2 WHERE Sect1_2 LIKE '%$Trade%' "),0);	
$totalpages = ceil($totalres / $max); 
?>
<div id="navigation">
<div style="float:left;"><?php echo $Trade; ?></div>
<div style="float:right;">
<strong>Page:</strong>
<?php
for($i = 1; $i <= $totalpages; $i++){ 
echo "<a href='".$_SERVER['PHP_SELF']."?Trade=".urlencode($Trade)."&p=$i'>$i</a>\n";
}    
?>
</div>
<div style="float:right; width:375px; text-align:left;">
<a class="boldlink" href="/new_directory/contents.php">Directory Contents</a> | <a class="boldlink" href="/default.php">Main Website</a>
</div>
</div>
<?php
if (mysql_num_rows($SQL) <1) {
echo "<p>Sorry there are currently no members under the category $Trade, <a href=\"/new_directory/contents.php\">click here</a> to go back to the contents</p>\n";
}
else { 
while ($row = mysql_fetch_array($SQL)) {
?>
<div class="trade">
<h3><a href="record.php?title=<?php echo urlencode($TTitle)."&T=".$T."&ID=".$row["CompanyID"]; ?>"><?php echo $row["Sect1_4"]?></a></h3>
<div class="trade-left">
<table width="100%" border="0">
      <tr>
        <td style="width:29%" class="top-right"><strong>  </strong></td>
        <td style="width:71%"><?php 
	echo $row["Sect1_7a"]."<br />\n";
	echo $row["Sect1_7b"]."<br />\n";
	echo $row["Sect1_7c"]."<br />\n";
	echo $row["Sect1_7d"]."\n";

	?></td>
      </tr>
          <tr>
        <td class="right">Tel:<strong>  </strong></td>
        <td><strong><?php echo $row["Sect1_5"]?></strong></td>
      </tr>
      <tr>
        <td class="right">CHAS:  </td>
        <td><?php echo YN($row["Sect1_10"])?></td>
      </tr>
    </table>
</div>
<div class="trade-right">
    <table width="100%" border="0">
      <tr>
        <td class="right">Pl Insurance Cover:  </td>
        <td>£<?php echo $row["Sect2_1"]?></td>
        <td class="right">El insurance Cover: </td>
        <td>£<?php echo $row["Sect2_2"]?></td>
      </tr>
      <tr>
        <td class="right">Risk insurance Cover:  </td>
        <td><?php echo $row["Sect2_3"]?></td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td class="right">Planning Supervisor Indemnity: </td>
        <td>£<?php echo $row["Sect2_5"]?></td>
        <td class="right">Design Work Indemnity: </td>
        <td>£<?php echo $row["Sect2_4"]?></td>
      </tr>
      <tr>
        <td class="right">Turnover for Previous Year: </td>
        <td><?php echo $row["Sect3_3"]?></td>
        <td class="right">CIS Type:  </td>
        <td><?php echo $row["Sect3_5"]?></td>
      </tr>
      <tr>
        <td colspan="4" class="right" style="padding:3px 0;"><a href="record.php?Trade=<?php echo urlencode($Trade)."&ID=".$row["CompanyID"]; ?>" style="color:#CC0033;">Full Company Details</a></td>
        </tr>
    </table>
</div>
</div>
<?php } 
}
?>

<div class="clear"></div>
<div id="lower-navigation">
<strong>Page:</strong>
<?php
for($i = 1; $i <= $totalpages; $i++){ 
echo "<a href='".$_SERVER['PHP_SELF']."?Trade=".urlencode($Trade)."&p=$i'>$i</a>\n";
}    
?>
</div>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?>

You could display a random page as the first page displayed to the user but again that's not ideal.

 

TBH, if it were me I think I would just start with the A's as you are doing at the moment. It's what the user would expect, they will expect the results to be in order (probably alpha) and that the first page will be displayed first.

U mean like adding user Ratings, Comments, Popularity (hits)?

 

I guess it depends on how u want to cycle/rotate the directory.

if there arent that many, u can just retreive the id's shuffle em, and then use the query.

storing the shuffles id's in a cookie/session (so its different for every user).

to save space, u can use the pack function.

 

Edit: U can also just have 2-3 companies at the top, a featured or similar concept.

no i dont need to add anything else to them its just as it is

 

its just when browsing, the A's always come first and i guess not all companies are getting full exposure

 

so would you suggest leaving it as is, becuase thats what they expect

or doing as laffin said?

 

i could swap pagnation for alphabetical?

 

eg. A B C D

instead of Page 1 2 3 4

 

what you think?

I think a combination of the two would work.

 

Its hard trying to find L's when ya got numbers.

and its a pain to have to go throu a page of 200 entries

 

so if ya have both, Letters on top, pagination below, it shud be a nice directory navigation system

 

if i used both though wouldnt it confuse a user?

 

or do you mean like pages for the letter A which i would obviously need

 

so it could be A B C D E...

 

then after clicking a letter EG A

 

Pg 1 2 3 4 of As

 

that would be more effcient yes?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.