Jump to content

Skipjackrick

Members
  • Posts

    196
  • Joined

  • Last visited

    Never

Everything posted by Skipjackrick

  1. I found that book. Its 20 bucks :'( I lose 10 hairs on my head for everyday I eat Ramen. Everyday I don't eat I lose 30 hairs. I'll go bald if I buy the book!!! LOL
  2. Here is show_image.php <?php include_once('thumbnail.inc.php'); $thumb = new Thumbnail($_GET['filename']); $thumb->resize($_GET['width'],$_GET['height']); $thumb->show(); $thumb->destruct(); exit; ?> And here is thumbnail.inc.php <?php class Thumbnail { /** * Error message to display, if any * * @var string */ var $errmsg; /** * Whether or not there is an error * * @var boolean */ var $error; /** * Format of the image file * * @var string */ var $format; /** * File name and path of the image file * * @var string */ var $fileName; /** * Image meta data if any is available (jpeg/tiff) via the exif library * * @var array */ var $imageMeta; /** * Current dimensions of working image * * @var array */ var $currentDimensions; /** * New dimensions of working image * * @var array */ var $newDimensions; /** * Image resource for newly manipulated image * * @var resource * @access private */ var $newImage; /** * Image resource for image before previous manipulation * * @var resource * @access private */ var $oldImage; /** * Image resource for image being currently manipulated * * @var resource * @access private */ var $workingImage; /** * Percentage to resize image by * * @var int * @access private */ var $percent; /** * Maximum width of image during resize * * @var int * @access private */ var $maxWidth; /** * Maximum height of image during resize * * @var int * @access private */ var $maxHeight; /** * Class constructor * * @param string $fileName * @return Thumbnail */ function Thumbnail($fileName) { //make sure the GD library is installed if(!function_exists("gd_info")) { echo 'You do not have the GD Library installed. This class requires the GD library to function properly.' . "\n"; echo 'visit http://us2.php.net/manual/en/ref.image.php for more information'; exit; } //initialize variables $this->errmsg = ''; $this->error = false; $this->currentDimensions = array(); $this->newDimensions = array(); $this->fileName = $fileName; $this->imageMeta = array(); $this->percent = 100; $this->maxWidth = 0; $this->maxHeight = 0; //check to see if file exists if(!file_exists($this->fileName)) { $this->errmsg = 'File not found'; $this->error = true; } //check to see if file is readable elseif(!is_readable($this->fileName)) { $this->errmsg = 'File is not readable'; $this->error = true; } //if there are no errors, determine the file format if($this->error == false) { //check if gif if(stristr(strtolower($this->fileName),'.gif')) $this->format = 'GIF'; //check if jpg elseif(stristr(strtolower($this->fileName),'.jpg') || stristr(strtolower($this->fileName),'.jpeg')) $this->format = 'JPG'; //check if png elseif(stristr(strtolower($this->fileName),'.png')) $this->format = 'PNG'; //unknown file format else { $this->errmsg = 'Unknown file format'; $this->error = true; } } //initialize resources if no errors if($this->error == false) { switch($this->format) { case 'GIF': $this->oldImage = ImageCreateFromGif($this->fileName); break; case 'JPG': $this->oldImage = ImageCreateFromJpeg($this->fileName); break; case 'PNG': $this->oldImage = ImageCreateFromPng($this->fileName); break; } $size = GetImageSize($this->fileName); $this->currentDimensions = array('width'=>$size[0],'height'=>$size[1]); $this->newImage = $this->oldImage; $this->gatherImageMeta(); } if($this->error == true) { $this->showErrorImage(); break; } } /** * Must be called to free up allocated memory after all manipulations are done * */ function destruct() { if(is_resource($this->newImage)) @ImageDestroy($this->newImage); if(is_resource($this->oldImage)) @ImageDestroy($this->oldImage); if(is_resource($this->workingImage)) @ImageDestroy($this->workingImage); } /** * Returns the current width of the image * * @return int */ function getCurrentWidth() { return $this->currentDimensions['width']; } /** * Returns the current height of the image * * @return int */ function getCurrentHeight() { return $this->currentDimensions['height']; } /** * Calculates new image width * * @param int $width * @param int $height * @return array */ function calcWidth($width,$height) { $newWp = (100 * $this->maxWidth) / $width; $newHeight = ($height * $newWp) / 100; return array('newWidth'=>intval($this->maxWidth),'newHeight'=>intval($newHeight)); } /** * Calculates new image height * * @param int $width * @param int $height * @return array */ function calcHeight($width,$height) { $newHp = (100 * $this->maxHeight) / $height; $newWidth = ($width * $newHp) / 100; return array('newWidth'=>intval($newWidth),'newHeight'=>intval($this->maxHeight)); } /** * Calculates new image size based on percentage * * @param int $width * @param int $height * @return array */ function calcPercent($width,$height) { $newWidth = ($width * $this->percent) / 100; $newHeight = ($height * $this->percent) / 100; return array('newWidth'=>intval($newWidth),'newHeight'=>intval($newHeight)); } /** * Calculates new image size based on width and height, while constraining to maxWidth and maxHeight * * @param int $width * @param int $height */ function calcImageSize($width,$height) { $newSize = array('newWidth'=>$width,'newHeight'=>$height); if($this->maxWidth > 0) { $newSize = $this->calcWidth($width,$height); if($this->maxHeight > 0 && $newSize['newHeight'] > $this->maxHeight) { $newSize = $this->calcHeight($newSize['newWidth'],$newSize['newHeight']); } //$this->newDimensions = $newSize; } if($this->maxHeight > 0) { $newSize = $this->calcHeight($width,$height); if($this->maxWidth > 0 && $newSize['newWidth'] > $this->maxWidth) { $newSize = $this->calcWidth($newSize['newWidth'],$newSize['newHeight']); } //$this->newDimensions = $newSize; } $this->newDimensions = $newSize; } /** * Calculates new image size based percentage * * @param int $width * @param int $height */ function calcImageSizePercent($width,$height) { if($this->percent > 0) { $this->newDimensions = $this->calcPercent($width,$height); } } /** * Displays error image * */ function showErrorImage() { header('Content-type: image/png'); $errImg = ImageCreate(220,25); $bgColor = imagecolorallocate($errImg,0,0,0); $fgColor1 = imagecolorallocate($errImg,255,255,255); $fgColor2 = imagecolorallocate($errImg,255,0,0); imagestring($errImg,3,6,6,'Error:',$fgColor2); imagestring($errImg,3,55,6,$this->errmsg,$fgColor1); imagepng($errImg); imagedestroy($errImg); } /** * Resizes image to maxWidth x maxHeight * * @param int $maxWidth * @param int $maxHeight */ function resize($maxWidth = 0, $maxHeight = 0) { $this->maxWidth = $maxWidth; $this->maxHeight = $maxHeight; $this->calcImageSize($this->currentDimensions['width'],$this->currentDimensions['height']); if(function_exists("ImageCreateTrueColor")) { $this->workingImage = ImageCreateTrueColor($this->newDimensions['newWidth'],$this->newDimensions['newHeight']); } else { $this->workingImage = ImageCreate($this->newDimensions['newWidth'],$this->newDimensions['newHeight']); } ImageCopyResampled( $this->workingImage, $this->oldImage, 0, 0, 0, 0, $this->newDimensions['newWidth'], $this->newDimensions['newHeight'], $this->currentDimensions['width'], $this->currentDimensions['height'] ); $this->oldImage = $this->workingImage; $this->newImage = $this->workingImage; $this->currentDimensions['width'] = $this->newDimensions['newWidth']; $this->currentDimensions['height'] = $this->newDimensions['newHeight']; } /** * Resizes the image by $percent percent * * @param int $percent */ function resizePercent($percent = 0) { $this->percent = $percent; $this->calcImageSizePercent($this->currentDimensions['width'],$this->currentDimensions['height']); if(function_exists("ImageCreateTrueColor")) { $this->workingImage = ImageCreateTrueColor($this->newDimensions['newWidth'],$this->newDimensions['newHeight']); } else { $this->workingImage = ImageCreate($this->newDimensions['newWidth'],$this->newDimensions['newHeight']); } ImageCopyResampled( $this->workingImage, $this->oldImage, 0, 0, 0, 0, $this->newDimensions['newWidth'], $this->newDimensions['newHeight'], $this->currentDimensions['width'], $this->currentDimensions['height'] ); $this->oldImage = $this->workingImage; $this->newImage = $this->workingImage; $this->currentDimensions['width'] = $this->newDimensions['newWidth']; $this->currentDimensions['height'] = $this->newDimensions['newHeight']; } /** * Crops the image from calculated center in a square of $cropSize pixels * * @param int $cropSize */ function cropFromCenter($cropSize) { if($cropSize > $this->currentDimensions['width']) $cropSize = $this->currentDimensions['width']; if($cropSize > $this->currentDimensions['height']) $cropSize = $this->currentDimensions['height']; $cropX = intval(($this->currentDimensions['width'] - $cropSize) / 2); $cropY = intval(($this->currentDimensions['height'] - $cropSize) / 2); if(function_exists("ImageCreateTrueColor")) { $this->workingImage = ImageCreateTrueColor($cropSize,$cropSize); } else { $this->workingImage = ImageCreate($cropSize,$cropSize); } imagecopyresampled( $this->workingImage, $this->oldImage, 0, 0, $cropX, $cropY, $cropSize, $cropSize, $cropSize, $cropSize ); $this->oldImage = $this->workingImage; $this->newImage = $this->workingImage; $this->currentDimensions['width'] = $cropSize; $this->currentDimensions['height'] = $cropSize; } /** * Advanced cropping function that crops an image using $startX and $startY as the upper-left hand corner. * * @param int $startX * @param int $startY * @param int $width * @param int $height */ function crop($startX,$startY,$width,$height) { //make sure the cropped area is not greater than the size of the image if($width > $this->currentDimensions['width']) $width = $this->currentDimensions['width']; if($height > $this->currentDimensions['height']) $height = $this->currentDimensions['height']; //make sure not starting outside the image if(($startX + $width) > $this->currentDimensions['width']) $startX = ($this->currentDimensions['width'] - $width); if(($startY + $height) > $this->currentDimensions['height']) $startY = ($this->currentDimensions['height'] - $height); if($startX < 0) $startX = 0; if($startY < 0) $startY = 0; if(function_exists("ImageCreateTrueColor")) { $this->workingImage = ImageCreateTrueColor($width,$height); } else { $this->workingImage = ImageCreate($width,$height); } imagecopyresampled( $this->workingImage, $this->oldImage, 0, 0, $startX, $startY, $width, $height, $width, $height ); $this->oldImage = $this->workingImage; $this->newImage = $this->workingImage; $this->currentDimensions['width'] = $width; $this->currentDimensions['height'] = $height; } /** * Outputs the image to the screen, or saves to $name if supplied. Quality of JPEG images can be controlled with the $quality variable * * @param int $quality * @param string $name */ function show($quality=100,$name = '') { switch($this->format) { case 'GIF': if($name != '') { ImageGif($this->newImage,$name); } else { header('Content-type: image/gif'); ImageGif($this->newImage); } break; case 'JPG': if($name != '') { ImageJpeg($this->newImage,$name,$quality); } else { header('Content-type: image/jpeg'); ImageJpeg($this->newImage,'',$quality); } break; case 'PNG': if($name != '') { ImagePng($this->newImage,$name); } else { header('Content-type: image/png'); ImagePng($this->newImage); } break; } } /** * Saves image as $name (can include file path), with quality of # percent if file is a jpeg * * @param string $name * @param int $quality */ function save($name,$quality=100) { $this->show($quality,$name); } /** * Creates Apple-style reflection under image, optionally adding a border to main image * * @param int $percent * @param int $reflection * @param int $white * @param bool $border * @param string $borderColor */ function createReflection($percent,$reflection,$white,$border = true,$borderColor = '#a4a4a4') { $width = $this->currentDimensions['width']; $height = $this->currentDimensions['height']; $reflectionHeight = intval($height * ($reflection / 100)); $newHeight = $height + $reflectionHeight; $reflectedPart = $height * ($percent / 100); $this->workingImage = ImageCreateTrueColor($width,$newHeight); ImageAlphaBlending($this->workingImage,true); $colorToPaint = ImageColorAllocateAlpha($this->workingImage,255,255,255,0); ImageFilledRectangle($this->workingImage,0,0,$width,$newHeight,$colorToPaint); imagecopyresampled( $this->workingImage, $this->newImage, 0, 0, 0, $reflectedPart, $width, $reflectionHeight, $width, ($height - $reflectedPart)); $this->imageFlipVertical(); imagecopy($this->workingImage,$this->newImage,0,0,0,0,$width,$height); imagealphablending($this->workingImage,true); for($i=0;$i<$reflectionHeight;$i++) { $colorToPaint = imagecolorallocatealpha($this->workingImage,255,255,255,($i/$reflectionHeight*-1+1)*$white); imagefilledrectangle($this->workingImage,0,$height+$i,$width,$height+$i,$colorToPaint); } if($border == true) { $rgb = $this->hex2rgb($borderColor,false); $colorToPaint = imagecolorallocate($this->workingImage,$rgb[0],$rgb[1],$rgb[2]); imageline($this->workingImage,0,0,$width,0,$colorToPaint); //top line imageline($this->workingImage,0,$height,$width,$height,$colorToPaint); //bottom line imageline($this->workingImage,0,0,0,$height,$colorToPaint); //left line imageline($this->workingImage,$width-1,0,$width-1,$height,$colorToPaint); //right line } $this->oldImage = $this->workingImage; $this->newImage = $this->workingImage; $this->currentDimensions['width'] = $width; $this->currentDimensions['height'] = $newHeight; } /** * Inverts working image, used by reflection function * * @access private */ function imageFlipVertical() { $x_i = imagesx($this->workingImage); $y_i = imagesy($this->workingImage); for($x = 0; $x < $x_i; $x++) { for($y = 0; $y < $y_i; $y++) { imagecopy($this->workingImage,$this->workingImage,$x,$y_i - $y - 1, $x, $y, 1, 1); } } } /** * Converts hexidecimal color value to rgb values and returns as array/string * * @param string $hex * @param bool $asString * @return array|string */ function hex2rgb($hex, $asString = false) { // strip off any leading # if (0 === strpos($hex, '#')) { $hex = substr($hex, 1); } else if (0 === strpos($hex, '&H')) { $hex = substr($hex, 2); } // break into hex 3-tuple $cutpoint = ceil(strlen($hex) / 2)-1; $rgb = explode(':', wordwrap($hex, $cutpoint, ':', $cutpoint), 3); // convert each tuple to decimal $rgb[0] = (isset($rgb[0]) ? hexdec($rgb[0]) : 0); $rgb[1] = (isset($rgb[1]) ? hexdec($rgb[1]) : 0); $rgb[2] = (isset($rgb[2]) ? hexdec($rgb[2]) : 0); return ($asString ? "{$rgb[0]} {$rgb[1]} {$rgb[2]}" : $rgb); } /** * Reads selected exif meta data from jpg images and populates $this->imageMeta with appropriate values if found * */ function gatherImageMeta() { //only attempt to retrieve info if exif exists if(function_exists("exif_read_data") && $this->format == 'JPG') { $imageData = exif_read_data($this->fileName); if(isset($imageData['Make'])) $this->imageMeta['make'] = ucwords(strtolower($imageData['Make'])); if(isset($imageData['Model'])) $this->imageMeta['model'] = $imageData['Model']; if(isset($imageData['COMPUTED']['ApertureFNumber'])) { $this->imageMeta['aperture'] = $imageData['COMPUTED']['ApertureFNumber']; $this->imageMeta['aperture'] = str_replace('/','',$this->imageMeta['aperture']); } if(isset($imageData['ExposureTime'])) { $exposure = explode('/',$imageData['ExposureTime']); $exposure = round($exposure[1]/$exposure[0],-1); $this->imageMeta['exposure'] = '1/' . $exposure . ' second'; } if(isset($imageData['Flash'])) { if($imageData['Flash'] > 0) { $this->imageMeta['flash'] = 'Yes'; } else { $this->imageMeta['flash'] = 'No'; } } if(isset($imageData['FocalLength'])) { $focus = explode('/',$imageData['FocalLength']); $this->imageMeta['focalLength'] = round($focus[0]/$focus[1],2) . ' mm'; } if(isset($imageData['DateTime'])) { $date = $imageData['DateTime']; $date = explode(' ',$date); $date = str_replace(':','-',$date[0]) . ' ' . $date[1]; $this->imageMeta['dateTaken'] = date('m/d/Y g:i A',strtotime($date)); } } } /** * Rotates image either 90 degrees clockwise or counter-clockwise * * @param string $direction */ function rotateImage($direction = 'CW') { if($direction == 'CW') { $this->workingImage = imagerotate($this->workingImage,-90,0); } else { $this->workingImage = imagerotate($this->workingImage,90,0); } $newWidth = $this->currentDimensions['height']; $newHeight = $this->currentDimensions['width']; $this->oldImage = $this->workingImage; $this->newImage = $this->workingImage; $this->currentDimensions['width'] = $newWidth; $this->currentDimensions['height'] = $newHeight; } } ?>
  3. I can get if to work when I do this. But, take a look at what happens...LOL http://www.ectackle.com/uploader/uploaded_files/example2.php <?php if ($handle = opendir('/home/ectackle/public_html/uploader/uploaded_files/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo " <a href='$file' onclick='return hs.expand(this)' class='highslide'> <img src='show_image.php?filename=sample.jpg&width=150&height=150'/> </a> "; } } closedir($handle); } ?>
  4. Can anybody tell me why my thumbnails are NOT generating? What am I missing here? Here is an example link to the page where the thumbnails are not generating. http://www.ectackle.com/uploader/uploaded_files/example.php <?php if ($handle = opendir('/home/ectackle/public_html/uploader/uploaded_files/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo " <a href='$file' onclick='return hs.expand(this)' class='highslide'> <img src='show_image.php?filename=$file' alt=''&width=150&height=150/> </a> "; } } closedir($handle); } ?>
  5. I found this script doing a search for "glob image gallery". Seems simple enough. Thanks for your help Marcus. <? /* Photo Gallery in a really short amount of time written and tested with PHP 5.0.4/ Apache2, RHE3 WS Demonstrates some basic techniques that can be used to create a simple photo gallery possible enhancements: support dynamic generation of thumbnails through a graphics library like gd or imagemagick provided for learning purposes only, use at your own risk */ // configurations //directory where large version images are kept $image_directory = 'images/'; //directory where thumbs are kept $thumb_directory = 'images/'; //prefix for large images, if any $image_prefix = ''; //prefix for thumbnail images // can leave empty or '' if in different folder with same names as larger versions etc $thumb_prefix = 't_'; //the number of thumbnails display per row $images_per_row = 5; //start of script //start by loading thumbnails $thumbs = glob($thumb_directory. "$thumb_prefix*"); // make sure we have found some thumbnails if((!is_array($thumbs)) || (!sizeof($thumbs))) die('There are no images'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Simple Photo Gallery</title> <style type="text/css"> body { background: #EEE; margin: 10px; } .outline { background: #FFF; border: solid 1px #DDD; } div { font-family: verdana, arial, sans-serif; font-size: 11px; color: #000; line-height: 17px; } </style> <script language="javascript" type="text/javascript"> function openimg(url,width,height,scroll) { if(!scroll) scroll = 0; if(!url) return false; var x = (screen.width) ? (screen.width - width)/2 : 0; var y = (screen.height) ? (screen.height - height)/2 : 0; var win = window.open(url, 'newino_'+ Math.round(100*Math.random()), 'width='+ width+ ',height='+ height+ ',left='+ x+ ',top='+ y+ ',toolbars=0,statusbar=0,scrollbars='+ scroll+ ',resizable=1'); return false; } </script> </head> <body> <table cellspacing="0" cellpadding="0" border="0" width="750" align="center" class="outline"> <tr><td align="left" valign="top"> <table cellspacing="0" cellpadding="5" border="0" width="750"> <tr> <? // the number of rows we have $rowcount = 1; //the total number of images displayed $imgcount = 1; // total number of images $numimages = sizeof($thumbs); // do the deed foreach($thumbs as $v) { // url/path for full size image $full_image = str_replace($thumb_prefix, $image_prefix, $v); // thumb properties using our extended getimagesizex $thumb_properties = getimagesizex($v); // image properties using our extended getimagesizex $image_properties = getimagesizex($full_image); // if we cant get the image properties skip it if((!$thumb_properties) || (!$image_properties)) continue; // file size etc description for image $desc = sprintf("%s (%sk)", basename($full_image), $image_properties['size']); print('<td align="center" valign="middle"><div>'); printf("<a href=\"%s\" onclick=\"openimg(this.href, %u, %u, 1); return false;\"><img src=\"%s\" %s border=\"0\"></a></div><div align=\"center\">%s</div></td>\n\t\t", $full_image, $image_properties['width'], $image_properties['height'], $v, $thumb_properties['attr'], $desc); // if we are displaying $image_per_row on this row, start a new row if(($imgcount % $images_per_row) == 0) { // but only if its not the last row if($imgcount % $numimages) { print("</tr><tr>\n\t\t"); } $rowcount++; } $imgcount++; } // make table columns even if the total number of images is not even compared to the number of image per row if($imgcount % sizeof($images)) { $offset = ($rowcount * $images_per_row) - $numimages; for($i = 0; $i < $offset; $i++) { print('<td align="center" valign="middle"> </td>'. "\n\t\t"); } } ?> </tr> </table> </td></tr> </table> </body> </html> <? // our extended getimagesizex function // adding additional information for images and putting an associative key for // the regular getimagesize integer keys function getimagesizex($image) { if(file_exists($image) && is_readable($image)) { $size = getimagesize($image); if(!is_array($size) || (!sizeof($size))) return(false); $result = array( 'width' => $size[0], 'height' => $size[1], 'type' => $size[2], 'attr' => $size[3], 'bits' => $size['bits'], 'channels' => $size['channels'], 'mime' => $size['mime'], 'size' => sprintf("%.2f", filesize($image) / 1024), ); return($result); } return(false); } ?>
  6. Hello fellas, I have the same request. Although, I am a noobie (4 weeks php experience) also. I can understand php for the most part. I have done alot of internet searches on this stuff and it seems everybody wants to sell their "Image Gallery Script"? So, I found a really nice interface for users to upload images to a web directory. http://www.webdeveloper.com/forum/showthread.php?t=101466 Now, if there is a way to dynamically display thumbnails of the images uploaded that you guys know of. That'd be great!! I have seen alot of really slick DNN "Live content" pages that do this. Example here. http://www.texassharkrodeo.com/2008Teams/Rockstars/tabid/188/Default.aspx I think google is going to have to add another search engine just from the traffic I've been giving it trying to search for this stuff!!?!?! Anybody have any leads or links to some script? I am sure this has been asked on this forum before. But, I couldn't find anything on it doing the search.
  7. I figured it out guys. I just had to insert a LIMIT 1 statement. Thanks anyways. $query_sum = "SELECT species_id, team_id, COUNT(species_id) FROM submit WHERE species_id=1 GROUP BY team_id ORDER BY COUNT(species_id) LIMIT 1";
  8. I have a table where I am counting the number of a particular species in my database. On my Display page I only want to show the highest value of species for that particular team. Is it possible to use the MAX() script to display the highest "COUNT()" value only? For example, Team A = 4 Red Drum Team B = 9 Red Drum Team C = 1 Red Drum My display table would only show Team B with 9 Red Drum Below is my count query for the total counted species of a particular id. $query_sum = "SELECT species_id, team_id, COUNT(species_id) FROM submit WHERE species_id=1 GROUP BY team_id"; But, how would I display only team B. Here is what I have so far and it displays all of the teams and the total number of that species. while($row = mysql_fetch_array($result)) { $team_id = $row['team_id']; $redfish = $row['COUNT(species_id)']; //get team's name from team table get_team_name($team_id); $_details .=<<<EOD <tr> <td align='center'>$teamname</td> <td align='center'>$redfish</td> </tr> EOD; } $_footer ="</table>"; $species_total =<<<SPECIESTABLE $_details $_footer SPECIESTABLE; print $species_total; ?>
  9. YAY!!! I got it!! THANKS MGALLFOREVER!! I had an error on the rest of my table. You had it correct. i didn't realize you could use order by and group by together. THANKS AGAIN!!
  10. I Tried that and for some reason it doesn't return any data from the database. I think its trying to GROUP BY team and then we are telling it to ORDER by total_points which contradicts the GROUP BY statement. I am clueless.
  11. Cool (one down), but how do I sort the Points from Highest to Lowest?
  12. hello again fellas. So, I am trying to make a standings page which will rank every team by the amount of points they have acquired. I figured out how to sum up the total points but I want to sort the points from Highest to Lowest and keep the (team/points) relationship together. Could you guys help out a Noobie!?! If you have any ideas on how I can populate the Rank column with First, Second, and third etc. that would help out too. But one step at a time. Thanks AGAIN!!! You guys always help out!! $query_sum = "SELECT team_id, SUM(points) FROM submit GROUP BY team_id"; $result = mysql_query($query_sum) or die(mysql_error()); $kayakwars_header=<<<EOD <h2><Center>Kayak Wars 2008 Standings</center></h2> <table width='70%' border='1' cellpadding='2' cellspacing='2' align='center'> <tr> <th>Rank</th> <th>Team</th> <th>Points</th> </tr> EOD; function get_team_name() { global $team_id; global $teamname; $query_d = "SELECT team_name FROM team WHERE team_id='$team_id'"; $results_d = mysql_query($query_d) or die(mysql_error()); $row_d = mysql_fetch_array($results_d); extract ($row_d); $teamname = $team_name; } while($row = mysql_fetch_array($result)) { $team_id = $row['team_id']; $points = $row['SUM(points)']; //get team's name from team table get_team_name($team_id); $kayakwars_details .=<<<EOD <tr> <td>First</td> <td>$teamname</td> <td>$points</td> </tr> EOD; } $kayakwars_footer ="</table>"; $kayak_wars =<<<KAYAKWARS $kayakwars_header $kayakwars_footer KAYAKWARS; print "There are $num_entries Kayak Wars submissions in our database"; print $kayak_wars;
  13. So in my form would I just have each <input> with the exact same id?? I am not sure how to code the form along with the php to where its all in one field. This is what my php looks like. With the form beneath it. <html> <head> </head> <?php if (isset($_POST['Submit'])) { $yyyy = $_POST['yyyy']; $mm = $_POST['mm']; $dd = $_POST['dd']; # THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(yyyy, mm, dd) values (''$yyyy', '$mm', '$dd', '$pic')"; if($result = mysql_query($sql ,$db)) { echo "Thank you, Your information has been entered into the database"; } else { echo "ERROR: ".mysql_error(); } } else { ?> <body> <form action="" method="POST" enctype="multipart/form-data" name="form1" id="form1"> <td><span class="style1">Date of Catch</span></td> <td><select name="yyyy" id="yyyy"> <option value="2008" selected="selected">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> </select> <select name="mm" id="mm"> <option value="00">Select Month</option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="dd" id="dd"> <option value="00">Select day</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select></td> <td colspan="2"> <div align="center"> <input type="Submit" name="Submit" id="Submit" value="Submit" /> <input type="reset" name="clear" id="clear" value="Clear" /> </div></td> </tr> </table> </div></td> </tr> </form> </body> <html>
  14. I have only shown a portion of the form but anyways...... When a user submits a date on the form below, the user chooses the year ("yyyy") month ("mm") and day ("dd"). Each piece of the form populates my database table "date" which has 3 fields (yyyy, mm, dd). The db fields are set as TINYINT(4). But, I have noticed that there is an option to set the db field as "DATE" Is there a better way to submit dates that I am not aware of? Is it possible to submit dates into one field rather than 3?? I tried an internet search and it comes back with all sorts of junk. It may be too simple to find a tutorial on. <html> <head> </head> <body> <form action="" method="POST" enctype="multipart/form-data" name="form1" id="form1"> <td><span class="style1">Date of Catch</span></td> <td><select name="yyyy" id="yyyy"> <option value="2008" selected="selected">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> </select> <select name="mm" id="mm"> <option value="00">Select Month</option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="dd" id="dd"> <option value="00">Select day</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select></td> <td colspan="2"> <div align="center"> <input type="Submit" name="Submit" id="Submit" value="Submit" /> <input type="reset" name="clear" id="clear" value="Clear" /> </div></td> </tr> </table> </div></td> </tr> </form> </body> <html>
  15. First off, thanks mainewoods for finding my mispelling in my last code. Now, I am trying to calculate the total points with a different value for each species of fish on the form. I thought I could use an "if" statement that would provide the correct value to multiply by. But it seems it isn't so easy. My code is shown below. How do I apply a different value for the var species1 in my function. For example if "species"=1 then {var species1=10} I would hope?????? <html> <head> <title>Kayak Wars Submission Form</title> <script type="text/javascript"> function calc_points() { if (getElementById("species").value=0) {var species1 = 0}; if (getElementById("species").value=1) {var species1 = 10}; if (getElementById("species").value=2) {var species1 = 10}; if (getElementById("species").value=3) {var species1 = 20}; if (getElementById("species").value=4) {var species1 = 20}; if (getElementById("species").value=5) {var species1 = 10}; if (getElementById("species").value=6) {var species1 = 20}; if (getElementById("species").value=7) {var species1 = 40}; if (getElementById("species").value= {var species1 = 20}; if (getElementById("species").value=9) {var species1 = 40}; if (getElementById("species").value=10) {var species1 = 10}; if (getElementById("species").value=11) {var species1 = 50}; if (getElementById("species").value=12) {var species1 = 20}; if (getElementById("species").value=13) {var species1 = 50}; if (getElementById("species").value=14) {var species1 = 50}; if (getElementById("species").value=15) {var species1 = 100}; if (getElementById("species").value=16) {var species1 = 50}; if (getElementById("species").value=17) {var species1 = 100}; if (getElementById("species").value=18) {var species1 = 100}; if (getElementById("species").value=19) {var species1 = 100}; if (getElementById("species").value=20) {var species1 = 200}; var quantity1 = document.getElementById("quantity").value; var total_points = (species1 * quantity1); document.getElementById("points").value = total_points; } </script> </head> <body> <form id="form1" name="form1" method="POST" action=""> <input type="hidden" name="submit_id" value="NULL"> <select name="species" id="species"> <option value="0">Select Species</option> <option value="1">Red Drum</option> <option value="2">Trout</option> <option value="3">Snook</option> <option value="4">Shark</option> <option value="5">Black Drum</option> <option value="6">Snapper</option> <option value="7">King Mackerel</option> <option value="8">Grouper</option> <option value="9">Cobia (Ling)</option> <option value="10">Flounder</option> <option value="11">Tarpon</option> <option value="12">Tripletail</option> <option value="13">Permit</option> <option value="14">Blackfin Tuna</option> <option value="15">Yellowfin Tuna</option> <option value="16">Barracuda</option> <option value="17">Bonefish</option> <option value="18">Dorado</option> <option value="19">Wahoo</option> <option value="20">Billfish</option> </select> <span class="style2"> <label>Quantity</label> </span> <label> <select name="quantity" id="quantity" onChange="calc_points();"> <option value="0">Select Quantity</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> </select> </label> <span class="style2"> <label>Total Points</label> </span> <label> <input name="points" id="points"> </body> </html>
  16. I am new to javascript so forgive me. Although, it seems very straightforward and logical and I can't figure out why this simple calculation is not working. I want the points field to be filled when I choose a species and place a quantity. For some reason nothing happens when I fill the too other form entities with values. <html> <head> <title>Kayak Wars Submission Form</title> <script type="text/javascript"> function calc_points() { var species1 = document.getElementById("species").value; var quantity2 = document.getElemendById("quantity").value; var total_points = (species1 * quantity2); document.getElementById("points").value = total_points; } </script> </head> <body> <form id="form1" name="form1" method="POST" action=""> <input type="hidden" name="submit_id" value="NULL"> <select name="species" id="species"> <option value="0">Select Species</option> <option value="1">Red Drum</option> <option value="2">Trout</option> <option value="3">Snook</option> <option value="4">Shark</option> <option value="5">Black Drum</option> <option value="6">Snapper</option> <option value="7">King Mackerel</option> <option value="8">Grouper</option> <option value="9">Cobia (Ling)</option> <option value="10">Flounder</option> <option value="11">Tarpon</option> <option value="12">Tripletail</option> <option value="13">Permit</option> <option value="14">Blackfin Tuna</option> <option value="15">Yellowfin Tuna</option> <option value="16">Barracuda</option> <option value="17">Bonefish</option> <option value="18">Dorado</option> <option value="19">Wahoo</option> <option value="20">Billfish</option> </select> <span class="style2"> <label>Quantity</label> </span> <label> <input name="quantity" type="text" id="quantity" size="3" maxlength="2" /> </label> <span class="style2"> <label>Total Points</label> </span> <label> <input name="points" id="points" onBlur="calc_points();"> </body> </html>
  17. Thanks guys. I will look up on some tutorials as to what you guys are talking about. I'll let you know what I learn or if I am still stuck.
  18. I am a beginner php guy but I can figure out most things. I created this Form and when I submit data the result I get doesn't coincide with the data chosen in the form. I get 1 - 0 - - 0 - 0 - 0 - 0 - 0 - 0 - 0 2 - 0 - - 0 - 0 - 0 - 0 - 0 - 0 - 0 3 - 0 - - 0 - 0 - 0 - 0 - 0 - 0 - 0 4 - 0 - - 0 - 0 - 0 - 0 - 0 - 0 - 0 and so on Can anybody help me figure out how to enter the correct data? What am I missing??? I am about 1 cup of coffee short from dropping my computer from the Sears Tower. Anybody ever see the movie Office Space where they went postal on the Copier/printer???? That's how I feel right about now...AHHHHHH!H!!!!H!H!H!H!H <?php #################################################################### ################ DATABASE CONFIGURE ############################## #################################################################### $hostname = "localhost"; $db_user = "********"; $db_password = "********"; $db_table = "submit"; # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db ("********") or die (mysql_error()); ?> <html> <head> <title>Kayak Wars Submission Form</title> <script type="text/javascript"> //<![CDATA[ // array of possible team in the same order as they appear in the country selection list var teamLists = new Array(5) teamLists["empty"] = ["Select Angler"]; teamLists["1"] = ["Oz", "Skipjack", "Curmit", "Old Salt", "Kip",]; teamLists["2"] = ["Jolly Roger", "Oscar", "Altonr77", "Mythman", "Crazy Yak"]; teamLists["3"] = ["Mako", "Tunakilla", "Jason Bundick", "Brandon Sellers", "Shane Casady"]; teamLists["4"] = ["Lets go", "Crank B8", "Bogdog", "Honky", "da kid from down south"]; /* teamChange() is called from the onchange event of a select element. * param selectObj - the select object which fired the on change event. */ function teamChange(selectObj) { // get the index of the selected option var idx = selectObj.selectedIndex; // get the value of the selected option var which = selectObj.options[idx].value; // use the selected option value to retrieve the list of items from the countryLists array cList = teamLists[which]; // get the team select element via its known id var cSelect = document.getElementById("angler"); // remove the current options from the country select var len=cSelect.options.length; while (cSelect.options.length > 0) { cSelect.remove(0); } var newOption; // create new options for (var i=0; i<cList.length; i++) { newOption = document.createElement("option"); newOption.value = cList[i]; // assumes option string and value are the same newOption.text=cList[i]; // add the new option try { cSelect.add(newOption); // this will fail in DOM browsers but is needed for IE } catch (e) { cSelect.appendChild(newOption); } } } //]]> </script> </head> <body> Kayak Wars Submission Form<hr> <?php if (isset($_REQUEST['Submit'])) { # THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(submit_id, team, angler, species, quantity, kayak, yyyy, mm, dd, water) values ('$submit_id', '$team', '$angler', '$species', '$quantity', '$kayak', '$yyyy', '$mm', '$dd', '$water')"; if($result = mysql_query($sql ,$db)) { echo "Thank you, Your information has been entered into the database"; } else { echo "ERROR: ".mysql_error(); } } else { ?> <form id="form1" name="form1" method="POST" action=""> <input type="hidden" name="submit_id" value="NULL"> <tr> <td><div align="left" class="style2">Team</div></td> <td><label> <select name="team" id="team" onChange="teamChange(this);"> <option value="0">Select a Team</option> <option value="1">Rockstar</option> <option value="2">Plastic Pirates</option> <option value="3">Third Coast Hustlas</option> <option value="4">Wildy</option> </select> </label></td> </tr> <tr> <td width="181"><div align="left" class="style2">Angler</div></td> <td width="309"><label> <select name="angler" id="angler"> <option value="0">Select Angler</option> </select> </label></td> </tr> <tr> <td><div align="left" class="style2">Species</div></td> <td><select name="species" id="species"> <option value="0">Select Species</option> <option value="1">Red Drum</option> <option value="2">Trout</option> <option value="3">Snook</option> <option value="4">Shark</option> <option value="5">Black Drum</option> <option value="6">Snapper</option> <option value="7">King Mackerel</option> <option value="8">Grouper</option> <option value="9">Cobia (Ling)</option> <option value="10">Flounder</option> <option value="11">Tarpon</option> <option value="12">Tripletail</option> <option value="13">Permit</option> <option value="14">Blackfin Tuna</option> <option value="15">Yellowfin Tuna</option> <option value="16">Barracuda</option> <option value="17">Bonefish</option> <option value="18">Dorado</option> <option value="19">Wahoo</option> <option value="20">Billfish</option> </select> <span class="style2"> <label>Quantity</label> </span> <label> <input name="quantity" type="text" id="quantity" size="3" maxlength="2" /> </label></td> </tr> <tr> <td><div align="left" class="style2">Kayak</div></td> <td><select name="kayak" id="kayak"> <option value="0">Select Kayak</option> <option value="1">Malibu 2 XL</option> <option value="2">Malibu 2</option> <option value="3">Cobra Fish N Dive</option> <option value="4">Scrambler XT</option> <option value="5">Speck</option> <option value="6">Hobie</option> </select></td> </tr> <tr> <td><div align="left" class="style2">Date of catch</div></td> <td><select name="yyyy" id="yyyy"> <option value="2008" selected="selected">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> </select> <select name="mm" id="mm"> <option value="00">Select Month</option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="dd" id="dd"> <option value="00">Select day</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> </td> </tr> <tr> <td><div align="left" class="style2">Body of Water</div></td> <td><label> <select name="water" id="water"> <option value="0">Select Body of Water</option> <option value="1">Upper Coast</option> <option value="2">Middle Coast</option> <option value="3">Lower Coast</option> </select> </label></td> </tr> <tr> <td colspan="2"><div align="center"> <label> <input type="Submit" name="Submit" id="Submit" value="Submit" /> </label> <label> <input type="reset" name="clear" id="clear" value="Clear" /> </label> </div></td> </tr> </form> <?php } ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.