HTML/Javascript

SES by business degree online promotion team.

Philippine Airlines International Flight schedules

Philippine Airlines International Flight schedules
Philippine Airlines International Flight schedules

Search This Blog

Wednesday, October 27, 2010

Max Function & sql display the highest number field data from mysql database

Display the highest number data from MySql Database

<?php
//protected area orig3 file
$query = "SELECT MAX(ttravelid) FROM travelid";
$resultx = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($resultx))
{
//echo "The most highest reservation id is ".$row['MAX(reservationid)'];
$ttravelid1 = $row['MAX(ttravelid)'];
//echo $ttraveliddd;
}
//this is the max number
echo $ttravelid1;

?>

or you can use sql, this will display the highest id number of the personal data.

<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM person order by id DESC limit 1");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>

Thursday, October 7, 2010

PHP FOR NEWS LETTER

code to paste:

newsentry.php


<table align="center" border="0">
<form method="post" action="addnews.php">
<tr>
<td align="right"><font face="tahoma" size="2"><b>News Title</b></font></td>
<td align="left"><input type="text" name="newstitle"></td>
</tr>
<tr>
<td align="right"><font face="tahoma" size="2"><b>Message</b></font></td>
<td align="left">
<textarea rows="10" cols="30" wrap="physical" name="message">
Enter Comments Here
</textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="submit">
<input type="reset" value="reset">
</td>
</td>
</form>
</table>


sample output:




Then insert/save data to mysql database. See below.

addnews.php

<html>
<body>
<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("newsletter", $con);

$newstitle=$_REQUEST['newstitle'];
$message=$_REQUEST['message'];

$sql="INSERT INTO news (newstitle, message)
VALUES
('$newstitle','$message')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";


mysql_close($con)
?>


Then dipslay newsletter.

latestnews.php


<?php
$con = mysql_connect("localhost","root","youpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("newsletter", $con);

$result = mysql_query("SELECT * FROM news order by newsid DESC");

echo "<table border='0' width='500' align='center'>
<tr>
<td align='center'><font color='#2E57A5' size='5'><b>Latest News</b></font></td>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b><font face='tahoma' size='2'>" . $row['newstitle'] . "</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='justify'><font face='tahoma' size='2'>" . $row['message'] . "</font></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>

note: this is only DUMMY sample , try to add date for the newsletter.

output:

PHP readmore using strip-tags

code to paste:

<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$result = mysql_query("SELECT * FROM jos_content where catid='5' order by ID DESC limit 2");
echo "<table border='0' width='215' align='center' cellpadding='0' cellspacing='0'>";
while($row = mysql_fetch_array($result))
{
$dateformatted_a = $row['created'];
//$dateformatted_1 = date("Y-m-d",strtotime($dateformatted_a));
$string= strip_tags($row['introtext']);
$readmorea = substr($string, 0, 50);
echo "<tr>";
echo "<td align='center' valign='top' width='0' align='left'><br><img src='images/stories/". $row['metadesc'] ."' width='70' height='54'></td>";
echo "<td width='214' valign='top' align='left'>";
echo "<table border='0' align='center' width='100%' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td><br><b>" .$dateformatted_1. "</b><br>" .$readmorea. "...</td>";
echo "</tr>";
echo "<tr>";
echo '<td align="right"><br><b><a href="id='.$row['id'].'">&raquo; View Articles</a></td>';
echo "</tr>";
echo "<tr>";
echo "<td align='right'>&nbsp;</td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>

Wednesday, October 6, 2010

PHP Delete Record Entry script

Sample delete record php script

<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("hotelreservation", $con);


$hotelid=$_POST['hotelid'];
$accountpassword=$_POST['accountpassword'];

$resultx = mysql_query("SELECT * FROM location where locationpassword='$accountpassword'");
$count=mysql_num_rows($resultx);
if($count==1)
{
mysql_query("delete from room where hotelid='$hotelid'");
echo "record deleted";
}
else
{
echo"<br><br><br><br><br><br>";
echo "<p align='center'><b>Your id is invalid.</b></p>";
}

mysql_close($con)
?>

or you can use this one to delete record

delete.php

<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("hotelreservation", $con);

// Get value first from form.
$id=$_GET['id'];

// create for delete statement
mysql_query("delete from name where id='$id'");

// Close the datebase connection
mysql_close();

// Redirect to recordelet_info.php
header("location:recordelete_info.php");


mysql_close($con)
?>

recordelete_info.php
<?php
echo "record deleted";
?>


or
delete.php this one to delete record

<?php
Note: This will delete all the records that have number id=3
mysql_query("delete from personelinfo where idno like '3'");
echo"<br><br><br><br><br><br>";
echo "<p align='center'><b>Record deleted.</b></p>";
?>

Round off a number

<?php
$number = "28";
$number = number_format($number, 2);
echo $number; // equals "28.00"

$average = $totalrank_totaling / 3;
$average_rounded =round($average, 2);

echo $number;
echo "<br>";
echo $average_rounded;
?>

Formatting Date

code to format date:

for example, after search date from mysql database, then you can format date.
Here is the sample code.

$created = $row['created'];
$created_crea = date("Y-m-d",strtotime($created));