Jump to content

mysql output help


chuck2009

Recommended Posts

hi im trying to load a sql quote it works find but it load all the old ad's first, how can i load all the new once first and then the old once here the code. im not all that good with mysql or php could anyone help me please

 

i did not write the code i both a classified script from http://www.scriptsfeed.com/

 

 

 

here the search code that show the quote fromt eh sql when a cat is select and a subcat is select

 

 

 

<?
require_once("conn.php");
require_once("includes.php");
require_once("templates/HeaderTemplate.php");
require_once("advanced.php");
require_once("templates/AdvancedSearchTemplate.php");
//Check for subcategories
if($_GET[c])
{
$catq="select * from yellow_subcat where rootcatid='$_GET[c]' order by subcatname asc";
$cats=mysql_query($catq);
if(mysql_num_rows($cats)!=0)
{ ?>
<table align=center width=100% bgcolor="#BBBBBB"  border=0 bordercolor=#020202  rules=rows cellspacing=1 class="subcats">
  <tr align="center">

    <td width=425 valign=top colspan=3 align="left" ><font face=verdana size=2><b>Select
      a Subcategory</b></font> </td>
   </tr>
   <tr style="border-width:1; border-color:#000000" onMouseOver="this.style.background='#B1B1B1'; this.style.cursor='hand'" onMouseOut="this.style.background='#F0F0F0'" align="center">
<?
//Check for rows and columns
$counted=1;
while($catsl = mysql_fetch_array($cats))
{
?>
    <td width=425 valign=top align="left"> <a href="search.php?s=<?=$catsl[subcatid]?>" class="style1">
      <?=$catsl[subcatname]?>
      </a></td>
<?if($counted%3==0){?></tr> <tr style="border-width:1; border-color:blue" onMouseOver="this.style.background='#B1B1B1'; this.style.cursor='hand'" onMouseOut="this.style.background='#F0F0F0'" align="center"><?}?>
<?
    $counted=$counted+1;
}
   ?>
</tr>
</table>
   <?}
   else
   {
   echo "No Subcategories were found!";
   }
}

