Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Are you referring to the square brackets like are shown here? array explode ( string $delimiter , string $string [, int $limit ] ) If so, it's just the way that it is shown that a parameter is optional.
  2. What do you think? Take a look at what your current code appears to do and then take a look at what the code i provided appears to do.
  3. Im not great with OOP either, but its just that you need to create an instance of an object if you want to use it's attributes/methods.
  4. You need to instantiate the class first: $rez = new lastRSS; $rez=$rez->Get($target_url); Next time, please use tags around your code.
  5. No. AJAX is javascript. Asynchronous Javascript And XML. You can use whatever server language you wish. If you google, im sure you'll find plenty of auto-suggest tutorials.
  6. $sql = mysql_query("SELECT COUNT(*)+1 as rank FROM example WHERE score > ".mysql_real_escape_string($_GET['score'])) or die(mysql_error()); $rank = mysql_result($sql,0); echo 'Your rank:# '.$rank;
  7. The error is caused because you cannot change headers once something has been sent to the browser. See this sticky In short, you need to make sure nothing at all, including whitespace, is sent to the browser prior to use setting a cookie/changing location etc. Can't do much more than that without seeing your code.
  8. 1.) You dont need the ! sign. That makes the statement read the opposite to what you want. 2.) Unless you extracted $country_id from the URL previously, then that is unset. 3.) You can do it all with one if statement: if(isset($_GET['country_id']) && $_GET['country_id'] == 2){ echo $europe_austria_txt; } Also, if you enclose your string in double quotes, then you can use \n to make a new line, rather than spreading it across multiple lines: $europe_austria_txt="\n<br />Here will be some great text about the wonderful place they call Austria<br />\n";
  9. For a rough estimate of distance and to find the closest match to a given post code, you should be able to do: SELECT SQRT(pow(longitude-(SELECT longitude FROM yourtable WHERE postcode='XXXX XXX'),2)+pow(latitude-(SELECT latitude FROM yourtable WHERE postcode='XXXX XXX'),2)) as distance FROM yourtable ORDER BY distance DESC LIMIT 1 For more accurate results, see here for the required formulae.
  10. The manual is always the best way to answer questions like that. If you didn't know, its set up so that you can browse easily to the function page by sticking it after the url, like: http://www.php.net/array_slice
  11. Ok, then the only other thing i would mention is that despite this: if(isset($_POST['upload')) Being commonly used to check for a form's submission, it is actually problematic. The reason? Rubbish web browsers (a.k.a. IE) dont actually set the submit button unless it is actually clicked. That is, if someone is filling out your form and hits enter to submit, IE wont post the value of the submit button, so it appears the form hasn't been submitted. A better way is to do: if(count($_POST) > 0) This ensures the $_POST array contains something. There is no requirement to previously check if $_POST has been set; it's a superglobal -- it is always set, even if it's empty.
  12. Google is your friend. In summary, if you're using a windows machine with office instance, you can use COM: http://web.informbank.com/articles/technology/php-office-documents.htm And if you're not, you'll have to create the document in an alternative format that can be read by word. Either something like an rtf, or you can create an HTML file and serve it as a .doc. Or just use pdfs. Probably easier.
  13. Would be easier to store it in a database. It is, afterall, what databases are designed to be used for. Though a simple read of a text file is not difficult, things get harder when you wish to modify a school's name or delete it. Or the requirements could change, and you may wish to store added information about each school. A database is a more 'future proof' solution.
  14. Probably have to read it into a sting, strip the HTML tags, explode by the new lines, then remove empty elements: <?php $file = file_get_contents('file.txt'); $file = strip_tags($file); $lines = explode("\n",$file); foreach($lines as $k=>$v){ $v = trim($v); if(empty($v)){ unset($lines[$k]); } } echo '<pre>'.print_r($lines,1).'<pre>'; ?> Actually, it would be easier to trim out the unnecessary white space first: <?php $file = file_get_contents('file.txt'); $file = trim(strip_tags($file)); $lines = explode("\n",$file); echo '<pre>'.print_r($lines,1).'<pre>'; ?>
  15. You dont do any validation of the file. What happens if the file doesn't contain what you expect? Malicious code for example?
  16. file() opens a file and creates an array who's elements are the lines of that file: $file = file('schools.txt'); echo '<pre>'.print_r($file,1).'</pre>';
  17. strtoupper is your friend: echo strtoupper(date('M-d-Y'));
  18. I also do not see any loop -- you must have your for loop inside your form tags, otherwise you'll be recreating the form lots of times.
  19. Well, for starters, how about adding something which tells you if the upload failed? function uploadImage($inputName, $uploadDir) { $image = $_FILES[$inputName]; $imagePath = ''; $thumbnailPath = ''; // if a file is given if (trim($image['tmp_name']) != '') { $ext = substr(strrchr($image['name'], "."), 1); // generate a random new file name to avoid name conflict // then save the image under the new file name $imagePath = md5(rand() * time()) . ".$ext"; $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath); if ($result) { // create thumbnail $thumbnailPath = md5(rand() * time()) . ".$ext"; $result = createThumbnail($uploadDir . $imagePath, $uploadDir . 'thumbnail/' . $thumbnailPath, THUMBNAIL_WIDTH); // create thumbnail failed, delete the image if (!$result) { unlink($uploadDir . $imagePath); $imagePath = $thumbnailPath = ''; echo 'Thumbnail could not be created<br />'; } else { $thumbnailPath = $result; } } else { // the image cannot be uploaded $imagePath = $thumbnailPath = ''; echo 'Image could not be created<br />'; } } return array('image' => $imagePath, 'thumbnail' => $thumbnailPath); }
  20. Well i see you fixed, so good stuff. However, i'd already typed this out so ill post anyway as there are a couple of points you might want to think about. 1.) Always debug your queries with mysql_error if you're having troubles. 2.) You dont need to execute a separate query to delete each item. implode the ids and use the IN clause: $del_ids = implode(',',$_POST['checkbox']); mysql_query("DELETE FROM `post_box` WHERE id IN ($del_ids)") or die(mysql_error()); 3.) Do you ever extract the variables from the $_POST array? Or are you relying on register_globals? 4.) Looks like the error is one of script logic. You output the checkboxes, then delete those which were previously selected. End result: the checkboxes are deleted, but you dont notice till you refresh the page.
  21. Yes -- assuming there is one for each of the names too. Why not give it a try and see if you break it?
  22. Try: <?php $cities = array('seattle','pheonix','new york');//array of cities //assuming $payscale is the variable containing the state name: echo '<select name="payscale">'; foreach($cities as $v){ $selected = ''; if($v == $payscale){ $selected = ' selected="selected" '; } echo '<option value="'.$v.'"'.$selected,'>'.$v.'</option>'; } echo '</select>'; ?>
  23. How about showing us the code you have? It'll be a simple case of adding selected="selected" to the relevant option through the use of an if statement, but if we knew the context we could help more.
×
×
  • 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.