Jump to content

Pawn

Members
  • Posts

    126
  • Joined

  • Last visited

    Never

Everything posted by Pawn

  1. I've written an extremely minimal landing page that animates the position of text links within a paragraph to form a simple navigation bar. You can see it at brickmedialab.com. Unfortunately, for everyone not running Firefox that page will look horrible. Because of my inexperience with jQuery, I absolutely positioned my text links so they could be easily moved with a click(). Because browsers render text so differently, this results in some very broken text positioning in anything but Firefox. Further, text-size is animated as part of the transition, which again looks great in FF, but terrible in WebKit browsers and (I assume) IE. Here's what's going on at the moment: $(function() { $('a').attr('onclick', 'return false').attr('href', '#'); $('a').click(function() { var go = $(this).attr('id'); $(this).css('color', '#404040'); $(this).blur(); $('p, h1').fadeTo(1200, '0', function() { $('#work').animate({ bottom: '540px', left: '0px', fontSize: '1.5em', fontStyle: 'normal' }, 1400); $('#about').animate({ bottom: '540px', left: '20px', fontSize: '1.5em', fontStyle: 'normal' }, 1400); $('#hello').animate({ bottom: '540px', left: '40px', fontSize: '1.5em', fontStyle: 'normal' }, 1400, function() { window.location = go; }); $('h1').fadeTo('slow', '0', function() { }) }); }); }); I'd really appreciate any thoughts on resolving these issues. When it comes to Javascript, I'm totally at sea.
  2. Thanks! Close, but no cigar. There's a test page here if it's any use.
  3. The goal is to interpret user search submissions like the following in an intelligent way. "oscar wilde 1903-1910 £4-10" Ideally after pattern matching such a query the script would have variables like $price_min, $price_max, $year_min, $year_max and $query_clean to work with. With these we could construct really useful SQL. All I've got for my efforts over the last couple of hours has been a headache. Can anyone help? Pseudo-code: $q = $_GET['query'] $price_range_expr = some_regex $year_range_expr = some_more_regex if $price_range = match all $price_range_expr in $q $q = strip $price_range from $q $price_min = $price_range[1] $price_max = $price_range[2] endif if $year_range = match all $year_range_expr in $q $q = strip $year_range from $q $price_min = $year_range[1] $price_max = $year_range[2] endif
  4. You are missing a semi colon after return $rss_datal.
  5. Then your form action is setting the querystring. Use <form action="<?=$_SERVER['REQUEST_URL']?>"> or similar. The querystring won't persist unless it's actually embedded in links.
  6. By refreshing the page, do you mean by pressing refresh, or following a link on the page to itself? Do you need the value of the $_GET variable to still be accessible? Why do you actually want to do this?
  7. Aways check the result of mysql_query. The more verbose your error handling, the easier you will find it to debug your code. $sql = "SELECT col FROM tbl_name"; if(!$query = mysql_query($sql)) { echo "An error occured on line ".__LINE__.".<br />\n" . "MySQL said: ".mysql_error().".<br /><br />\n" . "Query: ".$sql; exit; } $num_rows = mysql_num_rows($query); if($num_rows == 0) { echo "No results were returned.<br /><br />\n" . "Query: ".$sql; }
  8. Sorry, my bad. $months = array(); while($row = mysql_fetch_row($result)) { $months[] = $row[0]; } print_r($months); Or what PFMaBiSmAd said.
  9. $months = array(); while($row = mysql_fetch_assoc($result)) { $months[] = $row[0]; } print_r($months);
  10. Pawn

    Logout

    Reset the cookie on every page load.
  11. if(isset($_POST['Submit'])) { $to = 'blabla@gmail.com'; $subject = 'Bericht ontvangen van'.$fromsubject.' Actie Pagina'; $body = ''; unset($_POST['Submit']); foreach($_POST as $key => $val) { $body .= ucfirst($key).": ".$val."\n"; } if(mail($to, $subject, $body)) { echo "Mail sent to ".$to." successfully."; } else { echo "Mail could not be sent."; } }
  12. <?php $sql = "SELECT qid,question,oc1 FROM tblquestions WHERE qid = 1"; if(!$query = mysql_query($sql)) { echo mysql_error(); exit; } $row = mysql_fetch_assoc($query); ?> <input type="hidden" name="oc1" value="<?=$row['oc1']?>" />
  13. Pawn

    Order By Subquery

    Bingo! Nicely done.
  14. That code generates a fatal parse error. Set your scripts to report errors during development! You're not closing the foreach loop. foreach($columns as $col){ if($_POST[$col] != ""){ $where.= "$col = '$_POST[$col]' AND "; } }
  15. Hiya. I have a statement similar to: SELECT * FROM posts WHERE post_id NOT IN('121 84 376 20 3 94 1'); I'd like the "excluded" posts to be returned at the end of the results set, rather than skipped. Pseudo code: SELECT excluded = IN('121 84 376 20 3 94 1') ? 1 : 0 ORDER BY excluded ASC Any pointers much appreciated.
  16. Easy enough, but I think you might need to work this one out on your own. The PHP manual tells you everything about rename() that you need to know, and by passing a $_GET variable in the same way as we did with the delete function you'll be able to tell the script which file to rename. Good luck.
  17. Try this: $dir = "files/engelsk/";$list = '';$info = '';if (!$handle = opendir($dir)) { echo "Could not open directory ".$dir; exit;}while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(isset($_GET['rm']) && $_GET['rm'] == $file) { if(unlink($dir.$file)) { // File removed $info = $dir.$file." was removed."; } else { // Failed to remove file $info = $dir.$file." could not be removed. Check your paths and permissions."; } continue; } $extension = end(explode('.', $file)); $filename_no_ext = substr($file, 0, -(strlen($extension) + 1)); $list .= '» <a href="/files/engelsk/'.$file.'">'.$filename_no_ext.'</a> - <i><a href="?rm='.$file.'">Delete file</a></i><br />'; }}closedir($handle);// Outputif(!empty($info)) { echo "<p>".$info."</p>\n";}if(!empty($list)) { echo $list;} else { echo "The directory is empty.";} Previously, the part that added the list item was held in an else statement that only executed if $_GET['rm'] was not set. We just needed to rearrange the logic a little and add a continue to prevent a file that has just been removed still showing up in the list.
  18. The extension bit? $extension = end(explode('.', $file)); explode() is making an array from the string, using a fullstop as the delimiter. So "foo.bar" would become Array("foo", "bar") end() selects the last value of that array, which in your case is the file extension. $arr = array("foo", "bar"); $foo= end($arr); // $foo = bar The last line uses substr() to remove the number of characters in the extension from the end of $file, plus one to accommodate for the "." $filename_no_ext = substr($file, 0, -(strlen($extension) + 1));
  19. We are passing a variable to the script via the querystring, which is the portion of the url after "?" (see this). Notice that the href has become <a href="?rm='.$file.'">Delete file</a> When that's clicked, we'll go to the same page, but this time setting "rm" to equal the value of $file. Then, when we go through our loop we can check to see if "rm" is set. if(isset($_GET['rm'])) If it is, then we want to know if its value exactly equals the value of the file we are currently iterating over. If it does if($_GET['rm'] == $file) We can unlink it. We check to see if unlink() is TRUE, because we know from checking unlink's return values that that indicates success. if(unlink($dir.$file)) { // File removed echo $dir.$file." was removed."; } else { // Failed to remove file echo $dir.$file." could not be removed. Check your paths and permissions."; }
  20. $dir = "files/engelsk/";if (!$handle = opendir($dir)) { echo "Could not open directory ".$dir; exit;}while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(isset($_GET['rm'])) { if($_GET['rm'] == $file) { if(unlink($dir.$file)) { // File removed echo $dir.$file." was removed."; } else { // Failed to remove file echo $dir.$file." could not be removed. Check your paths and permissions."; } } } else { $extension = end(explode('.', $file)); $filename_no_ext = substr($file, 0, -(strlen($extension) + 1)); $en .= '» <a href="/files/engelsk/'.$file.'">'.$filename_no_ext.'</a> - <i><a href="?rm='.$file.'">Delete file</a></i><br />'; } }}closedir($handle); Untested.
  21. All of the output is in the second while loop. You'll get as many copies of that HTML as rows returned in $resultb.
  22. Pawn

    PHP HELP

    $i = 0; $fp = TRUE; while($i <= $_GET['goals']) { if($fp) { $fp = FALSE; echo $_REQUEST['scorer']."--<br />"; } else { $i++; if(isset($_REQUEST['scorer'.$i])) { echo $_REQUEST['scorer'.$i]."--<br />"; } } }
  23. This assumes you want to create a table row for each selected value. <?php if (isset($_POST['submit'])) { $dbc = mysqli_connect('localhost', '***', '***', '***') or die(mysqli_error()); unset($_POST['submit']); $num_fields = count($_POST); $i = 0; while($i <= $num_fields) { $i++; if(!empty($_POST['district_'.$i])) { $sql = "INSERT INTO tutor_preferred_dlocation (district_id) VALUES ('".$_POST['district_'.$i]."')"; if(!$query = mysql_query($sql)) { echo "Error on line ".__LINE__.". ".mysql_error(); exit; } echo "ID <b>".$_POST['district_'.$i]."</b> successfully inserted. <br />\n"; } } } else { ?> <input name="district_1" type="checkbox" id="yishun" value="1"> <label for="yishun">Yishun</label> <input name="district_2" type="checkbox" id="angMoKio" value="2"> <label for="angMoKio">Ang Mo Kio</label> <input name="district_3" type="checkbox" id="yioChuKang" value="3"> <label for="yioChuKang">Yio Chu Kang</label> <?php } ?> Untested.
  24. if($_SERVER['HTTP_REFERER'] == "loading.php") { // continue } else { header("Location: loading.php"); exit; }
×
×
  • 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.