else
{
$query = array();

if(!empty($_GET[c]))
{
   $query[] = "yellow_posts.CategoryID = '$_GET[c]' ";
}

if(!empty($_GET[CategoryID]))
{
   $query[] = "yellow_posts.CategoryID = '$_GET[CategoryID]' ";
}
if(!empty($_GET[s]))
{
   $query[] = "yellow_posts.SubCategoryID = '$_GET[s]' ";
}
if(!empty($_GET[old]))
{
$MyExp2 = time()-(24*60*60*$_GET[old]);
   $query[] = "yellow_posts.PostDate > '$MyExp2' ";
}
if(!empty($_GET[search_country]))
{
   $query[] = "yellow_agents.country = '$_GET[search_country]' ";
}

if(!empty($_GET[search_state]))
{
   $query[] = "yellow_agents.state = '$_GET[search_state]' ";
}

if(!empty($_GET[search_city]))
{
   $query[] = "yellow_agents.city = '$_GET[search_city]' ";
}

if(!empty($_GET[search_kw]))
{
   $query[] = " (yellow_posts.resume like '%$_GET[search_kw]%' or  yellow_posts.CompanyName like '%$_GET[search_kw]%') ";
}
if(!empty($_GET[zip]))
{
   $query[] = " (yellow_agents.zipcode like '%$_GET[zip]%') ";
}

if(!empty($query))
{
   $MyQuery = implode(" and ", $query);
   $MyQuery = " and ".$MyQuery;
}


////////////////////////////////////////////////////////////
//////////     order by
////////////////////////////////////////////////////////////

$order = array();

if(!empty($_GET[orderby]))
{
   $MyOrder = explode("|", $_GET[orderby]);

   while(list(,$ov) = each($MyOrder))
   {
      if($ov == "DateAdded")
      {
         $order[] = " yellow_agents.RegDate desc ";
      }

      if($ov == "address")
      {
         $order[] = " yellow_agents.address asc ";
      }

   }
}
else
{
   if(!empty($_GET[p]))
   {
      $order[] = " yellow_agents.RegDate asc ";
   }

}


if(count($order) > '0')
{
   $MyOrder = implode(", ", $order);

}
if($aset[sitefee]=="0")
      {
if(empty($MyOrder))
{
   $MyOrder = " order by yellow_agents.AgentID desc, yellow_agents.RegDate desc";
}
else
{
   $MyOrder = " order by yellow_agents.AgentID desc, $MyOrder, yellow_agents.RegDate desc";
}
      }

if(!empty($_GET[start]))
{
   $Start = $_GET[start];
}
else
{
   $Start = '1';
}

$ByPage = '25';
if($aset[sitefee]=="1")
      {
$q1 = "select * from yellow_agents, yellow_categories,yellow_subcat,yellow_posts  where yellow_posts.CategoryID = yellow_categories.CategoryID  and yellow_agents.AccountStatus = 'active' and yellow_posts.AgentID=yellow_agents.AgentID and yellow_posts.SubCategoryID = yellow_subcat.subcatid $MyQuery $MyOrder limit $Start, $ByPage ";

$qnav = "select * from yellow_agents, yellow_posts, yellow_categories where yellow_posts.CategoryID = yellow_categories.CategoryID and yellow_agents.AccountStatus = 'active' and yellow_posts.AgentID=yellow_agents.AgentID $MyQuery";

      }
      else
      {
/*$q1 = "select * from yellow_agents, yellow_priority, yellow_categories,yellow_subcat where yellow_agents.CategoryID = yellow_categories.CategoryID and yellow_agents.PriorityLevel = yellow_priority.PriorityLevel and yellow_agents.AccountStatus = 'active' and yellow_agents.SubCategoryID = yellow_subcat.subcatid $MyQuery $MyOrder limit $Start, $ByPage ";

$qnav = "select * from yellow_agents, yellow_priority, yellow_categories where yellow_agents.CategoryID = yellow_categories.CategoryID and yellow_agents.PriorityLevel = yellow_priority.PriorityLevel and yellow_agents.AccountStatus = 'active' $MyQuery";*/
$q1 = "select * from yellow_agents, yellow_categories,yellow_subcat,yellow_posts  where yellow_posts.CategoryID = yellow_categories.CategoryID  and yellow_agents.AccountStatus = 'active' and yellow_posts.SubCategoryID = yellow_subcat.subcatid and yellow_posts.AgentID=yellow_agents.AgentID $MyQuery $MyOrder limit $Start, $ByPage ";


$qnav = "select * from yellow_agents,  yellow_categories,yellow_posts where yellow_posts.CategoryID = yellow_categories.CategoryID and yellow_agents.AccountStatus = 'active' and yellow_posts.AgentID=yellow_agents.AgentID $MyQuery";

      }
$r1 = mysql_query($q1) or die(mysql_error());
$lrows = mysql_num_rows($r1);









if($lrows > '0')
{
   $ListingTable .= "<table bgcolor=#CFCFCF  align=center width=100% border=0 bordercolor=#000000 rules=rows cellspacing=1 class=\"subcats\">\n";
   $ListingTable .= "<tr  width=90><th>Photo</th><th>Title & Description</th><th>City/Town </th><th>Price</th></tr>";


   while($a1 = mysql_fetch_array($r1))
   {
     $rate="SELECT avg(rated) as abcde FROM yellow_rating WHERE mediaid ='".$a1[PostID]."' GROUP BY mediaid";
      $rank="";
      $rateq=mysql_query($rate)or die($rate);
      $rateline=mysql_fetch_array($rateq);
      $count=1;
      while($count<=round($rateline[abcde]))
      {
//      echo 1;
      $rank.= "<img src=\"images/star_yellow.png\">";
       $count=$count+1;
      }
     $ListingTable .= "<tr bgcolor=#F0F0F0 onMouseOver=\"this.style.background='#B1B1B1'; this.style.cursor='hand'\" onMouseOut=\"this.style.background='#F0F0F0'\" onClick=\"window.open('info.php?id=$a1[PostID]&s=$SCID', '_top')\">\n\t";
/*      $ListingTable .= "<td height=60>";

      $ListingTable .= "<table align=center width=\"100%\" border=1>\n";


      $ListingTable .= "<tr>";  */

  /*  if(!empty($a1[logo2]))
      {
         $MyImage = $a1[logo];

         $ListingTable .= "<img src=\"yellow_images/$MyImage\" width=75 height=60 border=1>";
      }
      else
      {
         $ListingTable .= "<img src=\"no_logo.jpg\" border=1>";
      }*/

      //$ListingTable .= "</td>\n\t";

      if($MyImage = $a1[logo]){
       $image_ad = "<img src=\"yellow_images/$MyImage\" width=\"75\" height=\"60\">";
      } else {
      $image_ad = "<img src=\"images/noImageAvailable.jpg\" border=\"1\" width=\"75\" height=\"60\">";

      }

    $ShortDesc3 =  substr( nl2br ($a1[resume]), 0, 150);
    $titlede2 =  substr( nl2br ($a1[CompanyName]), 0, 50);


      $ListingTable .= "<td valign=middle align=\"center\">$image_ad</td><td height=50 style=\"width:320px;\"  align=\"left\" valign=top nowrap><b>".$titlede2."</b><br><font face=\"Arial\" style=\"font-size:10px\">".$ShortDesc3."<br><p align=\"right\">Posted on: ".$a1[PostDate]."</p></font></td>\n<td align=\"center\" valign=middle>".$a1[city]."</td><td align=\"center\" width=100 valign=middle> ".$a1[price]." </td></tr>\n";

      $ShortDesc = substr($a1[DetailedDesc], 0, 200);

      $ListingTable .= "</tr>\n\n<tr>";

   }
/*         $q1 = "select distinct state from yellow_agents order by state";
$r1 = mysql_query($q1) or die(mysql_error());*/


      $rnav = mysql_query($qnav) or die(mysql_error());
      $rows = mysql_num_rows($rnav);

         if($rows > $ByPage)
         {
            $ListingTable .=  "<br><table align=center width=580>";
            $ListingTable .= "<td align=center><font face=verdana size=2> | ";

            $pages = ceil($rows/$ByPage);

            for($i = 0; $i <= ($pages); $i++)
            {
               $PageStart = $ByPage*$i;

               $i2 = $i + 1;

               if($PageStart == $Start)
               {
                  $links[] = " <span class=RedLink>$i2</span>\n\t ";
               }
               elseif($PageStart < $rows)
               {
                  $links[] = " <a class=BlackLink href=\"search.php?Start=$PageStart&c=$_GET[c]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&search_kw=$_GET[search_kw]\">$i2</a>\n\t ";
               }
            }

            $links2 = implode(" | ", $links);

            $ListingTable .= $links2;

            $ListingTable .= "| </td>";

            $ListingTable .= "</table><br>\n";

         }

}

else
{
   $ListingTable = "<br><br><center>No results were found!</center>";
}
}
   include("templates/SearchTemplate.php");
   include("templates/FooterTemplate.php");

?>

Link to comment
Share on other sites

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.