validation check, between and wildcard

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FE
Forum Commoner
Posts: 35
Joined: Fri Jul 14, 2006 5:21 am

validation check, between and wildcard

Post by FE »

i need some code to check if a variables are betwen a certain date and then check another variable to check if it begines with an "A":

E.G
$var=12-mar-06
$var2=13-mar-06
$var3=14-mar-06

$varcode= A3321

if $var2 is between $var and $var3
and if $varcode = A* (* being a wildcard)

then
echo 'validation complete'

else die('error message')


cheers
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have you picked up any tutorials or books yet? A lot of what you are asking are things covered by tutorials and PHP books. Just a suggestion...

For date ranges, you need to identify what you upper and lower limits are (just like for any BETWEEN type comparison), then identify what your checking, the check it...

Code: Select all

<?php
$enddate = strtotime('January 5, 2007');
$startdate = strtotime('November 10, 2005');
$checkdate = time();

if ($checkdate < $enddate && $checkdate > $startdate)
{
    //We are between the date range limits
}
else
{
    //We are not
}
?>
As for the first letter checker, look at strpos().
FE
Forum Commoner
Posts: 35
Joined: Fri Jul 14, 2006 5:21 am

Post by FE »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[quote="Everah"]Have you picked up any tutorials or books yet? A lot of what you are asking are things covered by tutorials and PHP books. Just a suggestion...
 [/quote]

ha, yeah i know, i'm just really lazy...sorry about that, anyway this one i really have tried to find the answer to, in my little php book i got but cant:

Code: Select all

$bg = '#eeeeee'; // Set the background color.
while ($row = odbc_fetch_array($result, OBDC_ASSOC)) {
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
	echo '<form name="form1" method="post" action="">';
	echo '<tr bgcolor="' . $bg . '">
		<td align="left"><input type="checkbox" name="checkbox" value="checkbox"></td>
		<td align="left">' . $row['GRN_NUMBER'] . '</td>
		<td align="left">' . $row['ITEM_NUMBER'] . '</td>
		<td align="left">' . $row['ORDER_NUMBER'] . '</td>
		<td align="left">' . $row['STOCK_CODE'] . '</td>
		<td align="left">' . $row['DESCRIPTION'] . '</td>
		<td align="left">' . $row['DATE'] . '</td>
		<td align="left">' . $row['QTY_RECEIVED'] . '</td>
	</tr>';
	echo '</form>';
i need to name the "check box" as the GRN number for the name


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
FE
Forum Commoner
Posts: 35
Joined: Fri Jul 14, 2006 5:21 am

Post by FE »

sorry about that feyd

going to bump this to see if anyone can help me
cheers
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Change this...

Code: Select all

<input type="checkbox" name="checkbox" value="checkbox">
to this...

Code: Select all

<input type="checkbox" name="{$row['GRN_NUMBER']}" />
FE
Forum Commoner
Posts: 35
Joined: Fri Jul 14, 2006 5:21 am

Post by FE »

Code: Select all

$bg = '#eeeeee'; // Set the background color.
while ($row = odbc_fetch_array($result, OBDC_ASSOC)) {
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
	echo '<form name="form1" method="post" action="">';
	echo '<tr bgcolor="' . $bg . '">
		<td align="left"><input type="checkbox" name="$row['GRN_NUMBER']" /></td>
		<td align="left">' . $row['GRN_NUMBER'] . '</td>
		<td align="left">' . $row['ITEM_NUMBER'] . '</td>
		<td align="left">' . $row['ORDER_NUMBER'] . '</td>
		<td align="left">' . $row['STOCK_CODE'] . '</td>
		<td align="left">' . $row['DESCRIPTION'] . '</td>
		<td align="left">' . $row['DATE'] . '</td>
		<td align="left">' . $row['QTY_RECEIVED'] . '</td>
	</tr>';
	echo '</form>';
I've been messing around with this for ages and keep getting the error:

Code: Select all

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in d:\Inetpub\wwwroot\batch2.php on line 117
line 117 is

"<td align="left"><input type="checkbox" name="$row['GRN_NUMBER']" /></td>"

i can 't see where the ; would go, can anyone help?
cheers
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

I think you should read Everahs post again and do EXACTLY what he said.

The syntax highlighting kinda gives it away
FE
Forum Commoner
Posts: 35
Joined: Fri Jul 14, 2006 5:21 am

Post by FE »

Pimptastic wrote:I think you should read Everahs post again and do EXACTLY what he said.

The syntax highlighting kinda gives it away
sorry the code doesn't match to Everahs, as i said i have been trying to fix the code, at the start i copy and pasted the code into my code.

anyway with this code

Code: Select all

$bg = '#eeeeee'; // Set the background color.
while ($row = odbc_fetch_array($result, OBDC_ASSOC)) {
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
	echo '<form name="form1" method="post" action="">';
	echo '<tr bgcolor="' . $bg . '">
		<td align="left"><input type="checkbox" name="{$row['GRN_NUMBER']}" /></td>
		<td align="left">' . $row['GRN_NUMBER'] . '</td>
		<td align="left">' . $row['ITEM_NUMBER'] . '</td>
		<td align="left">' . $row['ORDER_NUMBER'] . '</td>
		<td align="left">' . $row['STOCK_CODE'] . '</td>
		<td align="left">' . $row['DESCRIPTION'] . '</td>
		<td align="left">' . $row['DATE'] . '</td>
		<td align="left">' . $row['QTY_RECEIVED'] . '</td>
	</tr>';
	echo '</form>';
i still get the error:

"Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in d:\Inetpub\wwwroot\batch2.php on line 117 "
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Well, you could try doing it the way you have with all your other $row variables. That's what i would do.

Code: Select all

echo '<tr bgcolor="' . $bg . '">
                <td align="left"><input type="checkbox" name="' . $row['GRN_NUMBER'] . '" /></td>
                <td align="left">' . $row['GRN_NUMBER'] . '</td>
                <td align="left">' . $row['ITEM_NUMBER'] . '</td>
                <td align="left">' . $row['ORDER_NUMBER'] . '</td>
                <td align="left">' . $row['STOCK_CODE'] . '</td>
                <td align="left">' . $row['DESCRIPTION'] . '</td>
                <td align="left">' . $row['DATE'] . '</td>
                <td align="left">' . $row['QTY_RECEIVED'] . '</td>
        </tr>';
FE
Forum Commoner
Posts: 35
Joined: Fri Jul 14, 2006 5:21 am

Post by FE »

yeah cheers it worked
thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You know, Pimps way is a lot better than mine. Glad you got it working.
Post Reply