hi,
well there are many ways of doing this. i have done it the following way:-
HTML
<div id="spc">
<select id="selectform" onChange="selfo();">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<form id="abc" style="display:none">
<input>
</form>
<form id="def" style="display:none">
<input><input>
</form>
<form id="ghi" style="display:none">
<input><input><input>
</form>
</div>
//javascript
<script>
function selfo()
{
var a = document.getElementById("selectform").value;
if(a == 1){
document.getElementById("abc").style.display = "block";
document.getElementById("def").style.display = "none";
document.getElementById("ghi").style.display = "none";
}
else if(a == 2){
document.getElementById("def").style.display = "block";
document.getElementById("abc").style.display = "none";
document.getElementById("ghi").style.display = "none";
}
else if(a == 3){
document.getElementById("ghi").style.display = "block";
document.getElementById("abc").style.display = "none";
document.getElementById("def").style.display = "none";
}
else if(a == 0){
document.getElementById("spc").style.display = "none";
}
}
</script>
Being a complete non programmer, i thought it would be a good idea to help others like me who have no programming knowledge but want to develop web based applications. Additionally i wanted to be able to access all these for my own repetitive use.
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Sunday, March 9, 2014
Tuesday, August 13, 2013
how to get no of days in the current month(count)?
$da = date('d'); // gets the current day of the month
$mth = date('m'); // gets the current month
$yr = date('Y'); // gets the current year
$daysinmonth = cal_days_in_month(CAL_GREGORIAN,$mth,$yr);
$mth = date('m'); // gets the current month
$yr = date('Y'); // gets the current year
$daysinmonth = cal_days_in_month(CAL_GREGORIAN,$mth,$yr);
echo $daysinmonth; // this will echo the total no of days in the current month
now you might also want to use the no of days left in the current month from the current day, here's how that's done:-
$baldays = $daysinmonth - $da;
echo $baldays; // this would echo out the no of days remaining for the current month to end
how to automatically get the first date of the current month in mysql
there are several ways of doing it. here is how i do it. it just feels simpler this way :)
$mth = date('m'); // gets the current month
$yr = date('Y'); // gets the current year
$mth = date('m'); // gets the current month
$yr = date('Y'); // gets the current year
For example, if i want to run a query to get results between the first day of the current month and today, i would write it like this:-
"SELECT * FROM table WHERE date BETWEEN '$yr-$mth-01' AND CURDATE( )"
Sunday, June 30, 2013
how to change all to UPPERCASE in an input box
for a text box, here's the code.
<input type="text" onblur="this.value=this.value.toUpperCase()" name="" placeholder="all of this will be uppercase" />
Wednesday, May 22, 2013
Update one Mysql table with results from another table on a different database
here's how you update one table with results from another database query.
UPDATE
target_database.target_table A //database to be updated-target
INNER JOIN source_database.source_table B //join source database to target
ON B.ProductID = A.ProductID //join fields
SET A.Markup = B.Markup //fields to be updated
UPDATE
target_database.target_table A //database to be updated-target
INNER JOIN source_database.source_table B //join source database to target
ON B.ProductID = A.ProductID //join fields
SET A.Markup = B.Markup //fields to be updated
Sunday, April 28, 2013
how to find duplicates in two columns of mysql database table
any one column can have duplicates. but both columns together are unique. this is how you find duplicates
select columnA,
columnB,
count(*)
from table_name
group by columnA,
columnB
having count(*) > 1
Monday, July 9, 2012
how to use the switch statement in php
switch statement can be extremely useful in complex situations.
switch($variable)
{
case "a":
// run the code if $variable = a .
break;
case "b":
// run the code if $variable = b .
break;
case "c":
// run the code if $variable = c .
break;
default:
// run the code if $variable is not equal to either a,b or c
}
switch($variable)
{
case "a":
// run the code if $variable = a .
break;
case "b":
// run the code if $variable = b .
break;
case "c":
// run the code if $variable = c .
break;
default:
// run the code if $variable is not equal to either a,b or c
}
Monday, December 19, 2011
pull mysql data as options into select field
<?php
$con = mysql_connect("localhost","username","password"); //connection details
$db = mysql_select_db("databasename",$con); // database details
$qry = mysql_query("SELECT somefield FROM sometable WHERE something = 'somevalue' ")or die(mysql_error()); //actual query
echo "<select name=' '>";
echo "<option></option>"; //if you want the first one to be blank
while ($row = mysql_fetch_array($qry))
{
$i = $row['somefield'];
echo "<option>$i</option>";
}
echo "</select>";
mysql_close($con);
?>
$con = mysql_connect("localhost","username","password"); //connection details
$db = mysql_select_db("databasename",$con); // database details
$qry = mysql_query("SELECT somefield FROM sometable WHERE something = 'somevalue' ")or die(mysql_error()); //actual query
echo "<select name=' '>";
echo "<option></option>"; //if you want the first one to be blank
while ($row = mysql_fetch_array($qry))
{
$i = $row['somefield'];
echo "<option>$i</option>";
}
echo "</select>";
mysql_close($con);
?>
Sunday, December 18, 2011
cron job
the following command will fire the script in cron tab
/usr/bin/php -q /home/username/public_html/file.php
file.php is the file that will be fired.
public_html is the folder where the file is saved.
username is your username
/usr/bin/php -q /home/username/public_html/file.php
file.php is the file that will be fired.
public_html is the folder where the file is saved.
username is your username
Friday, December 16, 2011
how to echo mysql retrieved value into a form as default value
// single field that has been retrieved from mysql database
$qry = mysql_query(" SELECT somefield FROM sometable WHERE something = 'some value' ")or die(mysql_error());
$result = mysql_fetch_row($qry);
<form action="" method="">
<input type="" name="" value=" <?php echo $result[0]; ?> ">
</form>
// in case of multiple values retrieved from mysql as a simple array
$qry = mysql_query(" SELECT somefield FROM sometable WHERE something = 'some value' ")or die(mysql_error());
$result = mysql_fetch_row($qry);
<form action="" method="">
<input type="" name="" value=" <?php echo $result[0]; ?> ">
</form>
// in case of multiple values retrieved from mysql as a simple array
$qry = mysql_query(" SELECT somefield FROM sometable WHERE something = 'some value' ")or die(mysql_error());
$result = mysql_fetch_array($qry);
<form action="" method="">
<input type="" name="" value=" <?php echo $result[0]; ?> "> //places the first value from mysql
<input type="" name="" value=" <?php echo $result[1]; ?> "> //places the second value
<input type="" name="" value=" <?php echo $result[2]; ?> "> //places the third value
<input type="" name="" value=" <?php echo $result[3]; ?> "> //places the fourth value and so on
</form>
how to use mysql_num_rows example
$qry = mysql_query(" SELECT * FROM abc WHERE something = 'something' ")or die(mysql_error());
$num = mysql_num_rows($qry);
if($num = 0)
{
// run code here
}
else
{
// run code here
}
$num = mysql_num_rows($qry);
if($num = 0)
{
// run code here
}
else
{
// run code here
}
Subscribe to:
Posts (Atom)