Greetings to everyone,
i am new to this forum and new also to PHP programming.
Well,I try to improve.
So,i have a small program,and I want to display a picture :
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sistima", $con);
$result = mysql_query("SELECT * FROM gia_sxediasi");
$gia_sxediasi = mysql_fetch_array($result);
$a = $gia_sxediasi['dwmatia'];
$b = $gia_sxediasi['kouzines'];
$c = $gia_sxediasi['mpanio'];
$d = $gia_sxediasi['saloni'];
$button_text = $a;
$button_text2= $b;
$button_text3= $c;
$button_text4= $d;
if (empty($button_text))
{
echo 'Could not create image - form not filled out correctly';
exit;
}
// create an image of the right background and check size
$im = ImageCreateFromPNG ('house.png');
$width_image = ImageSX($im);
$height_image = ImageSY($im);
// Our images need an 18 pixel margin in from the edge of the image
$width_image_wo_margins = $width_image - (2 * 40);
$height_image_wo_margins = $height_image - (2 * 40);
// Work out if the font size will fit and make it smaller until it does
// Start out with the biggest size that will reasonably fit on our buttons
$font_size = 25;
// you need to tell GD2 where your fonts reside
$fontname = 'C:\WINDOWS\Fonts\arial.ttf';
do
{
$font_size--;
$font_size2--;
// find out the size of the text at that font size
$bbox=ImageTTFBBox ($font_size, 0, $fontname, $button_text);
$right_text = $bbox[2]; // right co-ordinate
$left_text = $bbox[0]; // left co-ordinate
$width_text = $right_text - $left_text; // how wide is it?
$height_text = abs($bbox[7] - $bbox[1]); // how tall is it?
$bbox2=ImageTTFBBox ($font_size, 0, $fontname, $button_text2);
$right_text2 = $bbox2[4]; // right co-ordinate
$left_text2 = $bbox2[2]; // left co-ordinate
$width_text2 = $right_text2 - $left_text2; // how wide is it?
$height_text2 = abs($bbox2[9] - $bbox2[2]); // how tall is it?
$bbox3=ImageTTFBBox ($font_size, 0, $fontname, $button_text3);
$right_text3 = $bbox3[4]; // right co-ordinate
$left_text3 = $bbox3[2]; // left co-ordinate
$width_text3 = $right_text3 - $left_text3; // how wide is it?
$height_text3 = abs($bbox3[9] - $bbox3[2]); // how tall is it?
$bbox4=ImageTTFBBox ($font_size, 0, $fontname, $button_text4);
$right_text4 = $bbox4[4]; // right co-ordinate
$left_text4 = $bbox4[2]; // left co-ordinate
$width_text4 = $right_text4 - $left_text4; // how wide is it?
$height_text4 = abs($bbox4[9] - $bbox4[2]); // how tall is it?
}
while ( $font_size>8 &&
( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
);
if ( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
{
// no readable font size will fit on button
echo 'Text given will not fit on button.<br />';
}
else
{
// We have found a font size that will fit
// Now work out where to put it
$text_x = $width_image/1.25 - $width_text/2.0;
$text_x2= $width_image/6.4 - $width_text2/3.0;
$text_x3= $width_image/2.2 - $width_text3/2.0;
$text_x4= $width_image/2.0 - $width_text4/5.0;
$text_y = $height_image/2.15 - $height_text/2.0 ;
$text_y2 = $height_image/3.1 - $height_text2/3.0 ;
$text_y3 = $height_image/2.3 - $height_text3/4.0 ;
$text_y4 = $height_image/1.3 - $height_text2/5.0 ;
if (($left_text < 0) && ($left_text2 < 0) && ($left_text3 < 0) && ($left_text4 < 0))
$text_x += abs($left_text);
$text_x2 += abs($left_text2);
$text_x3 += abs($left_text3);
$text_x4 += abs($left_text4);
// add factor for left overhang
$above_line_text = abs($bbox[15]); // how far above the baseline?
$text_y += $above_line_text;
$above_line_text = abs ($bbox2[15]);
$text_y2 += $above_line_text2;
$above_line_text = abs ($bbox3[15]);
$text_y3 += $above_line_text3;
$above_line_text = abs ($bbox4[15]);
$text_y4 += $above_line_text4; // add baseline factor
$text_y -= 2;
$text_y -= 4; // adjustment factor for shape of our template
$white = ImageColorAllocate ($im, 255, 255, 255);
ImageTTFText ($im, $font_size, 0, $text_x, $text_y, $white, $fontname,
$button_text);
ImageTTFText ($im, $font_size, 0,$text_x2, $text_y2, $white, $fontname,
$button_text2);
ImageTTFText ($im, $font_size, 0,$text_x3, $text_y3, $white, $fontname,
$button_text3);
ImageTTFText ($im, $font_size, 0,$text_x4, $text_y4, $white, $fontname,
$button_text4);
ImagePNG ($im);
}
ImageDestroy ($im);
?>
but i want to make a button,to goo back at main page and also,to truncate the table/delete the values.
the code i wrote goes like this :
<input type="submit" name="submit" value="Πατήστε εδώ για επιστροφή" />
<?php
mysql_query("TRUNCATE $gia_sxediasi");
?>
</form>
so i need a proper way to display those 2 at the same page. Any ideas please?