martin5211 37 Posting Whiz in Training

To generate a PDF into PHP, there are two techniques: PDFLib or FPDF. PDFLib has some restrictions on licencing (commercial applications), I encourage to use FPDF because is free and Open Source, although PDFLib is rough and more complete (use your criterion). At http://fpdf.org there are a place to download the class and good tutorials. Use $_GET or $_POST variables to get the form data depending the form method.

To send the email, mail() function or PHPMailer are commons methods to perform these assignments. Please take care to encode the attachment and the headers, set multipart content type first, then the proper content type and encoding in each part, we could send plain or html text and multiple attachments too.

In this example I've used FPDF and mail() techniques. I don't know if it is better move this code to snippets section.

<?php
// download fpdf class (http://fpdf.org)
require("fpdf153/fpdf.php");

// fpdf object
$pdf=new FPDF();

// generate a simple PDF (for more info, see http://fpdf.org/en/tutorial/)
$pdf->AddPage();
$pdf->SetFont("Arial","B",14);
$pdf->Cell(40,10, "this is a pdf example");

// email stuff
$to = "target@domain.com"; 
$from = "me@domain.com"; 
$subject = "send email with pdf attachment"; 
$message = "Please see the attachment.";

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "example.pdf";

// encode data (put attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = …
nav33n commented: good post! +8
Roebuc commented: FPDF is perfect, thanks! +1
martin5211 37 Posting Whiz in Training

To show the origin country, a general way is to lookup into a MySQL database with updated IP country ranges, GeoLite Free is a choice. Some commercial databases provide location even into cities. After this, you can use the country code to get their corresponding flag.

To get WHOIS information there are several PHP classes that perform this function.

User agent and Referral URL is easy obtainable through $_SERVER environment variable. Deviating server load to client processing using Javascript to perform this tasks -like in your code- is always better.

martin5211 37 Posting Whiz in Training

There is some little mistakes, like missing type on id_client field, a UNIX timestamp normally takes ten positions and lunch_time have one space inside (table names can't have any space). I recommend make the first field (id) as primary key usually.
The resultant SQL would be:

CREATE TABLE food_journal(
id INT( 11 ) NOT NULL AUTO_INCREMENT ,
id_client INT( 11 ) NOT NULL ,
TIMESTAMP INT( 11 ) NOT NULL ,
water VARCHAR( 8 ) NOT NULL ,
breakfast VARCHAR( 8 ) NOT NULL ,
breakfast_calories INT( 8 ) NOT NULL ,
breakfast_time VARCHAR( 8 ) NOT NULL ,
snack_1 VARCHAR( 8 ) NOT NULL ,
snack_1_calories VARCHAR( 8 ) NOT NULL ,
snack_1_time VARCHAR( 8 ) NOT NULL ,
lunch VARCHAR( 8 ) NOT NULL ,
lunch_calories VARCHAR( 8 ) NOT NULL ,
lunch_time VARCHAR( 8 ) NOT NULL ,
snack_2 VARCHAR( 8 ) NOT NULL ,
snack_2_calories VARCHAR( 8 ) NOT NULL ,
snack_2_time VARCHAR( 8 ) NOT NULL ,
dinner VARCHAR( 8 ) NOT NULL ,
dinner_calories VARCHAR( 8 ) NOT NULL ,
dinner_time VARCHAR( 8 ) NOT NULL ,
snack_3 VARCHAR( 8 ) NOT NULL ,
snack_3_calories VARCHAR( 8 ) NOT NULL ,
snack_3_time VARCHAR( 8 ) NOT NULL ,
PRIMARY KEY ( id )
)
martin5211 37 Posting Whiz in Training

UNIQUE and KEY id_2 isn't necessary, let alone primary key (id), indexes are meant to use a basic field for lookups, you could use more fields like fname and lname to perform special full-text lookups using MATCH().

And yes, you could avoid spaces or make carriage returns between commas to make the code more readable.

martin5211 37 Posting Whiz in Training

For clients I recommend to start with id, fname (first name), lname, username, email

For journal, id, id_client, title, body, date

You could use text type for any field except id (I suggest int, 11 chars length for this)

martin5211 37 Posting Whiz in Training

I recommend every-time as possible the guideline use mentioned by digital-ether. I will try to make a more deep review.

Create one table for clients, first field called id_(table name), type Int, as primary key and with auto-increment extra feature. Then, when you add a record, a new auto-incremented unique id number will be generated for each client. That's the normal usage for tables.

You can translate the client id to another tables to maintain the relationships between tables (e.g. for posts table, I suggest to create the first field id_post, the second as id_client and then the additional ones - title, body, etc.).

When you add a new client the question is how to insert the resultant client id in another table? Well, you could do a lookup by client name to get the client id before, using a input field or a dropdown list with client names and id values, or use

SELECT id FROM clients ORDER BY id_client DESC LIMIT 1

same as mentioned by digital-ether again, in this case to get the latest inserted id from clients. When you make a insertion in another table do not forget to insert the client id.

You could make a lookup by logon name, e.g.

SELECT id FROM clients WHERE username = $logon_name

To make a single query through several tables with a same field in common (e.g. client id) you could perform a query like this:

SELECT *
FROM clients
INNER JOIN posts ON …
martin5211 37 Posting Whiz in Training

Use WHERE clause to filter occurrences in Mysql results and $_GET or $_POST variables to get url parameters (according to form method). For example, add including the quotes:

WHERE id = '". $_GET['id'] . "'
martin5211 37 Posting Whiz in Training

Another solution is changing z-index on divs, with z-index you could locate an image over another and build a custom header layout too. Higher values put the image on the top.
This is the trick:

getElementById(--id--).style.zIndex += 1

I've enclosed the source code again with new modifications

martin5211 37 Posting Whiz in Training

Suggestions (maybe one will be enough)

- <div> with more width
- getElementById(id).height with lower value in the condition
- <div> with auto margins or without width property in CSS.

martin5211 37 Posting Whiz in Training

You can pass the image id as parameter in functions:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="date" content="2003-12-02T09:54:03+08:00" />
<meta http-equiv="imagetoolbar" content="no" />

<title>Dynamically enlarge image on mouseover and mouseout</title>

<style type="text/css">
body {margin:64px;}
#apDiv1 {
position:absolute;
left:361px;
top:161px;
width:186px;
height:144px;
z-index:1;
}
#apDiv2 {
position:absolute;
left:306px;
top:127px;
width:300px;
height:164px;
z-index:1;
}
#apDiv3 {
position:absolute;
left:188px;
top:116px;
width:100px;
height:75px;
z-index:1;
}
#apDiv4 {
position:absolute;
left:387px;
top:113px;
width:100px;
height:75px;
z-index:2;
}
</style>


