Tizag.com Webmaster Tutorials - A collection of webmaster tutorials from HTML to PHP.

Monday, March 23, 2009

Update Table from another table MySQL

< ? php
$DBConnect = mysqli_connect('localhost', 'root', '', 'phpbb');
mysqli_select_db($DBConnect, "phpbb");
$sql = "SELECT topic_title, topic_views, topic_id, forum_id FROM phpbb_topics";

$sql_execute=mysqli_query($DBConnect, $sql)or die(mysqli_error());
while ($row = mysqli_fetch_row($sql_execute)) {
echo "Topic Id: ".$row[2]." - Topic Title:".$row[0]."
";
$oldText="Ask the Analyst";
$newText="Analyst Corner";
$formattedData = str_replace($oldText, $newText, $row[0]);
echo $formattedData;

$updateQuery = "UPDATE phpbb_topics SET topic_title='".$formattedData."' WHERE topic_id='".$row[2]."'";
mysqli_query($DBConnect, $updateQuery) or die(mysqli_error());
}
? >

Wednesday, March 18, 2009

MySQL DATE FORMAT Function for date display


DATE_FORMAT(date,format)



The following script uses
the DATE_FORMAT() function to display different formats. We will use the NOW() function to get the current date/time:





DATE_FORMAT(NOW(),'%b %d %Y %h:%i %p')
DATE_FORMAT(NOW(),'%m-%d-%Y')
DATE_FORMAT(NOW(),'%d %b %y')
DATE_FORMAT(NOW(),'%d %b %Y %T:%f')


The result would look something like this:







Nov 04 2008 11:45 PM

11-04-2008

04 Nov 08

04 Nov 2008 11:45:34:243

Where date is a valid date and format specifies the output format for the date/time.


The formats that can be used are:











































FormatDescription
%aAbbreviated weekday name
%bAbbreviated month name
%cMonth, numeric
%DDay of month with English suffix
%dDay of month, numeric (00-31)
%eDay of month, numeric (0-31)
%fMicroseconds
%HHour (00-23)
%hHour (01-12)
%IHour (01-12)
%iMinutes, numeric (00-59)
%jDay of year (001-366)
%kHour (0-23)
%lHour (1-12)
%MMonth name
%mMonth, numeric (00-12)
%pAM or PM
%rTime, 12-hour (hh:mm:ss AM or PM)
%SSeconds (00-59)
%sSeconds (00-59)
%TTime, 24-hour (hh:mm:ss)
%UWeek (00-53) where Sunday is the first day of week
%uWeek (00-53) where Monday is the first day of week
%VWeek (01-53) where Sunday is the first day of week, used with %X
%vWeek (01-53) where Monday is the first day of week, used with %x
%WWeekday name
%wDay of the week (0=Sunday, 6=Saturday)
%XYear of the week where Sunday is the first day of week, four digits, used with %V
%xYear of the week where Monday is the first day of week, four digits, used with %v
%YYear, four digits
%yYear, two digits

Tuesday, March 17, 2009

Show Hide DIV Webpage

<script language="JavaScript">

function hidediv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('mysubmenuarea').style.visibility = 'hidden';
document.getElementById('mysubmenuarea').style.display = "none";
}
else {
if (document.layers) { // Netscape 4
document.mysubmenuarea.visibility = 'hidden';
document.getElementById('mysubmenuarea').style.display = "none";
}
else { // IE 4
document.all.mysubmenuarea.style.visibility = 'hidden';
document.getElementById('mysubmenuarea').style.display = "none";
}
}
}

function showdiv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('mysubmenuarea').style.visibility = 'visible';
document.getElementById('mysubmenuarea').style.display = 'block';
}else {
if (document.layers) { // Netscape 4
document.mysubmenuarea.visibility = 'visible';
}else { // IE 4
document.all.mysubmenuarea.style.visibility = 'visible';
}
}
}
</script>


----| CALL IN EVENT |---------
onmouseover="javascript: return showdiv();" onmouseout="javascript: return showdiv();"

Thursday, March 12, 2009

Yesterday, Today, One week for MySQL - PHP

$today=date("Y-m-d");

$m= date("m"); // Month value
$de= date("d"); //today's date
$y= date("Y"); // Year value

$sevenDaysBefore = date('Y-m-d', mktime(0,0,0,$m,($de-7),$y));
$thirtyDaysBefore = date('Y-m-d', mktime(0,0,0,$m,($de-30),$y));