PHP - Help!! How To Add A Minimum $i Counter Instead Of Maximum??
ok here is my code:
it has a counter variable $i at the start which basically acts as a maximum cutoff for how much data can be output. i have this variable set at 5. how can i make it so that it doesnt cut off the results (outputs the full 7 days worth of results if available), but ALWAYS outputs a minimum of 5 results? $now = $now-(7*24*60*60); // Display 7 Days of Results $query = mysql_query("SELECT * FROM table WHERE date >= '$now' ORDER BY max(date) desc"); $i = 0; while ($row = mysql_fetch_assoc($query)) { $cid = $row['cat_id']; $title = $row['name']; $seoname = cleanurl($title,0); $img = 'images/'.$seoname.'.jpg'; if (!file_exists($img)) { $img = ''; } else { $img = 'images/'.$seoname.'.jpg'; } if (!empty($img)) { $i++; } if (!empty($img) && $i <= 5) { // Always show ATLEAST 5 results echo '<img src="'.$img .'" style="width:528px;" alt="" />' . "\n"; } } Please help and look at my code..thanks. Similar TutorialsHi i need a bit of help. i have toner database which stores, the type, brand, colour, min, max stock. I just want to know if there is anyway of notifying the user when the toner reachs the min level, maybe highligh the row in red or something similar. many thanks. Here's the scenario.... A Customer clicks on a product on the product page, this will open up the page for the individual product. In this example, it's a shirt. The shirt is available in many sizes and colors. The Minimum QTY for this product is : 12 . The customer can select as many sizes and colors as they want, as long they select a total of 12 (all sizes + all colors = total). After making their selections for this shirt, there is an "Add to Cart" button. I would like to run a check to make sure that the total is equal to or greater than the minimum QTY. Here is the form : Code: [Select] <?php session_start(); require("db.php"); require("functions.php"); $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir); $prodsql = "SELECT * FROM products WHERE id = " . $_GET['id'] . ";"; $prodres = mysql_query($prodsql); $numrows = mysql_num_rows($prodres); $prodrow = mysql_fetch_assoc($prodres); $prodcatsql = "SELECT * FROM categories WHERE id = " . $_GET['id'] . ";"; $prodcatres = mysql_query($prodcatsql); $bulkcat = mysql_num_rows($prodcatres); if($numrows == 0) { header("Location: " . $config_basedir); } else { if($_POST['submit']) { if(!$_SESSION['SESS_ORDERNUM']) { if($_SESSION['SESS_LOGGEDIN']) { $sql = "INSERT INTO orders(customer_id, registered, date) VALUES(" . $_SESSION['SESS_USERID'] . ", 1, NOW())"; mysql_query($sql); session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = mysql_insert_id(); } else { $sql = "INSERT INTO orders(registered, date, session) VALUES(0, NOW(), '" . session_id() . "')"; mysql_query($sql); session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = mysql_insert_id(); } } foreach ($_POST as $name => $value) { if (substr($name, 0, 4) == 'qty_' && $value != '' && is_numeric($value)) { $arrOptions = explode('_', $name); $sizeid = $arrOptions[1]; $colorid = $arrOptions[2]; $quantity = $value; $itemsql = "INSERT INTO orderitems(order_id, product_id, size_id, color_id, quantity) VALUES (" . $_SESSION['SESS_ORDERNUM'] . ", " . $_GET['id'] . ", " . $sizeid . ", " . $colorid . ", " . $quantity . ")"; mysql_query($itemsql); } } $totalprice = $prodrow['price'] * $_POST['amountBox'] ; $updsql = "UPDATE orders SET total = total + " . $totalprice . " WHERE id = " . $_SESSION['SESS_ORDERNUM'] . ";"; mysql_query($updres); header("Location: " . $config_basedir . "showcart.php"); } else { require("header.php"); echo "<div id='adminhome'>"; echo "<form action='addtobasket.php?id=" . $_GET['id'] . "' method='POST'>"; echo "<table cellpadding='10' border='0'>"; echo "<tr>"; if(empty($prodrow['image2'])) { echo "<td width='205'><img src='store-images/no-image-large.jpg' width='200' alt='" . $prodrow['name'] . "'>"; } else { echo "<td width='205'> <img src='store-images/" . $prodrow['image2'] . "' width='200' alt='" . $prodrow['name'] . "'>"; } echo "</td>"; echo "<td>"; echo "<h1>";echo $prodrow['name'];echo "</h1>"; echo "<h2>";echo $prodrow['description'];echo "</h2>"; //echo "<pre>" . wordwrap( $prodrow['description'] , 30 ) . "</pre>"; echo "<p>";echo $prodrow['details'];echo "</p>"; echo "<br>"; if($bulkcat==0) { echo "<div id='bulk1'>"; echo "<table cellpadding='2' border='0'>"; echo "<tr>"; echo "<td>Quantity</td>"; echo "<td>12</td>"; echo "<td>24+</td>"; echo "<td>48+</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Price</td>"; echo "<td>$" . money_format('%i', $prodrow['price']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price2']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price3']) . "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "<div id='bulk2'>"; echo "<table cellpadding='2' border='0'>"; echo "<tr>"; echo "<br><div align='center'><strong>For Sizes 2XL - 5XL</strong></div>"; echo "</tr>"; echo "<tr>"; echo "<td>Quantity</td>"; echo "<td>12</td>"; echo "<td>24+</td>"; echo "<td>48+</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Price</td>"; echo "<td>$" . money_format('%i', $prodrow['price4']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price5']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price6']) . "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; } else { echo "<div id='bulk1'>"; echo "<table cellpadding='2' border='0'>"; echo "<tr>"; echo "<td>Quantity</td>"; echo "<td>12</td>"; echo "<td>24+</td>"; echo "<td>48+</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Price</td>"; echo "<td>$" . money_format('%i', $prodrow['price']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price2']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price3']) . "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; } echo "</td>"; echo "</tr>"; echo "</table>"; echo '<div id="basketmatrix">'; echo '<table cellpadding="1" border="1">'; echo '<tr>'; echo '<td></td>'; $arrsizes = array(); $i = 0; $result = mysql_query("SELECT DISTINCT s.id, s.size FROM sizes s INNER JOIN productoptions p ON s.id = p.sizeid WHERE p.productid = '" . $_GET['id'] . "' ORDER BY s.id"); while ($row = mysql_fetch_assoc($result)) { echo '<td class="heading">' . $row['size'] . '</td>'; $arrsizes[$i] = $row['id']; $i++; } echo '</tr>'; $i = 0; $result = mysql_query("SELECT DISTINCT c.id, c.color FROM colors c INNER JOIN productoptions p ON c.id = p.colorid WHERE p.productid = '" . $_GET['id'] . "' ORDER BY c.id"); while ($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<td class="heading">' . $row['color'] . '</td>'; foreach ($arrsizes as $sizevalue) { echo '<td><input type="text" name="qty_' . $sizevalue . '_' . $row['id'] . '" size="5" /></td>'; } echo '</tr>'; } echo '</table>'; echo '</div>'; echo "<br>"; echo "<br>"; echo '<table>'; echo '<tr>'; echo '<td>'; echo '<p>You MUST order a total of <font color="#ff0000"><strong>(' . $prodrow['minimum'] . ')</strong></font> or more to add this item to your cart.<br>'; echo '(all colors + all sizes = total)</p>'; echo '</td>'; echo '<tr>'; echo '<td>'; echo"<input type='submit' name='submit' value='Add To Cart'>"; echo '</td>'; echo '</tr>'; echo '</table>'; echo "</form>"; echo "</div>"; } } require("footer.php"); ?> I'm working on a little shopping cart and my issue is this.... Some of the products available have a minimum quantity that must be reached before they can add it to the cart. I have a field in the products table called "minimum". When the admin adds a new product, he inputs the minimum required to order the item. I need help figuring out how to write the code that checks to make sure the quantity entered meets the minimum quantity set in the products table. My code is below: Code: [Select] <?php session_start(); require("db.php"); require("functions.php"); $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir); $prodsql = "SELECT * FROM products WHERE id = " . $_GET['id'] . ";"; $prodres = mysql_query($prodsql); $numrows = mysql_num_rows($prodres); $prodrow = mysql_fetch_assoc($prodres); $prodcatsql = "SELECT * FROM categories WHERE id = " . $_GET['id'] . ";"; $prodcatres = mysql_query($prodcatsql); $bulkcat = mysql_num_rows($prodcatres); if($numrows == 0) { header("Location: " . $config_basedir); } else { if($_POST['submit']) { if(!$_SESSION['SESS_ORDERNUM']) { if($_SESSION['SESS_LOGGEDIN']) { $sql = "INSERT INTO orders(customer_id, registered, date) VALUES(" . $_SESSION['SESS_USERID'] . ", 1, NOW())"; mysql_query($sql); session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = mysql_insert_id(); } else { $sql = "INSERT INTO orders(registered, date, session) VALUES(0, NOW(), '" . session_id() . "')"; mysql_query($sql); session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = mysql_insert_id(); } } foreach ($_POST as $name => $value) { if (substr($name, 0, 4) == 'qty_' && $value != '' && is_numeric($value)) { $arrOptions = explode('_', $name); $sizeid = $arrOptions[1]; $colorid = $arrOptions[2]; $quantity = $value; $itemsql = "INSERT INTO orderitems(order_id, product_id, size_id, color_id, quantity) VALUES (" . $_SESSION['SESS_ORDERNUM'] . ", " . $_GET['id'] . ", " . $sizeid . ", " . $colorid . ", " . $quantity . ")"; mysql_query($itemsql); } } $totalprice = $prodrow['price'] * $_POST['amountBox'] ; $updsql = "UPDATE orders SET total = total + " . $totalprice . " WHERE id = " . $_SESSION['SESS_ORDERNUM'] . ";"; mysql_query($updres); header("Location: " . $config_basedir . "showcart.php"); } else { require("header.php"); echo "<div id='adminhome'>"; echo "<form action='addtobasket.php?id=" . $_GET['id'] . "' method='POST'>"; echo "<table cellpadding='10' border='0'>"; echo "<tr>"; if(empty($prodrow['image'])) { echo "<td width='205'><img src='store-images/no-image-large.jpg' width='200' alt='" . $prodrow['name'] . "'>"; } else { echo "<td width='205'> <img src='store-images/" . $prodrow['image'] . "' width='200' alt='" . $prodrow['name'] . "'>"; } echo "</td>"; echo "<td>"; echo "<h1>";echo $prodrow['name'];echo "</h1>"; echo "<h2>";echo $prodrow['description'];echo "</h2>"; //echo "<pre>" . wordwrap( $prodrow['description'] , 30 ) . "</pre>"; echo "<p>";echo $prodrow['details'];echo "</p>"; echo "<br>"; if($bulkcat==0) { echo "<div id='bulk1'>"; echo "<table cellpadding='2' border='0'>"; echo "<tr>"; echo "<td>Quantity</td>"; echo "<td>12</td>"; echo "<td>24+</td>"; echo "<td>48+</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Price</td>"; echo "<td>$" . money_format('%i', $prodrow['price']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price2']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price3']) . "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "<div id='bulk2'>"; echo "<table cellpadding='2' border='0'>"; echo "<tr>"; echo "<br><div align='center'><strong>For Sizes 2XL - 5XL</strong></div>"; echo "</tr>"; echo "<tr>"; echo "<td>Quantity</td>"; echo "<td>12</td>"; echo "<td>24+</td>"; echo "<td>48+</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Price</td>"; echo "<td>$" . money_format('%i', $prodrow['price4']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price5']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price6']) . "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; } else { echo "<div id='bulk1'>"; echo "<table cellpadding='2' border='0'>"; echo "<tr>"; echo "<td>Quantity</td>"; echo "<td>12</td>"; echo "<td>24+</td>"; echo "<td>48+</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Price</td>"; echo "<td>$" . money_format('%i', $prodrow['price']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price2']) . "</td>"; echo "<td>$" . money_format('%i', $prodrow['price3']) . "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; } echo "</td>"; echo "</tr>"; echo "</table>"; echo '<div id="basketmatrix">'; echo '<table cellpadding="1" border="1">'; echo '<tr>'; echo '<td></td>'; $arrsizes = array(); $i = 0; $result = mysql_query("SELECT DISTINCT s.id, s.size FROM sizes s INNER JOIN productoptions p ON s.id = p.sizeid WHERE p.productid = '" . $_GET['id'] . "' ORDER BY s.id"); while ($row = mysql_fetch_assoc($result)) { echo '<td class="heading">' . $row['size'] . '</td>'; $arrsizes[$i] = $row['id']; $i++; } echo '</tr>'; $i = 0; $result = mysql_query("SELECT DISTINCT c.id, c.color FROM colors c INNER JOIN productoptions p ON c.id = p.colorid WHERE p.productid = '" . $_GET['id'] . "' ORDER BY c.id"); while ($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<td class="heading">' . $row['color'] . '</td>'; foreach ($arrsizes as $sizevalue) { echo '<td><input type="text" name="qty_' . $sizevalue . '_' . $row['id'] . '" size="5" /></td>'; } echo '</tr>'; } echo '</table>'; echo '</div>'; echo "<br>"; echo "<br>"; echo '<table>'; echo '<tr>'; echo '<td>'; echo '<p>You MUST order a total of <font color="#ff0000"><strong>(' . $prodrow['minimum'] . ')</strong></font> or more to add this item to your cart.<br>'; echo '(all colors + all sizes = total)</p>'; echo '</td>'; echo '<tr>'; echo '<td>'; echo"<input type='submit' name='submit' value='Add To Cart'>"; echo '</td>'; echo '</tr>'; echo '</table>'; echo "</form>"; echo "</div>"; } } require("footer.php"); ?> I need help this problem seem too tricky for me right now. I got an array with decimal numbers and behind it says Yes/No. The min() function works magically and still is able to correctly give me the lowest value. But how do i make a while loop that loops until it pops a value that is lowest and has Yes behind it? For example: Array => ('11,64|No', '209,81|Yes', '533,42|Yes', '27,90|No', '93,01|Yes') So this function should return '93,01|Yes' Hi all, I have the following array, which represents option_id => number_of_votes Code: [Select] Array ( [3] => 4 [5] => 5 [2] => 11 ) Is it possible to look at the value side of the array and neglect the smallest values, and pick a vote winner? Also, if we get the case: Code: [Select] Array ( [3] => 4 [5] => 11 [2] => 11 ) can we pick a random winner between option 5 and option 2? Thanks so much for all your help, let me know if more information will be useful. Hi Guys I am adding a short contact form to a site. All the fields are text fields. What do you think is the minimum validation I need to add to make the form safe against hacking etc. Thanks i want make php script using minimum spanning tree algorithm, the start node is define from user input, and the end nodes are from database table. the distance is calculated between Start node (koord_x, koord_y) and end nodes (koord_x2, koord_y2). The output are the minimun distance, name start node and end node include distance between them. please help me, i'm working on my thesis... Okay, I have a healing spell that allows people to regain stats when it's cast. But, how do I limit it so that they can't go over their maxhp? Here's what I have so far: $db->execute("UPDATE `users` SET `hp`=?, `mp`=?, `energy`=? WHERE `id`=?", array($player->hp + $healspell, $player->mp - $spell['mp'], $player->energy - $spell['energy'], $player->id)); What do I need to do in this to tell it to limit it to the maxhp but never going over it? $healspell is a random number, so it is quite possible to go over the maxhp at the moment. Thank you! Hi I know that maximum size of one cookie is 4Kb.. That is kilobytes right? and not kilobit? And a byte is 8 bits right? So if I have "Hello" in my cookie thats 5 characters which means the cookie is 5 x 8 = 40 bit which is again 5 bytes (?). Does this mean that I can have a maximum of 4000 characters in my cookie? Or did I miss something here? Thanks Im having a hard time even explaining this so a search was not fruitful.
I have an INT column in a mysql table. i want to UPDATE it in increments of 10 but the value should never exceed 100. what is an efficient way to do this?
ie. if the current value in the field is 96, when it tried to update
field = field+10, it should dynamically only be field = field+4so that we do not exceed the 100 mark. I have a simple script that imports all images in a folder to my site and generates thumbnails. It works, but on folders with a rather large amount of images (500+) it can reach the max execution time and give a fatal error. I could always break up my import folders into smaller chunks or increase the max execution time, but I am wondering if there is a different approach I could take. Is there a way to reset the execution time of a script by inserting some kind of a pause/delay? I got 30 files to convert to png each in a dir containing 5 files I get the maximum execution time when i run the following code: Code: [Select] $dir = glob("images/*/*.png"); foreach($dir as $file) { $filename = $file; $files = getimagesize($filename); $img = imagecreatefrompng($filename); imagepng($img,$filename); } hi Lets say a member has 4500 points and I have this code: Code: [Select] UPDATE points SET members_point=(members_point+1000)....... but will not allow it to go above 5000 how should this be written? I have a comment section that is secure against everything except spam.. Is there anyway to do like a 10second minimum wait time between posts? I want to set a never expire date, so I figured I would set the date 99 years into the future. No dice. After trial and error, it appears you can only make it 25 years into futu date("Y-m-d",strtotime("+25 years")); I wonder if it is the absolute date, or the number 25. If it is the maximum date (i.e. nothing after 2035) then I will have a problem with this code next year! Please help me out ..... ERROR: Maximum execution time of 30 seconds exceeded error occured in the function CRM/sys1.7.2/database/DB_active_rec.php line num :180 i.e $this->$item = $default_value; function _reset_run($ar_reset_items) { foreach ($ar_reset_items as $item => $default_value) { if ( ! in_array($item, $this->ar_store_array)) { $this->$item = $default_value; } } } Hi, I have a Flash contact form that sends its name, e-mail, and message variables to a PHP script. The script works fine if the message is under ~700 characters, but anything more and the script won't post the message at all. An e-mail with just the name and e-mail address will come through to my inbox (which is embarrassing as a potential client sent me a contact form e-mail about a development job ). Is there some way to check the maximum character length for a string variable? Or to set its length to something higher? This is my php. Thank you!! <? $senderName = $_POST['userName']; $senderEmail = $_POST['userEmail']; $senderMessage = $_POST['userMsg']; $senderName = stripslashes($senderName); $senderMessage = stripslashes($senderMessage); $senderMessage = strip_tags($senderMessage, '<p><br>'); $to = "kevin@kevinburkeportfolio.com"; $from = "email@kevinburkeportfolio.com"; $subject = "E-mail from $senderName"; $message = "<p><font size='2.5' face='Helvetica Neue, Helvetica, Sans Serif'><b>FROM:</b> $senderName <br><br> <b>E-MAIL:</b> <a href='mailto:$senderEmail'>$senderEmail</a> <br><br> <b>MESSAGE:</b> $senderMessage</p>"; $headers = "From: $from\r\n"; $headers = "MIME-Version: 1.0\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $to = "$to"; mail($to, $subject, $message, $headers); $my_msg = "Thanks $senderName, your message has been sent."; print "return_msg=$my_msg"; exit(); ?> hello, I am using a script which takes backup of my database and convert it into a zip file, I am getting following error Code: [Select] Fatal error: Maximum execution time of 30 seconds exceeded in /home/USERNAME/public_html/functions.php on line 110 I know I read and search forum for solving this by editing PHP.INI file, but i Have no access to it So is their any way that I can able to run the script but modifying it?? Its working fine on localhost I have also attached the files Code: [Select] <?php /** * Class to dynamically create a zip file (archive) * * @author Rochak Chauhan */ class createZip { public $compressedData = array(); public $centralDirectory = array(); // central directory public $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record public $oldOffset = 0; /** * Function to create the directory where the file(s) will be unzipped * * @param $directoryName string * */ public function addDirectory($directoryName) { $directoryName = str_replace("\\", "/", $directoryName); $feedArrayRow = "\x50\x4b\x03\x04"; $feedArrayRow .= "\x0a\x00"; $feedArrayRow .= "\x00\x00"; $feedArrayRow .= "\x00\x00"; $feedArrayRow .= "\x00\x00\x00\x00"; $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("v", strlen($directoryName) ); $feedArrayRow .= pack("v", 0 ); $feedArrayRow .= $directoryName; $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("V",0); $this -> compressedData[] = $feedArrayRow; $newOffset = strlen(implode("", $this->compressedData)); $addCentralRecord = "\x50\x4b\x01\x02"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x0a\x00"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x00\x00\x00\x00"; $addCentralRecord .= pack("V",0); $addCentralRecord .= pack("V",0); $addCentralRecord .= pack("V",0); $addCentralRecord .= pack("v", strlen($directoryName) ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $ext = "\x00\x00\x10\x00"; $ext = "\xff\xff\xff\xff"; $addCentralRecord .= pack("V", 16 ); $addCentralRecord .= pack("V", $this -> oldOffset ); $this -> oldOffset = $newOffset; $addCentralRecord .= $directoryName; $this -> centralDirectory[] = $addCentralRecord; } /** * Function to add file(s) to the specified directory in the archive * * @param $directoryName string * */ public function addFile($data, $directoryName) { $directoryName = str_replace("\\", "/", $directoryName); $feedArrayRow = "\x50\x4b\x03\x04"; $feedArrayRow .= "\x14\x00"; $feedArrayRow .= "\x00\x00"; $feedArrayRow .= "\x08\x00"; $feedArrayRow .= "\x00\x00\x00\x00"; $uncompressedLength = strlen($data); $compression = crc32($data); $gzCompressedData = gzcompress($data); $gzCompressedData = substr( substr($gzCompressedData, 0, strlen($gzCompressedData) - 4), 2); $compressedLength = strlen($gzCompressedData); $feedArrayRow .= pack("V",$compression); $feedArrayRow .= pack("V",$compressedLength); $feedArrayRow .= pack("V",$uncompressedLength); $feedArrayRow .= pack("v", strlen($directoryName) ); $feedArrayRow .= pack("v", 0 ); $feedArrayRow .= $directoryName; $feedArrayRow .= $gzCompressedData; $feedArrayRow .= pack("V",$compression); $feedArrayRow .= pack("V",$compressedLength); $feedArrayRow .= pack("V",$uncompressedLength); $this -> compressedData[] = $feedArrayRow; $newOffset = strlen(implode("", $this->compressedData)); $addCentralRecord = "\x50\x4b\x01\x02"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x14\x00"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x08\x00"; $addCentralRecord .="\x00\x00\x00\x00"; $addCentralRecord .= pack("V",$compression); $addCentralRecord .= pack("V",$compressedLength); $addCentralRecord .= pack("V",$uncompressedLength); $addCentralRecord .= pack("v", strlen($directoryName) ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("V", 32 ); $addCentralRecord .= pack("V", $this -> oldOffset ); $this -> oldOffset = $newOffset; $addCentralRecord .= $directoryName; $this -> centralDirectory[] = $addCentralRecord; } /** * Fucntion to return the zip file * * @return zipfile (archive) */ public function getZippedfile() { $data = implode("", $this -> compressedData); $controlDirectory = implode("", $this -> centralDirectory); return $data. $controlDirectory. $this -> endOfCentralDirectory. pack("v", sizeof($this -> centralDirectory)). pack("v", sizeof($this -> centralDirectory)). pack("V", strlen($controlDirectory)). pack("V", strlen($data)). "\x00\x00"; } } /* MySQL database backup class, version 1.0.0 Written by Vagharshak Tozalakyan <vagh@armdex.com> Released under GNU Public license */ define('MSB_VERSION', '1.0.0'); define('MSB_NL', "\r\n"); define('MSB_STRING', 0); define('MSB_DOWNLOAD', 1); define('MSB_SAVE', 2); class MySQL_Backup { var $server = 'localhost'; var $port = 3306; var $username = 'root'; var $password = ''; var $database = ''; var $link_id = -1; var $connected = false; var $tables = array(); var $drop_tables = true; var $struct_only = false; var $comments = true; var $backup_dir = ''; var $fname_format = 'd_m_y__H_i_s'; var $error = ''; function Execute($task = MSB_STRING, $fname = '', $compress = false) { if (!($sql = $this->_Retrieve())) { return false; } if ($task == MSB_SAVE) { if (empty($fname)) { $fname = $this->backup_dir; $fname .= date($this->fname_format); $fname .= ($compress ? '.sql.gz' : '.sql'); } return $this->_SaveToFile($fname, $sql, $compress); } elseif ($task == MSB_DOWNLOAD) { if (empty($fname)) { $fname = date($this->fname_format); $fname .= ($compress ? '.sql.gz' : '.sql'); } return $this->_DownloadFile($fname, $sql, $compress); } else { return $sql; } } function _Connect() { $value = false; if (!$this->connected) { $host = $this->server . ':' . $this->port; $this->link_id = mysql_connect($host, $this->username, $this->password); } if ($this->link_id) { if (empty($this->database)) { $value = true; } elseif ($this->link_id !== -1) { $value = mysql_select_db($this->database, $this->link_id); } else { $value = mysql_select_db($this->database); } } if (!$value) { $this->error = mysql_error(); } return $value; } function _Query($sql) { if ($this->link_id !== -1) { $result = mysql_query($sql, $this->link_id); } else { $result = mysql_query($sql); } if (!$result) { $this->error = mysql_error(); } return $result; } function _GetTables() { $value = array(); if (!($result = $this->_Query('SHOW TABLES'))) { return false; } while ($row = mysql_fetch_row($result)) { if (empty($this->tables) || in_array($row[0], $this->tables)) { $value[] = $row[0]; } } if (!sizeof($value)) { $this->error = 'No tables found in database.'; return false; } return $value; } function _DumpTable($table) { $value = ''; $this->_Query('LOCK TABLES ' . $table . ' WRITE'); if ($this->comments) { $value .= '#' . MSB_NL; $value .= '# Table structure for table `' . $table . '`' . MSB_NL; $value .= '#' . MSB_NL . MSB_NL; } if ($this->drop_tables) { $value .= 'DROP TABLE IF EXISTS `' . $table . '`;' . MSB_NL; } if (!($result = $this->_Query('SHOW CREATE TABLE ' . $table))) { return false; } $row = mysql_fetch_assoc($result); $value .= str_replace("\n", MSB_NL, $row['Create Table']) . ';'; $value .= MSB_NL . MSB_NL; if (!$this->struct_only) { if ($this->comments) { $value .= '#' . MSB_NL; $value .= '# Dumping data for table `' . $table . '`' . MSB_NL; $value .= '#' . MSB_NL . MSB_NL; } $value .= $this->_GetInserts($table); } $value .= MSB_NL . MSB_NL; $this->_Query('UNLOCK TABLES'); return $value; } function _GetInserts($table) { $value = ''; if (!($result = $this->_Query('SELECT * FROM ' . $table))) { return false; } while ($row = mysql_fetch_row($result)) { $values = ''; foreach ($row as $data) { $values .= '\'' . addslashes($data) . '\', '; } $values = substr($values, 0, -2); $value .= 'INSERT INTO ' . $table . ' VALUES (' . $values . ');' . MSB_NL; } return $value; } function _Retrieve() { $value = ''; if (!$this->_Connect()) { return false; } if ($this->comments) { $value .= '#' . MSB_NL; $value .= '# MySQL database dump' . MSB_NL; $value .= '# Created by MySQL_Backup class, ver. ' . MSB_VERSION . MSB_NL; $value .= '#' . MSB_NL; $value .= '# Host: ' . $this->server . MSB_NL; $value .= '# Generated: ' . date('M j, Y') . ' at ' . date('H:i') . MSB_NL; $value .= '# MySQL version: ' . mysql_get_server_info() . MSB_NL; $value .= '# PHP version: ' . phpversion() . MSB_NL; if (!empty($this->database)) { $value .= '#' . MSB_NL; $value .= '# Database: `' . $this->database . '`' . MSB_NL; } $value .= '#' . MSB_NL . MSB_NL . MSB_NL; } if (!($tables = $this->_GetTables())) { return false; } foreach ($tables as $table) { if (!($table_dump = $this->_DumpTable($table))) { $this->error = mysql_error(); return false; } $value .= $table_dump; } return $value; } function _SaveToFile($fname, $sql, $compress) { if ($compress) { if (!($zf = gzopen($fname, 'w9'))) { $this->error = 'Can\'t create the output file.'; return false; } gzwrite($zf, $sql); gzclose($zf); } else { if (!($f = fopen($fname, 'w'))) { $this->error = 'Can\'t create the output file.'; return false; } fwrite($f, $sql); fclose($f); } return true; } } function mailAttachment($file, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $filename = basename($file); $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!"; } } function directoryToArray($directory, $recursive) { $array_items = array(); if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir($directory. "/" . $file)) { if($recursive) { $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive)); } $file = $directory . "/" . $file ."/"; $array_items[] = preg_replace("/\/\//si", "/", $file); } else { $file = $directory . "/" . $file; $array_items[] = preg_replace("/\/\//si", "/", $file); } } } closedir($handle); } return $array_items; } function pr($val) { echo '<pre>'; print_r($val); echo '</pre>'; } ?> Hey, I'm getting an error: Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\test.php on line 11 My code: <?php $file = fopen ('C:\xampp\htdocs\GDict.txt', 'r'); $i = 0; while(!feof ($file)) { $load[$i] = fgets($file, 1024); mysql_connect("localhost","root",""); mysql_select_db("md5"); $word = $load[$i]; $md5 = md5($word); mysql_query("INSERT INTO md5 VALUES ('$md5', '$word');"); $i++; $limit = count($load); $width2 = $limit; } fclose($file); echo '[o] Loaded' . $limit . 'word. <br />'; echo '<br />Done.'; ?> I have tried changing the php.ini file. max_execution_time = 60 To max_execution_time = 30000000000000 But that still dosent work. Any help would be loved Thanks Jragon I have a counter that updates the database automatically with out refreshing the page. However i was wondering if someone can give me some pointers on how i can keep it updating the database even after someone exits the page. Currently it updates the database every 2 seconds by increasing the number by 1..however i want to be able to do this even if the page i not loaded is there any way i can do this? |