<script type="text/javascript">
// <![CDATA[
var glbInc, glbDec;

function decreaseSizeImage(image) // will get back to its normal default size
{
var id = image;
if(glbInc != null) {clearTimeout(glbInc); glbInc = null;};
if (document.getElementById(id).height > 100)
{
document.getElementById(id).height -= 30;
document.getElementById(id).width -= 40;
glbDec = setTimeout("decreaseSizeImage('"+id+"')", 32);
};
}

function increaseSizeImage(image)
{
var id = image;
if(glbDec != null) {clearTimeout(glbDec); glbDec = null;};
if (document.getElementById(id).height < 216)
{
document.getElementById(id).height += 30;
document.getElementById(id).width += 40;
glbInc = setTimeout("increaseSizeImage('"+id+"')", 32);
};
}
// ]]>
</script>

</head>

<body>
<div id="apDiv3"><a href="#" onmouseover="increaseSizeImage('image2');"
onmouseout="decreaseSizeImage('image2');"><img id="image2"
src="avatar196367_1.gif" width="100" height="75" alt="color" id="image2" /></a></div>
<p>&nbsp;</p>
<div id="apDiv4"><a href="#" onmouseover="increaseSizeImage('image1');"
onmouseout="decreaseSizeImage('image1');"><img id="image1"
src="avatar196367_1.gif"
width="100" height="75" alt="Krusty is helpless" /></a></div>
<p>&nbsp;</p>

<p id="validation">&nbsp;</p>

</body></html>
martin5211 37 Posting Whiz in Training

And another method, I've created a mini function:

function big_num() {
	
	for ($i = 1; $i <= rand(60,80); $i++) {
		$a .= rand(1, 32768);
	}
	
	return $a;
}

echo big_num();
martin5211 37 Posting Whiz in Training

I don't know if it possible, because there are a limit in rand() and the processor, but if you really want only large numbers you could concatenate them with dots and min and max parameters, like:

$big_num = rand(32765, 32768). rand(32763, 32765). rand(10000, 32768). rand(32763, 32767). rand(15000, 32768). rand(18000, 32768);

echo $big_num;
martin5211 37 Posting Whiz in Training

^ you can't kill your soul :)

martin5211 37 Posting Whiz in Training

$form = "<td class=hr>";
$form .= htmlspecialchars(Town)."&nbsp;</td>";
$form .= "<td class=dr><input type=text name=Town maxlength=30 value=\"". str_replace('"', "&quot;", trim($row)) ."\"></td>";

echo $form;

Always use escaping \ when you use quotations inside another quotations, you could separate and concatenate items to deal then more clearly.

martin5211 37 Posting Whiz in Training

appart from sessions, you could use hash or random ids to reassert an identity coming from one computer