Jump to content

How Do I Get The Date Order To be correct?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
byronwells

byronwells

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts
Alright guys

Please take a look at this page

Untitled Document

The products are being display in the wrong order.. I would like the products to be displayed in date order.. With the newest date showing first and so on


<?php

include_once ("header.php");

$cat = $_GET["cat"];

$link = $_GET["category"];

$search = $_GET["search"];

$cat_title = str_replace("_"," ",$link);


if($cat != "t")

	{

	$GetFile = file("http://www.digitalresellersvault.com/template/template.php");

	$Content = join("", $GetFile);

	$categories=$common->categories($db);

	$content=str_replace("{categories}",$categories,$content);	

	$Pat = "/<{Begin}>(.*?)<{End}>/s";

	preg_match($Pat,$Content,$Output);

	$SelectedContent = $Output[1];

	$q = "select * from ".$prefix."products where show_product = '1' ORDER BY Rand() LIMIT 1";

	$r = $db->get_a_line($q);

	$id = $r[id];

	$imageurl = $r[imageurl];

	$prod_description = $r[prod_description];

	$salesprice = $r[price];

	$product_name = $r[product_name];

	$licence = $r[licence];

	$product_date = $r[product_date];

	$salespage_link='<a href="prods.php?pid='.$id.'"><img border="0" src="http://www.digitalresellersvault.com/template/images/moreinfobutton.jpg" width="104" height="16"></a>';

	

			

	$prod_image ='<img src="images/'.$imageurl.'" border="0">';

	

	$Content = preg_replace($Pat,$ToReplace,$Content);

	$Content = preg_replace("/{{(.*?)}}/e", "$$1", $Content);

	echo $Content;

	include_once ("footer.php");		

	exit();		

	}



elseif($cat == "t")

	{

	$search = $_GET["search"];

	$link = $_GET["category"];

	$cat_title = str_replace("_"," ",$link);

	$GetFile = file("http://www.digitalresellersvault.com/template/template.php");

	$Content = join("", $GetFile);

	$categories=$common->categories($db);

	$content=str_replace("{categories}",$categories,$content);	

	$theselect=$common->category_select($db, 'select');

 $Content = str_replace("{{category_select}}", $theselect, $Content);


$Pat = "/<{Begin}>(.*?)<{End}>/s";

	preg_match($Pat,$Content,$Output);

	$SelectedContent = $Output[1];


	if($search_txt != "")

		{

		$cond	= "where product_name like '%".$search_txt."%' && show_product = '1'";		

		}

	else

		{

		$cond	= "where category = '$cat_title' && show_product = '1'";

		}


	########## pagination ###########

	$q = "select count(*) as cnt from ".$prefix."products $cond";

	$r = $db->get_a_line($q);

	$count = $r[cnt];

	if($count == "0")

		{

		$warning = "No Results Found";

		}

	$records=10;

	$links="marketplace.php?cat=t&category=$link&search_txt=$search_txt&";


	if($page=="")

		{

		$page=1;

		}

	$start=($page-1)*$records;

	$Content=$common->print_page_break3($db,$Content,$count,$records,$links,$page);

	########## pagination ###########


	$ChangeColor = 1;

	$ToReplace = "";

	$GetProduct = $db->get_rsltset("select * from ".$prefix."products $cond order by product_date DESC limit $start, $records");

	for($i = 0; $i < count($GetProduct); $i++)

		{

		$bgcolor = "#FFFFFF";

		@extract($GetProduct[$i]);

		if($period3_interval == "D"){$interval = "Day(s)";}

		if($period3_interval == "W"){$interval = "Week(s)";}

		if($period3_interval == "M"){$interval = "Month(s)";}

		if($period3_interval == "Y"){$interval = "Year(s)";}


		if($subscription_active == "1")

			{

			$salesprice = $amount3." every ".$period3_value." ".$interval;

			}

		else

			{

			$salesprice = $price;

			}	

		$prod_image ='<img src="images/'.$imageurl.'" border="0"width="140" height="140">';

		$salespage_link='<a href="prods.php?pid='.$id.'"><img border="0" src="http://www.digitalresellersvault.com/template/images/moreinfobutton.jpg" width="104" height="16"></a>';

		$ToReplace .= preg_replace($Ptn,"$$1",$SelectedContent);

		}

	}	

		

$Content = preg_replace($Pat,$ToReplace,$Content);

$Content = preg_replace("/{{(.*?)}}/e", "$$1", $Content);

echo $Content;

include_once ("footer.php");

?>



#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You need to order by a date field, not rand().
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
byronwells

byronwells

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts

WingedPanther said:

You need to order by a date field, not rand().

I have just changed
$q = "select * from ".$prefix."products where show_product = '1' ORDER BY Rand() LIMIT 1";


To

$q = "select * from ".$prefix."products where show_product = '1' ORDER BY product_date() LIMIT 1";

Product_date is the date field on the db..

But nothing has happened...

#4
byronwells

byronwells

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts

WingedPanther said:

You need to order by a date field, not rand().

I have another question for you in regards to the date :) At the moment I am getting the date inputted and outputted in this format 12/02/2010 mm-dd-yyyy

I am using a datepicker calender to input the date into my db. Without changing the javascript code is there anyway that I could do the following..

The date is stored into the db field in the above format..

Then I write some php code that converts the mm part into text, ie dec/02/2010 and then get it to output on the layout?

Or do I need to attack the javascript code?

#5
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Hypothetically it would be:
$q = "select * from ".$prefix."products where show_product = '1' ORDER BY product_date LIMIT 1";

But what type is product_date? varchar?

#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts

byronwells said:

Then I write some php code that converts the mm part into text, ie dec/02/2010 and then get it to output on the layout?

Just read the php manual for the date() command,

convert your database date-string(?) to a date value with strtodate()
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#7
Guest_Jaan_*

Guest_Jaan_*
  • Guests
I suggest using unix's timestamp. it's like.. greatest thing for date or MySQL time (as table type)