Jump to content

HuggieBear

Members
  • Posts

    1,899
  • Joined

  • Last visited

Everything posted by HuggieBear

  1. You haven't made the change yet...  :D Look at the while loop I just posted.  I concatenate the string before using it in fwrite(). Regards Huggie
  2. Fear, it probably doesn't like concatenation in fwrite(). Try this for the while() loop... [code]<?php // Loop through the results, writing to the file while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){   $data = $row['col1'] . "\t\t\t" . $row['col2'] . "\n";   fwrite($fh, $data); } ?>[/code] Regards Huggie
  3. Something like this should work... [code]<?php // Select info from database $sql = "SELECT col1, col2 FROM table WHERE col3 = 'condition'"; $result = mysql_query($sql); // Open the file for writing $fh = fopen('/my/file/path/goes/here.tmp', "w"); // Create a header row in the file fwrite($fh, "Column 1\t\t\tColumn 2\n"); // Loop through the results, writing to the file while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){   fwrite($fh, $row['col1'] . "\t\t\t" . $row['col2'] . "\n"); } // Close the file fclose($fh); ?>[/code] Regards Huggie
  4. It does, but use fopen() before hand.  If you use fopen() with the file name as the first argument and "w" as the second argument then php will attempt to create the file if it doesn't exist. Regards Huggie
  5. No problem, don't forget to use the 'Solved' mod to mark the topic as solved. Regards Huggie
  6. I'd say the easiest way is to open a file and use fwrite() in a while loop over the results. Regards Huggie
  7. You can use ksort() to sort an array on it's keys. [code]<?php $foo = array('banana'=>'2', 'apple'=>'5', 'grape'=>'8'); ksort($foo); ?>[/code] Regards Huggie  ;)
  8. Lose the parenthesis... [code]<?php $ap_ss = $_POST['ap_ss1'] . $_POST['ap_ss2'] . $_POST['ap_ss3']; ?>[/code] Regards Huggie
  9. OK, I think I get it... Can you confirm the following for me. You display a form to the users that has a list of sources selected from the database, these are displayed as checkboxes on the page.  How do we know if it should be checked or not, is there a value for that in the database? Regards Huggie
  10. In that case you're data must be incorrect, the code should pull all members that have an 's' in their name so long as you put 's' into $search. Also, as a side note, I'm assuming that $search is coming from a form or URL parameter of some kind, if it is then you should really be using the global name for it, something like $_GET['search'] or $_POST['search'] as opposed to relying on 'Register Globals' being switched on. Check that your query returns the right result in phpMyAdmin before continuing. Regards Huggie
  11. I just knocked this up.  It's messy, but it will give you an idea of how it's done.  You'd be better using an XML data feed if possible though.  There's plenty of them out there. Regards Huggie [code]<?php // URL of currency data $url = "http://newsvote.bbc.co.uk/1/shared/fds/hi/business/market_data/currency/11/12/default.stm"; // Connect to the URL and pull the data down into a string $raw_data = file_get_contents($url); // Match the currency value preg_match('/South African Rand.*?right">([^<]+)/is', $raw_data, $matches); // Format to 2 decimal places $ex_rate = number_format($matches[1], 2, '.', ''); // Total GBP $p = "15.00"; // Echo some results echo "The product you selected is £" . $p . " GBP, That's approximately " . number_format($p * $ex_rate, 2) . " ZRA*<br><br>"; echo "* price based on a rounded exchange rate of " . $matches[1]; ?> [/code]
  12. OK, well then either the query, or the data is incorrect. The query I've given you will work even if you only put a single character in.  What happens when you run the query in phpMyAdmin?  Does it return three rows?  If it does, then maybe you can post all of your query code here? Regards Huggie
  13. Yes, [code]<?php // Loop through the results while($row = mysql_fetch_array($results2, MYSQL_ASSOC)){   echo $row['char_name'] . "(" . $row['char_id'] . ")"; } ?>[/code] Regards Huggie
  14. OK, this is actually quite simple.  First you have to decide: A) Where's the content going to come from e.g. text file, website html, xml request to aggregator etc. B) If you need to parse the value once it's returned. C) How you want to output it. I have a page that connects to Reuters website, gets a share price for a specific symbol, returns it to a script of mine and then tells me what my net share worth is, how many of each share I have, what I paid for them originally, and how much I've gained or lost on them. Regards Huggie
  15. You could probably do this with something like mod_rewrite on Apache. Regards Huggie
  16. Change your query to this: [code]$query2 = "SELECT char_name, char_id FROM accounts WHERE char_id LIKE '%$search%' OR char_name LIKE '%$search%'";[/code] Notice the percent (%) signs in there.  They're wild cards for multiple characters. Regards Huggie
  17. If they won't use a simple html form element, what makes you think they're going to be able to use anything else? If you're wanting drag and drop capability then you could possibly look at something like flash or dhtml, but php isn't the solution for you here.  Or if it is, then it's not a complete solution on its own. Regards Huggie
  18. The problem is that you're using [url=http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html]reserved words[/url] in your statement.  You can't use [b]to[/b] without quoting it with backticks (`), as it's a reserved word in MySQL... Try this: [code]<?php $ins = "INSERT INTO msg (`to`, `txt`, `type`) VALUES ($cid, '$newtxts', '1')"; ?>[/code] Regards Huggie
  19. Try it outside of the single quotes... [code=php:0]$query = "INSERT IGNORE subscribers(id,email,date_added) VALUES ('', SELECT email FROM subscribers_temp, now())";[/code] Regards Huggie
  20. As far as I'm aware, that sets it to bool(false); Regards Huggie
  21. You could try quoting the table names with back ticks (`) as [b]to[/b] is a [url=http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html]reserved word[/url]. :D [code]<?php $sql = "INSERT INTO messages (`to`, `subject`) VALUES ('$to', '$subject')"; mysql_query($sql) or die ("Unable to run $sql: " . mysql_error()); ?>[/code] Regards Huggie
  22. The short answer is that your authenticated browser session isn't captured in the script.  Maybe someone else can give you the technical details as to why, but I'm afraid I don't have the time.  I can however give you an example using the CURL library: [code]<?php /* * Initialise the CURL object and provide it the URL that we want to connect to * This is normally the page that a form is calling (so in your case, the page that * your login script is calling. */ $ch = curl_init('http://www.dizzie.co.uk/php/testform.php'); /* * Set the options, I'll comment each of these briefly as you can find out what * each means in detail on the curl_setopt() function page on php.net */ curl_setopt($ch, CURLOPT_HEADER, FALSE); // don't return the http header to me, I only want page contents curl_setopt($ch, CURLOPT_POST, TRUE); // I want to use the post method curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // I want the output returned as a string, not direct to browser curl_setopt($ch, CURLOPT_POSTFIELDS, "name=Richard&hello=Hello"); // Here's the post fields /* * This executes the curl object and assigns the returned page contents to the variable */ $output = curl_exec($ch); /* * Close the curl object */ curl_close($ch); /* * Output the returned data to the screen (Showing HTML) */ echo htmlentities($output); ?>[/code] OK, if you visit http://www.dizzie.co.uk/php/testform.php you'll find a simple form (this is the equivalent of your login form) and you can test it by typing in any name and then submitting the form.  You'll be taken to the same page that displays a greeting. Now try going to http://www.dizzie.co.uk/php/testcurl.php which is the exact script posted above.  You should get output to the screen, the exact source code of the above page. That's using CURL in it's simplest form to submit a form on another site. Regards Huggie
  23. The following code works, but 'everything' is being processed in PHP.  If you refined your query, you could reduce a lot of this processing. [code]<?php // Get the current 'timestamp' $today = strtotime('today'); // Array of test dates $dates = array('0601','1406','0809','1912'); // Get current year $yyyy = date("Y", $today); // Loop through putting the results in an array keyed on timestamp foreach($dates as $d){   $dd = substr($d, 0, 2); // get dd   $mm = substr($d, 2, 2); // get mm   $date = $yyyy.$mm.$dd; // join date with year   $ds = strtotime($date);   if ($ds < $today){ // if the date has past this year, then show next years       $nyyyy = $yyyy+1;       $date = $nyyyy.$mm.$dd;       $ts = strtotime($date);       $date_array[$ts] = $d; // put date into array   }   else { // if date hasn't past       $ts = strtotime($date);       $date_array[$ts] = $d; // put date into array   } } // Sort ascending ksort($date_array); // Dump the array to prove it works echo "<pre>\n"; print_r($date_array); echo "</pre>\n"; ?>[/code] In the above example, it takes the date that you've provided in DDMM format and returns the time stamp for that date (in the current year) if that date's passed, then it gets the timestamp for that date next year. It puts these values into an array keyed on time stamp and then orders them. Regards Huggie
  24. My advice would be to use strtotime() to get the 'seconds from the epoch' value for the particular day of the year and then order it by that. You'll need to include the current year in that code. Regards Huggie
  25. ok, here it is broken down.  I've only included the first half as once you have that the rest is self explanatory [table] [tr][td][color=red]/[/color][/td][td]Start the pattern sequence[/td][/tr] [tr][td][color=red]^[/color][/td][td]Match the start of the line[/td][/tr] [tr][td][color=red](\d{2})[/color][/td][td]Match 2 digits, enclosing inside the parenthesis says we want to capture that specific data into a variable[/td][/tr] [tr][td][color=red]-[/color][/td][td]Match a hyphen[/td][/tr] [tr][td][color=red](\d{2})[/color][/td][td]Match another 2 digits, again capturing them into a separate variable[/td][/tr] [tr][td][color=red]-[/color][/td][td]Match a hyphen[/td][/tr] [tr][td][color=red](\d{4})[/color][/td][td]Match the last 4 digits, again, put them into a separate variable[/td][/tr] [tr][td][color=red]/[/color][/td][td]End the pattern matching sequence[/td][/tr] [/table] Regards Huggie
×
×
  • 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.