Jump to content

CAN Some Really Truely Help Me Please?

- - - - -

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

#1
byronwells

byronwells

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts
Alright guys

I am hoping that there is a coder out there that can guide me, explain how to do this please.. PLEASE dont send me to look on a link, etc.. I need someone to explain what to do.. That way I will understand.... :) :)

I need some php code writen that allows me to change the way the date is displayed.. The date information is been taken from the product_date field, with the value date type.

At the moment the db defualt format is yyyy-mm-dd I would very much like it to display mm-dd-yyyy instead

And then the second thing is more complicated. I know that we can set the month to display in words.. But does it have to be the full words?? i.e can we set it up so it displays like this for the month, dec, jan, feb, mar, apr, may, jun, and so on??

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
All of this can be done. What part of the advice you've received so far was not clear? Can you get specific about how to use recommended functions, for example?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
byronwells

byronwells

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts

WingedPanther said:

All of this can be done. What part of the advice you've received so far was not clear? Can you get specific about how to use recommended functions, for example?

Wingpanther

I am hoping that you can really help me this time...

Because I am really getting confused with this one....

Right can we start from the top...

I need to tell my script that when the date is output on the marketplace pages it needs to be shown in the mm-dd-yyyy format..

At the moment the output for it is yyyyy-mm-dd

This is the bit of code that I am now using on the add_product.php page to get the date from the text to be entered in the correct format

$product_date = date("Y-m-d", strtotime($_POST["product_date"]));

Its now the rest that I am getting confused with...

I firstly need to understand this.. I know I have got to use a select command..

I guess I have to start it out like this
<php>
select date_format (or something like that) Or am I totally wrong?

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
I think I showed him to the php.net page for the date function, which is the one you do the collaboration with date formats in php.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
if you want it mm-dd-yyyy instead, then do
$product_date = date("m-d-Y", strtotime($_POST["product_date"]));

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#6
byronwells

byronwells

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts

Orjan said:

if you want it mm-dd-yyyy instead, then do

$product_date = date("m-d-Y", strtotime($_POST["product_date"]));


If I do that then no date is showed.. I think you are misunderstanding what I am asking for...

I am not asking for the way it is entered into the db field.. Because there is only way that you can enter it, and that is by the defualt setting off yyyy-mm-dd

I want the output of that display.. So basically when I am ready to display the date in my layout it will look like this mm-dd-yyyy

Bearing in mind because of my datepicker uses the mm-dd-yyyy format anyway... It was not getting stored in the db without it be changed to yyyy-mm-dd

Hopefully I have more sense now..

#7
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
strange, cause that is how you change date format in PHP. just print/echo the variable $product_date there and it shall be in your selected format...

you want a way to read out the yyyy-mm-dd formatted value from the database, and print it to the web page as mm-dd-yyyy. then you do that way I described.
or do you want it mm/dd/yyyy ? then you need to write "m/d/Y" instead.

wait, now I see, you read $_POST.. that is when you store it to the db. but you do it exactly the same on reading the field from the database, you need to alter another part of the code where you read your code and do it similar to this, but with the field from your sql inside your strtotime instead.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#8
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
Byron, Orjan is correct, but you need to format the date again when you get the information from the database.

So when you go to display the time on the post you need to use the date function again as Orjan described but replace the $_POST with what ever variable you used to get the information from the database.

#9
byronwells

byronwells

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts

Feral said:

Byron, Orjan is correct, but you need to format the date again when you get the information from the database.

So when you go to display the time on the post you need to use the date function again as Orjan described but replace the $_POST with what ever variable you used to get the information from the database.

Alright Feral

On the add_product.php I had to put two piece of coes in regards to the product_date, which are these ones

$product_date = date("Y-m-d", strtotime($_POST["product_date"]));

$set .= "product_date = '$product_date'";

If you need to see the full code then I can supply you with that :)

Then on the marketplace.php page I used this bit of code
$product_date = $r[product_date];

And then on the actual template that I am using for the layout of the marketplace I used this command

{{product_date}}

which allows me to display the date where I want to..

Which part do I need to modify??

#10
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
its the
$product_date = $r[product_date];

that needs to be modified of course, as that is where you read it from the database.
let it look like this:

$product_date = date("m-d-Y", strtotime($r["product_date']));
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#11
byronwells

byronwells

    Learning Programmer

  • Members
  • PipPipPip
  • 58 posts

Orjan said:

its the
$product_date = $r[product_date];

that needs to be modified of course, as that is where you read it from the database.
let it look like this:

$product_date = date("m-d-Y", strtotime($r["product_date']));

That bit of code is just quite right.. Dreamweaver doesnt like it..

Here is the full code


<?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 id 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");

?>



#12
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
what is it dreamweaver complains about then? because that code is correct.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall