Jump to content

HuggieBear

Members
  • Posts

    1,899
  • Joined

  • Last visited

About HuggieBear

  • Birthday 06/14/1980

Contact Methods

  • Website URL
    http://www.phpfreaks.com

Profile Information

  • Gender
    Male
  • Location
    England, UK

HuggieBear's Achievements

Member

Member (2/5)

0

Reputation

  1. You can't pass in additional arguments to this function as it's a callback of uasort(), but you could use global variables. See the example below. I've added two new variables, sort order and sort key. I've also added quantity to the product array as a new key to sort on. <?php // Setup product array (You already have yours) $products = array( 'Bike' => array('price' => '199.99','quantity' => '1'), 'Apple' => array('price' => '0.87','quantity' => '2'), 'Car' => array('price' => '5999.00','quantity' => '3') ); // *NEW* Specify either ASC or DESC $sortorder = 'DESC'; // *NEW* Specify the key you'd like the array sorted on $sortkey = 'quantity'; // Comparison function *NOTE* You now change the sort order with the global variable, not by swaping the return values around function compare($x, $y){ global $sortorder; global $sortkey; if ( $x[$sortkey] == $y[$sortkey] ){ $return = 0; } if ($sortorder == 'ASC'){ return ($x[$sortkey] < $y[$sortkey]) ? -1 : 1; } else { return ($x[$sortkey] < $y[$sortkey]) ? 1 : -1; } } uasort($products, 'compare'); // Output the products echo '<pre>'; print_r($products); echo '</pre>'; ?>
  2. No, it will work, but as far as I'm aware it can't be done in the same page as you need to output different header types. It's easier if just the image path is stored in the database. I think you'll need a page that displays the html, with the image source links pointing to something like getimage.php?imageid=1
  3. Where's your code that does the insert, we'll let you know.
  4. You can still use the same principle, just a variable to keep count.
  5. OK, so is it safe to assume that if Friday is the 13th of the month and you run the script you want events from the database between Thursday 12th and Thursday 19th?
  6. I'm well thanks, if you don't get any joy after reading that then just shout.
  7. You realise that this will only send you an email when you run the page in the browser right?
  8. This should get you started // Set secret word $word = 'mysecretword'; // How many letters must they provide $required_letters = 3; // Populate array with letters keyed on their position $letters = array(); while (count($letters) < $required_letters){ $k = rand(1, strlen($word)); $letters[$k] = substr($word, $k-1, 1); } // Sort if you want them to enter the letters in order ksort($letters); // Print array echo '<pre>'; print_r($letters); echo '</pre>';
  9. So are you going to invoke the script every Friday morning or something?
  10. How is this script going to be invoked? Via the browser, or via a cron job?
  11. Take a look at the cURL library
  12. Hey Stu, you still hanging around on here. You could take a look at the is_dir() Rich
  13. Are you storing the actual image in the database or just the path to the image?
  14. Try this for returning the award // Query the database for active awards $res = mysql_query("SELECT code, award FROM awards WHERE active = '1'"); // Populate the codes array $codes = array(); while ($row = mysql_fetch_assoc($res)){ $codes[$row['code']] = $row['award']; } // Hardcoded userid, yours probably comes from a form or something $userid = '1'; // Query the database for user awards $res = mysql_query("SELECT * FROM log WHERE userid = '$userid'"); // Print the award details (I'm assuming this will only be a single row) $row = mysql_fetch_assoc($res); foreach ($codes as $code => $award){ if ($row[$code] == 1){ echo $award . "<br />\n"; } } As for the id, you can just use a simple count variable. Do you need the id to output as an HTML id, or do you just need it for layout of the awards?
×
×
  • 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.