Jump to content

Cagecrawler

Members
  • Posts

    247
  • Joined

  • Last visited

    Never

Everything posted by Cagecrawler

  1. <?php function filter_keys(&$array, $n, $offset) { for($i = $offset; $i < count($array); $i = $i+$n) { unset($array[$i]); unset($array[$i + 1]); //For a more generic function, remove this and then call the function twice. } } Passing the array by reference removes the need to return the function. I haven't tested it.
  2. Don't use w3schools. The information is quite often out of date (they still list .php3 as a php file extension) or just plain wrong. If you really want a beginner site like that, I'd recommend Tizag but the first sections of the manual explain the syntax pretty well. As for the list of other things to learn, xhtml is dead. Use html5, that's where the standard is going. Also, ajax is javascript. The best way to learn is to practice. Write a script for any problem you have, whether it's organising your music collection or grabbing the latest tweets.
  3. You've got an extra semi-colon in there. There should only be one at the end, not after true).
  4. mysql_affected_rows gives you the number of rows affected. Timings you'll have to make yourself.
  5. It's only two lines, it's about as simple as you can get it... And I made a typo - the function is mysql_fetch_assoc, not mysql_assoc.
  6. <?php $query = mysql_query("SELECT * FROM table ORDER BY datetime ASC"); $ids = array(); $startTime = null; while ($row = mysql_fetch_assoc($result)) { if($startTime == null) { $ids[] = $row['id']; $startTime = $row['datetime']; } else if(strtotime($row['datetime']) - strtotime($lastRow['datetime']) > 60*15) { //Within 15 mins of the last row. $ids[] = $row['id']; } else { //Not within 15 mins, so dump the info and start a new row. var_dump($ids,$startTime,$lastRow['datetime']); $ids = array(); $startTime = null; } $lastRow = $row; } Something like this should work.
  7. $newsletters = mysql_assoc(mysql_query("SELECT mens, womens FROM newsletters WHERE email = '$email' LIMIT 1")); if($newsletters['mens'] == 0 && $newsletters['womens'] == 0){
  8. Your routes both have the same name (post) and are overwriting each other.
  9. It's the validator that's the problem, your code produces a valid output. <?xml version="1.0"?> <myroot><title number="12"><titleName>title1</titleName><titleLink>link1</titleLink></title></myroot> Try http://validator.w3.org/.
  10. Something like this should get you started. <?php $input = "15/09/11 - 18/06/11"; //Explode input to get first date. $dates = explode("-", $input); //Explode it again to get the date parts. $dateParts = explode("/", $dates[0]); //Flip the parts around to Americanise the date, since that's what strtotime takes. $time = strtotime($dateParts[1]."/".$dateParts[0]."/".$dateParts[2]); //Compare to the current time. echo ($time - time() > 60*60*24*30) ? "OVER 30 DAYS" : "UNDER 30 DAYS";
  11. You need to look at the GD image functions: imagecreatefromjpeg or imagecreatefromgif imagecopyresampled imagejpeg or imagegif
  12. The Google Contacts API is probably what you're looking for with regards to Gmail accounts. The Windows Live API probably has something similar.
  13. You can work out if it's a multiple by using the modulus operator (%) and then run an if else to compare different multiples. $my_no = mt_rand(1, 100); if($my_no % 3 == 0) { echo "<td style=\"background-color:red\">$my_no</td>"; } else if($my_no % 2 == 0) { echo "<td style=\"background-color:blue\">$my_no</td>"; } else { echo "<td>$my_no</td>"; } Numbers which are both multiples of 3 and 2 (eg. 6) will be coloured red since that comes first in the if else.
  14. You just need to put another for loop around the code that generates the row. for($ii = 0; $ii < $number_of_rows; $ii++) { echo "<tr>"; for ($i=0; $i<$number_of_columns; $i++) { $my_no = mt_rand(1, 100); echo "<td>$my_no</td>"; } echo "</tr>"; }
  15. You can't close a loop in the middle of the string. The for loop needs to look like this: for ($i = 0; $i < $numItem; $i++) { extract($orderedItem[$i]); $subTotal += $pd_price * $od_qty; $message_c += "<tr class=\"content\"> <td>". $od_qty . " x " . $pd_name ."</td> <td align=\"right\">". displayAmount($pd_price). "</td> <td align=\"right\">". displayAmount($od_qty * $pd_price). "</td> </tr>"; } $message_c += "</table>";
  16. Are the mail settings in your php.ini set correctly? Try removing the @ at the beginning of the mail function, it's blocking any possible error messages that may help diagnose what's wrong.
  17. Your string isn't in quotes: @mail($name.'@myemailaddress.com', $subject, $msg, $headers);
  18. gallery_user needs to be int(11) rather than varchar(20). It should also be a foreign key with users.id. When the user logs in, put their id into the session. Then, when they go to view the images, you can use the following query: $query = "SELECT image_id FROM images WHERE gallery_user = '{$_SESSION['user_id']}'"; When you run the query, you can then output the images in a similar manner to your code earlier in the thread. You should also do a check to make sure they're logged in before the query is run (else the session value won't be set).
  19. Depending on your table structure, you should just need a select like this: $query = "SELECT * FROM galleries WHERE user_id = '{$_SESSION['user_id']}'";
  20. Instead of having your script set the header type and then echo the image content, just save that content to a file. file_put_contents('/path/to/image.jpg',$imgContent);
  21. Storing a value in a session is as simple as doing: session_start(); $_SESSION['key'] = $value; Also see the session handling documentation. All you need to do is retrieve the value you want from your database (depends on which database you're using) and then assign it as above. If you're unsure of how to do this, I suggest you read the documentation for your database.
  22. It is possible, look at mkdir and the fopen family of functions. Any file you write to can be used the same as any other file on the filesystem (you can use include for example).
  23. I think so, the manual talks of a change to the errors thrown in PHP4.4.0.
  24. & before a function name means the function returns a reference. The second & is to do with references as well, it passes a reference of the Configure object to $instance[0], rather than a copy.
×
×
  • 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.