Jump to content

QuietWhistler

Members
  • Posts

    42
  • Joined

  • Last visited

    Never

Everything posted by QuietWhistler

  1. Hello everyone, I'm trying to build a website that's relying on a cache system, I chose Memcache for this. However, when we've tried to install it on our Linux Server with Cpanel, and tested Memcache, I got the following error: "Cannot connect to localhost:11211". I have checked in the php.ini file and it says that Memcache is installed correctly, with the port 11211. Also, the line "memcache.so" is added in the php ini. However, I cannot seem to find the correct host. When I use the function $memcache->addServer(), the php info file shows 1 persistent connection. My question is how to configure the host correctly so that it will work. Thanks, Shady El Gewily
  2. You can do it like this: <?php $checkboxes = array( "designer1" => "Designer", "pm1" => "PM", "writer" => "Writer", "pm2" => "PM" ); if( is_array( $checkboxes ) ) { foreach( $checkboxes as $key => $value ) { print( "<input type=\"checkbox\" name=\"" . $key . "\" class=\"checkbox\" id=\"" . $key . "\" /> <label for=\"" . $key . "\">" . $value . "</label></div> )"; } } ?>
  3. $lastmtime = 0; $lastfname = ""; if ($dh = opendir("../upload/")) { while (false !== ($file = readdir($dh))) { if (filemtime($file) > $lastmtime) { $lastmtime = filemtime($file); $lastfname = $file; } } } echo "<img src='../upload/$lastfname' />";
  4. First of all, skunkbad made a mistake in his script. foreach($_POST['checkboxes'] as $key=>$val) { $data_name .= $key . ","; //mind the dot $data_value .= $val . ","; //mind the dot } $qry = mysql_query("INSERT INTO fake ($data_name) VALUES ('$data_value')") or die(mysql_error()); Now to get rid of the last comma, I always use this method: $i = 0; foreach($_POST['checkboxes'] as $key=>$val) { $data_name .= $key; $data_value .= $val; if( $i != sizeof( $_POST[ "checkboxes" ] ) - 1 ) { $data_name .= ","; $data_value .= ","; } $i++; } $qry = mysql_query("INSERT INTO fake ($data_name) VALUES ('$data_value')") or die(mysql_error());
  5. What I do to catch errors with foreach loops, is checking if the variable is actually an array. So like this: <?php $multi_winner[ $i ] = $row[ "invited_by" ]; if( is_array( $multi_winner ) { foreach( $multi_winner as $value ) { print( "stuff" ); } } ?>
  6. I'm not going to write the whole code for you now, but you could use regex to find the tags. With the results of that tag, split in to tag (ex. "JOB", "other tags" ), and value. What you would then do is create a switch statement for the tag value. Then you make a function for example getJobs( $amount ), whereas $amount would be the value extracted with regex. Then you would do like this: $replace = getJobs( $amount ); And replace the tag by $replace. Hope you can work with this information.
  7. Why don't you use the following statement then? <?php $sql = "SELECT * FROM payment WHERE Name LIKE '%$Name%' AND ( Date > '$new_date1' AND Date < '$new_date2' ) LIMIT $offset, $rowsperpage"; ?>
  8. You can use the phpZipLocator class. You can download it at http://www.sanisoft.com/downloads/ziploc/phpZipLocator.zip. You can then calculate the distance like this: <?php $oZip = new phpZipLocator(); $distance = $oZip->distance( $zip1, $zip2 ); ?>
  9. You can also set it it more easily by using the integrated SQL math. You would then update it as follows: <?php if( is_numeric( $newnum ) ) { mysql_query( "UPDATE table SET total = total + '$flthrs'" ); } ?>
  10. As long as the $_SESSION array keys are the same as the variable names you assign them to, you can use the following code: <?php $keys = array( "sendertitle", "senderforename" ); //etc. if( is_array( $keys ) ) { foreach( $keys as $key => $value ) { if( isset( $_SESSION[ $value ] ) ) { ${$value} = $_SESSION[ $value ]; //or $_POST } } } ?>
  11. Try using the following code: <?php include("conf.inc.php"); // Includes the db and form info. $result = mysql_query("SELECT fname,lname,haddress,hcity,hstate,hzip FROM users WHERE hzip = 76247"); while( $row = mysql_fetch_array( $result ) ) { echo $row[ "fname" ] . "<br />"; } ?>
  12. <?php $currentMonth = 2; //february integer value ?> <select name="month"> <?php $months = array( "January", "February", "March" ); //etc. for( $i = 0; $i < sizeof( $months ); $i++ ) { if( $currentMonth == ( $i + 1 ) { print( "<option selected>" . $months[ $i ] . "</option>" ); } else { print( "<option>" . $months[ $i ] . "</option>" ); } } ?> </select>
  13. You are not returning any values in your function, so the $scores and $average variables are terminated at the closing } of your function. To prevent this you could pass the parameters like this: function doCalc( &$scores, &$average ) This is called passing variables by reference. It means that everything you do to those variables in your function, will stay that way, even when the function is closed.
  14. You can't use comparison operators in an URL. Just assign the variables like: http://www.website.com/index.php?sdate=20080601&&edate=20080701 and then use that query.
  15. $sql = "SELECT * FROM `table` WHERE `sdate` > '" . $_GET[ "begin" ] . "' && `edate` < '" . $_GET[ "edate" ] . "'"; mysql_query( $sql ); That should do it.
  16. Use the following: $times_star = strlen( $search_word ); for( $i = 0; $i < sizeof( $times_star ); $i++ ) { $replacement .= "*"; } $message = eregi_replace( "($search_word)", $replacement, $message ); Also, a tip: use a check before using a foreach loop, else you'll get an error code which is not very tidy. if( !is_array( $search_words ) ) { return false; }
  17. Look at the gmmktime() function: http://nl3.php.net/manual/en/function.gmmktime.php
  18. First of all, = is different than ==. The = operator, is the assignment operator and you use it like this: $variable = "value"; the == is a comparison operator and it is used for checking/comparing variables. So your if statement should be: if( $stocbProblem == false ){ //rest } Then, if it runs everytime, try outputting the $reorder and $qty values to check whether $stockProblem is actually set to true.
  19. for( $i = 0; $i < $nbr_rangees; $i++ ) { $sql_text .= ${mysql_result($results_text,$i,"name")} . "', "; } You can use it like that.
  20. ${$variablename}, use it like that and it'll give you for example: $variablename = "butter"; $butter = "lala"; print( ${$variablename} ); that will print: lala. Hope that helps.
  21. for( $i = 0; $i < $nbr_rangees; $i++ ) { $sql_text .= "`" . mysql_result($results_text,$i,"id") . "`, "; } $sql_text = substr( $sql_text, 0, strlen( $sql_text ) - 2 ); $sql_text .= ") VALUES ("; for( $i = 0; $i < $nbr_rangees; $i++ ) { $sql_text .= "'$" . mysql_result($results_text,$i,"name") . "', "; } $sql_text = substr( $sql_text, 0, strlen( $sql_text ) - 2 ); $sql_text .= ")"; mysql_query( $sql_text ) or die(mysql_error()); That should work. You had 2 mistakes. The first one being; the 2 in the substr function means that the last 2 characters should be skipped, so the , and the space. You only had a , in the first part. Then, you should substract it AFTER the for loop, else it will do it every time the for loop iterates.
  22. What is the code you are using now?
  23. For one thing, you have to strip the last ", " in your $sql_text. You can do that like this: $sql_text = substr( $sql_text, 0, strlen( $sql_text ) - 2 ); after each for loop. Let me know if that solves your problem.
  24. As SemiApocalyptic said, you cannot use a for loop in such a context. this is one way how you can do it: $sql_text = "INSERT INTO .... "; for( $i = 0; $i < $nbr_rangees; $i++ ) { $sql_text .= "text for each iteration"; } $sql_text .= "rest of the query"; mysql_query( $sql_text );
  25. header( "Location: doc.pdf" ); if you want to use PHP.
×
×
  • 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.