Jump to content

fezzik

Members
  • Posts

    42
  • Joined

  • Last visited

    Never

Everything posted by fezzik

  1. Can anyone list a link or resource with a good/correct tutorial about creating a session for a site with multiple users. I'm interested in also being able to manage the session length. Any help is appreciated. Cheers, Fezzik
  2. Ignore this request. Issue solved. Thanks though!
  3. I've been looking for help with creating a automatic popup for a page. Most resources I've found only show how to implement a popup window with a link/button. I would like to have the popup launch depending on the state of a session variable. The session variable would be either true or false. I appreciate any assistance or information about other possible resources. Cheers, Fezzik
  4. This works: for ( $preloadCnt = 1; $preloadCnt <= 10; $preloadCnt ++ ) {   $_SESSION['preloaded_name_'.$preloadCnt] = $_POST['preloaded_name'.$preloadCnt];   $_SESSION['preloaded_num_'.$preloadCnt] = $_POST['preloaded_num'.$preloadCnt]; }
  5. Is it possble to use a for loop to create a series of variables and assign values to them? The below loop is incorrect. I'm attempting to assign $_SESSION['preloaded_name_X] = $preloaded_numX. X is equal to 1 thru 10. for ( $preloadCnt = 1; $preloadCnt <= 10; $preloadCnt ++ ) {   $_SESSION['preloaded_name_'.$preloadCnt] = $preloaded_name.$preloadCnt;   $_SESSION['preloaded_num_'.$preloadCnt] = $preloaded_num.$preloadCnt; } Any help is appreciated. Fezzik
  6. Thanks! I just discovered this! Cheers, Fezzik
  7. Thanks for the response. I believe that $_SESSION[$id] is not correct. I need to keep the $numbers[$id] as an array.
  8. I need help with correctly rewriting the below script as a session variable, primarily the correct way to write $numbers[$id] as a session array: if (isset($numbers[$id])) {   $numbers[$id] += $another_count; } else {   $numbers[$id] = $another_count; } foreach($numbers as $key => $val) echo $key . ' : ' . $val . "<br />\r\n"; Thank you for any assistance! Fezzik
  9. I need some help with creating a method to manage information from a form. The form has 2 input fields. The 1st field accepts a number similar to a sku or product code. The 2nd field accepts a number as a quantity. I think using a multidimensional array is a possible solution to store this data but I'm uncertain as to how to create the array and give it the desired functionality. One of the issues I'm trying to work out is that the form needs to allow the user to input the same product code multiple times. Since there is a count associated with each product code I would like matching product codes to have their count updated rather than being recorded as new entries. So there needs to be some sort of validation to see if the product code has already been entered. Sample data is as follows: Product Code(count) ------------------- 111222333(2) 444555666(1) 777888999(3) 111222333(2) I would like to store the data in the array as: Product Code(count) ------------------- 111222333(4) 444555666(1) 777888999(3) Any help is appreciated. If you need more information please let me know. A friend has helped by creating a untested ASP script that I'm trying to convert to PHP and test but I have been unsuccessful. [code] <% CONST COL_PNUM = 0 CONST COL_QTY = 1 Dim products Sub AddProduct( prodnum )     Dim row     products = Session("Products")     If Not IsArray(products) Then         ReDim products( 1, 10 ) ' arbitrary size         For row = 0 To 10 : products(COL_QTY,row) = 0 : Next     End If     ' See if we already have a product by that number     For row = 0 To UBound(products,2)         If products( COL_PNUM, row ) = prodnum Then             ' found match...bump quantity             products( COL_QTY, row ) = products( COL_QTY, row ) + 1             Session("products") = products ' save updated array             Exit Sub ' and we are done         End If     Next     ' no match found, so find an empty slot in array     For row = 0 To UBound(products,2)         If products( COL_QTY, row ) = 0 Then             products( COL_PNUM, row ) = prodnum             products( COL_QTY, row ) = 1             Session("products") = products ' save updated array             Exit Sub ' and we are done         End If     Next     ' no empty slot found...expand array     newslot = UBDOUND(products,2) + 1     ReDim Preserve products( 1, newslot + 9 ) ' allow extra space     ' zap the quantities in the new elements     For row = newslot To UBOUND(products,2) : products(COL_QTY,row) = 0 : Next     ' use the first slot for our new product     products( COL_PNUM, newslot ) = prodnum     products( COL_QTY, newslot ) = 1     Session("products") = products ' save updated array End Sub %> [/code] Cheers, Fezzik
  10. I'm looking for assistance with creating a method that displays a total on a page without requiring form submission. Basically I have a list of  items that are populated from a db query using php. I list the item name, quantity field, item price, item total and grand total. Similar to: Mishra's Workshop      [INPUT QUANTITY]    $250.00    [TOTAL] --------------------------------------------------------------                                                                   [GRAND TOTAL] When you change the quantity I would like the total to reflect the change without having to submit the form. I would also like the grand total to behave the same as total. Is it possible to use javascript to accomplish this? If so, can you please give me an example or a link with more details. If you need more information let me know. Cheers, Fezzik
  11. Thanks sasa! This function is splendid! I've been trying to modify your function so that it lists all the $data_key's associated with the $group_key but have been unsuccessful. Is this easily accomplished with the function you provided? Cheers, Fezzik
  12. Thanks for the responses. I'll see what I can come up with using your example.
  13. Sure! So I have a multidimensional array of many rows and 5 columns per row. The data is similar to: $myArray[0][0] = "Autobots"; $myArray[0][1] = "Bumblebee"; $myArray[0][2] = "VW Bug"; $myArray[0][3] = "Yellow"; $myArray[0][4] = "Smog Check"; $myArray[0][0] = "Autobots"; $myArray[0][1] = "Jazz"; $myArray[0][2] = "Porsche"; $myArray[0][3] = "White"; $myArray[0][4] = "Steering Realignment"; $myArray[0][0] = "Autobots"; $myArray[0][1] = "Optimus Prime"; $myArray[0][2] = "Diesel"; $myArray[0][3] = "Red and Blue"; $myArray[0][4] = "Catalytic Converter"; $myArray[0][0] = "Decepticons"; $myArray[0][1] = "Starscream"; $myArray[0][2] = "Flying Machine"; $myArray[0][3] = "Red"; $myArray[0][4] = "Girly Voice"; $myArray[0][0] = "Decepticons"; $myArray[0][1] = "Megatron"; $myArray[0][2] = "Pea Shooter"; $myArray[0][3] = "Purple and Black"; $myArray[0][4] = "Everything"; I would like to create a function that will cycle through the array and print something similar to (grouping every row by the value of the 1st column): Autobots ----------------- Bumblebee Jazz Optimus Prime Decepticons ----------------- Megatron Starscream Thus grouping and ordering the information that is printed by the value of the first column of the row. Here is my coding attempt: [code] // region $previousRegion = ""; $currentRegion = ""; // company $currentCompany = ""; $previousCompany = ""; // counter $tradeCounter = 0; foreach ($tradeInfo as $book) { foreach ($book as $key => $value){ // region if ( $key == 0 ) { $currentRegion = $value; if ( $currentRegion != $previousRegion ) { if ( $tradeCounter != 0 ) { echo "<br />"; } echo "<strong>".$value."</strong><br /><br />"; $previousCompany = ""; } } // company if ( $key == 1 ) { $currentCompany = $value; if ( $currentCompany != $previousCompany ) { echo "<span style=\"font-weight:bold;color:#5d5d5d;\">".$value."</span><br /><br />"; } } if ( !empty($value) && $key != 0 && $key != 1) { echo "$value <br />\n"; } if ( $key == 0 ) { $previousRegion = $value; } if ( $key == 1 ) { $previousCompany = $value; } if ( $key == 4 ) { echo "<br />"; } $tradeCounter ++; } } [/code] The variable names in my code do not reflect the sample data which I provided in this post. This code is just a reflection of my attempt to sort the array using foreach() and print the information how I would like it arranged. I hope this is clearer. Please let me know if you need additional details. Thanks for your response. Cheers, Fezzik
  14. I need help with how to accomplish the following... I have a multidimesional array with an unlimited number of rows and 5 columns called $myArray.The array is created from a database query. I would like to create 2 different displays from this array that are printed to a page. The first display would be grouping all rows which share the same value for a specified column (i.e. $myArray[$row][0]) and then printing them. Similar to: // array data $myArray[1][0] = "sifl"; $myArray[1][1] = "apple"; $myArray[2][0] = "olly"; $myArray[2][1] = "orange"; $myArray[3][0] = "sifl"; $myArray[3][1] = "pear"; $myArray[4][0] = "sifl"; $myArray[4][1] = "banana"; // printed output would look like sifl apple pear banana olly orange The second display would be similar but it would group rows which shared the same values for specified 2 columns. If anyone has the time to help me possibly create 2 functions to accomplish this task I would appreciate it. Any information is appreciated. Best, Fezzik
  15. Thanks for the responses! I was thinking javascript was the best route to take too. I just wanted to see if it could be easily accomplished with php. I did create a method that allows this functionality with php. I created session variables to hold the values of the form variables that were a result of the form submission. Once the validation encounters an error I redirect the user with the header() command but append the appropriate page link to the end of the url. (i.e. header(somewebpage.php#contactInfo)) This will redirect the user to the location of the error. Although the page is refreshed using the header() command all the user's form input is still displayed because it was preserved using session variables. Best, Fezzik
  16. Is there an alternative command to use that will move you to a specific section of a page? I don't want to refresh the page using header() but would like to move the user to a specified location on the page. Basically I have a large form. When you encounter validation errors after submission I want to 'jump' the user to the specific section of the form where the error occured. Cheers, Fezzik
  17. Nevermind. I have a different recursive script that I'm using now.
  18. I'm working on copying files from one directory to another. I'm trying to use a function I found at http://us2.php.net/copy to perform the requested operation. The function is as follows: [code] // A function to copy files from one directory to another one, including subdirectories and // nonexisting or newer files. Function returns number of files copied. // This function is PHP implementation of Windows xcopy  A:\dir1\* B:\dir2 /D /E /F /H /R /Y // Syntaxis: [$number =] dircopy($sourcedirectory, $destinationdirectory [, $verbose]); // Example: $num = dircopy('A:\dir1', 'B:\dir2', 1); function dircopy($srcdir, $dstdir, $verbose = false) {   $num = 0;   if(!is_dir($dstdir)) mkdir($dstdir);   if($curdir = opendir($srcdir)) {   while($file = readdir($curdir)) {     if($file != '.' && $file != '..') {       $srcfile = $srcdir . '\\' . $file;       $dstfile = $dstdir . '\\' . $file;       if(is_file($srcfile)) {         if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1;         if($ow > 0) {           if($verbose) echo "Copying '$srcfile' to '$dstfile'...";           if(copy($srcfile, $dstfile)) {             touch($dstfile, filemtime($srcfile)); $num++;             if($verbose) echo "OK\n";           }           else echo "Error: File '$srcfile' could not be copied!\n";         }                      }       else if(is_dir($srcfile)) {         $num += dircopy($srcfile, $dstfile, $verbose);       }     }   }   closedir($curdir);   }   return $num; } [/code] In my code I call the function: [code] // move files to temp directory if (DIRECTORY_SEPARATOR=='/') { $absolute_path = dirname(__FILE__).'/'; } else { $absolute_path = str_replace('\\\\', '/', dirname(__FILE__)).'/'; } $absolute_path = str_replace("admin/","",$absolute_path); echo $absolute_path."<br />"; // "/home/tyler/public_html/hymnal/" $scrdir = $absolute_path."uploads/".$categoryInfo['category_path']."/"; echo $scrdir."<br />"; // "/home/tyler/public_html/hymnal/uploads/652900643/" $dstdir = $absolute_path."uploads/temp/"; echo $dstdir."<br />"; // "/home/tyler/public_html/hymnal/uploads/temp/" // call move directory function $num = dircopy($scrdir, $dstdir, 1); echo $num."<br />"; [/code] I use the above code to find the absolute path and then strip "admin/" from the path because the directory "uploads/" resides on the same level as "admin/". The dircopy() function is not returning any errors so I'm not sure why it is not coping the files. I've included print statements to verify the information but I'm still unsuccessful in finding the problem. Any suggestions are appreciated. Cheers, Fezzik
  19. Cool! Thanks Tom. I'm coding some of this now. Thanks for letting me know the names of the read, write and copy functions.
  20. Can anyone give me some advice on the best method to use to create new directories via mkdir. If other functions are more appropriate to use please let me know. Background on what I wish to accomplish... I would like to organize files upon upload based on which group/category they belong to. I have one page that manages groups/categories called category.php. I would assume this would be the best page to manage directories since they are associated with the category. When I create a new category the script would validate by checking if the directory already exists and if it does not would create the new directory. Then if I decide to delete a category I would like to create a method that would move existing files within the directory to a temp directory and then delete the requested directory. Renaming directories would also be a nice feature if I needed to modify a category name. I'm currently reading the php manual for the best smethod to accomplish this. If anyone has any experience or can direct me to some good tutorials I would appreciate it. Best, Fezzik
  21. I think I have remedied this issue. It seems that imagecreatexxxx function was not being called due to the _imgFinal dimensions being larger than the _imgOrg dimensions. I noticed that some of the thumbnail images I was cropping were less than 75 pixels on one axis. The _cropSize function validates this: if (($nx > imagesx($this->_imgOrig)) || ($ny > imagesy($this->_imgOrig))) {   $this->_debug('The image could not be cropped because the size given is larger than the original image.');   return false; } Unfortunately I did not have the script printing errors. Thanks to those that posted. Sorry to waste your time. Cheers, Fezzik
  22. My last post may have been incorrect about the saveImage() function using an imagecreatexxxxx function. The cropToSize() function does use a imagecreatexxxx function though: [code] function cropToSize($x, $y, $position = ccCENTRE)     {         return ($this->_cropSize(-1, -1, ($x <= 0 ? 1 : $x), ($y <= 0 ? 1 : $y), $position));     } function _cropSize($ox, $oy, $nx, $ny, $position)     {         if ($this->_imgOrig == null) {             $this->_debug('The original image has not been loaded.');             return false;         }         if (($nx <= 0) || ($ny <= 0)) {             $this->_debug('The image could not be cropped because the size given is not valid.');             return false;         }         if (($nx > imagesx($this->_imgOrig)) || ($ny > imagesy($this->_imgOrig))) {             $this->_debug('The image could not be cropped because the size given is larger than the original image.');             return false;         }         if ($ox == -1 || $oy == -1) {             list($ox, $oy) = $this->_getCopyPosition($nx, $ny, $position);         }         if ($this->gdInfo['Truecolor Support']) {             $this->_imgFinal = imagecreatetruecolor($nx, $ny);             imagecopyresampled($this->_imgFinal, $this->_imgOrig, 0, 0, $ox, $oy, $nx, $ny, $nx, $ny);         } else {             $this->_imgFinal = imagecreate($nx, $ny);             imagecopyresized($this->_imgFinal, $this->_imgOrig, 0, 0, $ox, $oy, $nx, $ny, $nx, $ny);         }         return true;     } [/code]
  23. Thanks for posting! Can you explain further? I don't quite understand your post. This issue occurs with random images. I have one image in a group that recieves this error every time, while the remaining group's images do not. saveImage() creates a .jpg using imagejpeg and .png is created using imagepng(). So shouldn't the line: imagedestroy($this->_imgFinal); be ok? All the images I'm uploading are .jpg The function for saveImage() is: [code] function saveImage($filename, $quality = 90, $forcetype = '')     {         if ($this->_imgFinal == null) {             $this->_debug('There is no cropped image to save.');             return false;         }         $ext  = ($forcetype == '') ? $this->_getExtension($filename) : strtolower($forcetype);         $func = 'image' . ($ext == 'jpg' ? 'jpeg' : $ext);         if (!$this->_isSupported($filename, $ext, $func, true)) {             return false;         }         $saved = false;         switch($ext) {             case 'gif':                 if ($this->gdInfo['Truecolor Support'] && imageistruecolor($this->_imgFinal)) {                     imagetruecolortopalette($this->_imgFinal, false, 255);                 }             case 'png':                 $saved = $func($this->_imgFinal, $filename);                 break;             case 'jpg':                 $saved = $func($this->_imgFinal, $filename, $quality);                 break;         }         if ($saved == false) {             $this->_debug("The image could not be saved to the '$filename' file as the file type '$ext' using the '$func' function.");             return false;         }         return true;     } [/code] Cheers, Fezzik
  24. Is the user(admin) to have an 'accesslevel' associated with him/her which allows them access to certain information in the database or are you looking to retrieve all database rows where a column called 'accesslevel' has a value of 300? If it is the latter then you will need something like: $result = mysql_query("select * from table_name where accesslevel = 300"); while($row = mysql_fetch_array($result)) { // reference either the column name: $row['email'] or column number: $row[0] echo $row['column_0']; echo $row['column_1']; echo $row['column_2']; echo $row['column_3']; } If provide more information I can probably be of more assistance. Cheers, Fezzik
×
×
  • 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.