You are here: Re: Help: Can you make this .php less than 1 month?? « PHP Programming Language « IT news, forums, messages
Re: Help: Can you make this .php less than 1 month??

Posted by Colin Fine on 12/09/05 12:45

Novice Computer User wrote:
> Ok.. Thanks for the info.. I didn't even know I was looking at the
> wrong page.. I THINK this is correct page that I need to modify to
> reduce the 1 month option to 24 hours. I copied/pasted the .php file
> here -- if you can figure out a way to modify the 1 month limit to 24
> hours -- or even 1 hour (whichever is easiest is fine with me), PLEASE
> let me know.. thanks greatly:
>
> <?
> require_once("../conn.php");
> require_once("../includes.php");
> require_once("access.php");
>
> include_once("LeftStyles.php");
>
> ?>
>
> <script>
> function CheckNewPrice() {
>
> if(document.f1.PackageName.value=="")
> {
> window.alert('Enter the new package name, please!');
> document.f1.PackageName.focus();
> return false;
> }
>
> if(document.f1.NewPrice.value=="")
> {
> window.alert('Enter the new price value, please!');
> document.f1.NewPrice.focus();
> return false;
> }
>
> if(document.f1.nDuration.value=="")
> {
> window.alert('Select a duration period, please!');
> document.f1.nDuration.focus();
> return false;
> }
>
> if(document.f1.pLevel.value=="")
> {
> window.alert('Select a priority level, please!');
> document.f1.pLevel.focus();
> return false;
> }
>
> }
>
> function CheckDelete() {
>
> if(confirm('Are you sure you want to delete this price?'))
> {
> return true;
> }
> else
> {
> return false;
> }
>
> }
>
> </script>
>
> <form method=post name=f1 onsubmit="return CheckNewPrice()">
>
> <table align=center>
> <tr>
> <td colspan=2 align=center class=TableHead>Enter a new price</td>
> </tr>
>
> <tr>
> <td>Package name:</td>
> <td><input type=text name=PackageName maxlength=50></td>
> </tr>
>
>
> <tr>
> <td>Price:</td>
> <td><input type=text name=NewPrice size=6 maxlength=6></td>
> </tr>
>
> <tr>
> <td>Duration:</td>
> <td>
> <select name=nDuration>
> <option value=""></option>
> <?
> for($i = '1'; $i <= '12'; $i++)
> {
> echo "<option value=\"$i\">$i</option>\n";
> }
> ?>
> </select> months
> </td>
> </tr>
>
> <tr>
> <td>Priority Level:</td>
> <td>
> <select name="pLevel">
> <option value=""></option>
> <?
> //create the Priority level select menu
> $q1 = "select * from legal_priority order by PriorityLevel asc ";
> $r1 = mysql_query($q1) or die(mysql_error());
> while($a1 = mysql_fetch_array($r1))
> {
> echo "<option value=\"$a1[PriorityLevel]\">$a1[PriorityLevel] -
> $a1[PriorityName]</option>\n\t";
> }
> ?>
> </select>
> </td>
> </tr>
>
> <tr>
> <td>&nbsp;</td>
> <td><input type=submit name=s1 value=Save class=sub></td>
> </tr>
>
> </table>
>
> </form>
>
> <?
>
> if(isset($_POST[s1]))
> {
> $q1 = "insert into legal_prices set
> PackageName = '$_POST[PackageName]',
> PriceValue = '$_POST[NewPrice]',
> Duration = '$_POST[nDuration]',
> PriorityLevel = '$_POST[pLevel]' ";
>
> mysql_query($q1) or die(mysql_error());
> }
>
> //show prices
> $q1 = "select * from legal_prices, legal_priority where
> legal_prices.PriorityLevel = legal_priority.PriorityLevel order by
> legal_prices.PriorityLevel desc";
> $r1 = mysql_query($q1) or die(mysql_error());
>
> if(mysql_num_rows($r1) == '0')
> {
> exit();
> }
>
> ?>
>
> <table align=center width=650 cellspacing=0 bordercolor=black
> frame=below>
> <tr>
> <td class=TableHead width=200>Package Name</td>
> <td class=TableHead>Priority Level</td>
> <td class=TableHead align=center>Duration</td>
> <td class=TableHead align=right>Price</td>
> <td class=TableHead align=center>Action</td>
>
> <?
> while($a1 = mysql_fetch_array($r1))
> {
> if($a1[Duration] > '1')
> {
> $MyDuration = $a1[Duration]." months";
> }
> else
> {
> $MyDuration = $a1[Duration]." month";
> }
>
> echo
> "<tr>\n\t<td>$a1[PackageName]</td>\n\t<td>$a1[PriorityName]</td>\n\t<td
> align=center>$MyDuration</td>\n\t<td align=right>$aset[currency_sign]
> $a1[PriceValue]</td>\n\t<td align=center><a class=GreenLink
> href=\"PriceEdit.php?PriceID=$a1[PriceID]\">edit</a> | <a class=RedLink
> href=\"PriceDelete.php?PriceID=$a1[PriceID]\" onclick=\"return
> CheckDelete();\">delete</a></td>\n</tr>\n\n ";
> }
>
> echo "</table>\n\n<br><br>";
> ?>
>
You say you have spent HOURS on this question. I don't wish to seem
unkind, but what did you spend hours doing?

Reading an introduction to HTML might help, as would trying to
understand what the code does.

ALL that the code above does with Duration is:

<select name=nDuration>
> <option value=""></option>
> <?
> for($i = '1'; $i <= '12'; $i++)
> {
> echo "<option value=\"$i\">$i</option>\n";
> }
> ?>
> </select> months

which creates a drop-down menu offering the numbers 1-12. (The only PHP
here is the loop generating the entries).

On going to the edit page (I think, I haven't checked the details), it
saves the data in the database:

> $q1 = "insert into legal_prices set
> PackageName = '$_POST[PackageName]',
> PriceValue = '$_POST[NewPrice]',
> Duration = '$_POST[nDuration]',
> PriorityLevel = '$_POST[pLevel]' ";

Then it displays it for the user to decide what to do. First it does:
> if($a1[Duration] > '1')
> {
> $MyDuration = $a1[Duration]." months";
> }
> else
> {
> $MyDuration = $a1[Duration]." month";
> }

which gets the duration out the database and sets the variable
$MyDuration to "1 month" or "6 months" etc.
Then it displays it to the user offering 'edit' and 'delete'.

As regards the code above, this is all that happens to it, and you can
quite happily change the word 'month' to 'day' and the value '12' to
'24' and it will suddenly offer you 1-24 days instead of 1-12 months.
(You'll presumably need to make a corresponding change to the original
HTML file you posted, but I'll leave the details as an exercise).


However, you haven't shown us what it does with that duration value - I
guess that's in some other script somewhere that gets it out of the
database - and since it's about a duration that expires, I would guess
that it's not a web script at all, but another script or program that is
run every month. (This might be manual but is more likely to be
automatic. If you are on a unix-like system it's probably run by 'cron',
on Windows there's something called ? Windows scheduler ? )
Presumably that script does some date calculation, and you'll have to
tell it that duration has suddenly become days rather than months. Oh,
and you'll have to arrange to run it every day.

Colin

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация