PHP Snippets

<?php include("filename.html"); ?>


Session variables:

if ($Debug) print " # Before change QueryModelsFilter(Session) =".$_SESSION['QueryModelsFilter']." # ";   
   
//if (isset($QueryModelsType) || $QueryModelsType <> "")
//    $_SESSION['QueryModelsFilter']= "ManType";
//else
//    if (isset($QueryModelsMan) || $QueryModelsMan <> "")
//        $_SESSION['QueryModelsFilter']= "Man";
//    else
//        $_SESSION['QueryModelsFilter']= "All";

if ($QueryModelsAll || !isset($_SESSION['QueryModelsFilter']))
    $_SESSION['QueryModelsFilter']= "All";
else
    if ($QueryModelsMan)
        $_SESSION['QueryModelsFilter']= "Man";
    else
        if ($QueryModelsManType)
            $_SESSION['QueryModelsFilter']= "ManType";
 

 

 


Checkbox on data items

 

<input type='checkbox' name='YourFieldName[]' value=\"$DataBaseValue\"
/>

Then in the script that recieves the form POST or GET data, cycle
through the array of checkbox values and do with them as you will.

foreach($YourFieldName as $val)
{
//echo checkbox values to the page or do whatver you will with
them..
echo "checkbox value: $val";


Action confirm box using Javascript: (thanks http://bytes.com/topic/javascript/answers/674138-how-pop-up-confirm-delete-box-when-user-click-delete)


<?php
if (isset($_GET['action']) && isset($_GET['record']) )
{
    $RecordId = htmlspecialchars($_GET['record']);
    $Action = htmlspecialchars($_GET['action']);
    if($Action=='deleteRecord'){
    echo 'You are ready to delete ID: '.$RecordId;
    #
    # CODE for delete records
    #
    }
 
}
?>
<html>
<head>
<script language="javascript" type="text/javascript">
function deleteRecord(RecordId)
{
    if (confirm('Delete this Record?')) {
        window.location.href = 'index.php?action=deleteRecord&record=' + RecordId;
    }
}
</script>
</head>
 
<body>
<br>
Item 1 <a href="javascript:deleteRecord('1001');">DELETE
 
Item 3<a href="javascript:deleteRecord('1003');">DELETE
 
Item 15 <a href="javascript:deleteRecord('1015');">DELETE
 
</body>
</html>
 
a

 


 

Jump to a bookmark on page load:

<body>

<script type="text/javascript">

function goToAnchor() {
location.href = "myPage.html#myAnchor";
}

</script>