Jump to content

tgavin

Members
  • Posts

    176
  • Joined

  • Last visited

Everything posted by tgavin

  1. I have to run out for an appointment. I'll bbl in a couple of hours and try your code mrMarcus. Again, thanks for your help!
  2. I was screwing around with that earlier. I was also using while($row_episodes_count = mysql_fetch_array($sql_episodes_count)) { $episodes_array[] = $row_episodes_count; } both of which gave me a multidimensional array. I still couldn't figure out how to match pos with the ID
  3. mrMarkus, that's already being done in the pagination links. That's what pos is, the position within the array. My problem has been matching pos to the ID number in the array. What I'm trying to do is (using psudo code) // get the position number $pos = $_GET['pos']; // get the corresponding ID number in the array $id = $episodes_array[$pos]['id'] // query using the ID number $sql = mysql_query("SELECT * FROM movies WHERE id=$id"); I'm not trying to make this complicated. I apologize if it's confusing. It seems a simple matter of matching pos to the ID and then performing a query using the result.
  4. Nothing would make me happier than passing the previous or next ID in the URL, or using SESSION. That would make my life a lot easier. My last two days have been spent trying to find my position in the array. I just don't know how to do it. Trying to get the next or previous ID numbers hasn't worked for me. I wasn't passing the key in the get variable, I just realized that pos and the key were the same, so I was trying to us it as a place holder. How do I get the next and previous ID numbers so I can pass them in the URL? or at the lease just find my place in the array (using SESSION, or whatever)? Thanks for your help!
  5. $_GET['id'] is only passed on the first page. Using the next and prev links won't pass $id, however, they do pass pos, which is short for position and tells the script which position in the array to go to, &pos=0, &pos=1, etc. The problem I've been having for the past couple of days is that, every time I go to a new page, the array resets and I start from 0, which, in the array = 90976. So I've been trying to match $pos with the key. Using the array, if I'm on page 5, then &pos=4 and I want to find the ID number that has 4 as the key, which would be 90980. Then I could do a sql query using that ID number. Yes, it would be a LOT easier to pass &id= in the URL. I tried that using next() and received errors. I can't figure out how to get the next or previous IDs in the array, so I started doing it this way. At this point I'm completely wiped out and somewhat confused because I've been all over the place with this. I'm trying to keep it simple, but fear I'm making this overly complicated.
  6. Excellent! Thank you! I've been working on this for two days and am FINALLY making some progress thanks to array_search(). I've been trying current(), next(), and everything else. I'm trying to get the ID from the array. When the script is first called, the ID is retrieved via $_GET['id']. After that I need to search the array for the position I'm in ($_GET['pos'] is passed on every page) and the corresponding ID number. This is what I have so far. // get the ID of every episode in this series/season $query_episodes_count = "SELECT id FROM movies WHERE kind='TV Show' AND show_name='".$_GET['show']."' AND season='".$_GET['season']."' ORDER BY episode ASC"; $sql_episodes_count = mysql_query($query_episodes_count) or die(mysql_error()); // if episodes exist if(mysql_num_rows($sql_episodes_count) > 0) { // build an array of the ID numbers $episodes_array = array(); while($row_episodes_count = mysql_fetch_array($sql_episodes_count)) { array_push($episodes_array,$row_episodes_count['id']); } // get the position in the array (which episode are we browsing?) $pos = abs((int) $_GET['pos']); // get the current show ID number in the array $id = array_search($_GET['id'],$episodes_array); // if $_GET['id'] isn't available, how do I get the current show's ID number from the array? // get the current position ($pos) and then match it to an ID number in the array // get the show's data $query = "SELECT * FROM movies WHERE id=$id)"; $sql = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($sql); echo $row['title'].'<br />'; // pagination if($pos > 0) { // show prev link $pos_prev = '<div style="float:left; padding-right:10px;"><a href="pagtest.php?pos='; $pos_prev .= $pos-1; $pos_prev .= '">previous</a></div>'; } if($pos < count($episodes_array) - 1) { // show next link $pos_next = '<div style="float:left"><a href="pagtest.php?pos='; $pos_next .= $pos+1; $pos_next .= '">next</a></div>'; } echo $pos_prev; echo $pos_next; }
  7. Here's my array. Array ( [0] => 90976 [1] => 90977 [2] => 90978 [3] => 90979 [4] => 90980 [5] => 90981 [6] => 90982 [7] => 90983 [8] => 90984 [9] => 90985 [10] => 90986 [11] => 90987 [12] => 90988 ) I'm trying to do a pagination script for a results page, not a listing page. Like in a photo gallery script. I'm not browsing the thumbnails, I'm looking at the large image. I have the script working to the point that if you start at the beginning, you can page through to the end and back to the beginning, in order. The problem I have is, what if you start in the middle? I can't tell where I am in the array. How do I match the ID number to the position in the array?
  8. Let me retract that. I had a period instead of a comma between the first and second email It's working perfectly. Thanks!
  9. Thanks, but that doesn't work either. I posted 3 email addresses and var_dump(count($email)) = 2.
  10. I'm not getting the proper count. If I enter 3 email address in the form and click submit, the count is 3. Then, I fill out the form with one address and now the total count is 5 instead of 4. I'm sure it's because I'm setting $i=1, but if I don't, then a single address isn't counted. // update counter page function write_file($filename,$content) { // let's make sure the file exists and is writable first. if(is_writable($filename)) { // open the file in write mode so that we erase previous contents if(!$handle = fopen($filename, 'w')) { die("cannot open file: {$filename}"); } // write $status to our opened file. if(fwrite($handle, $content) === FALSE) { die("cannot write to file: {$filename}"); } // close the file fclose($handle); chmod($filename, 0644); } else { die('Could not write to the file located at: '.$filename); } } $emails = trim($_POST['email']); $email = explode(',' , $emails); $previous_count = file_get_contents('count.txt'); $i=1; foreach($email as $to) { $sent = mail($to,$subject,$message,$headers); $i++; } $new_count = $previous_count + $i; write_file('count.txt',$new_count);
  11. my bad. It was something else. I forgot that I had made this post or I would have mentioned it. Sorry.
  12. little problem. I noticed that numbers are disappearing. If I use shrek, then shrek2, the original shrek is overwritten.
  13. I noticed that bug too. After trial and error, scratching head, pulling hair I finally realized why my previous database records were being rewritten The solution I had wasn't very elegant. However, it did keep the title intact, sans the punctuation, and made everything lowercase. The problem I see in your fix is that if somebody was looking for 'up in smoke', they would be more apt to type 'cheech-and-chongs', not 'Cheech-Chong'. It's also easier to read in a search result, and to remember. Making it lowercase just simplifies everything. Plus, I *think* it's common practice too.
  14. Effigy, thank you! Brandon, thank you too. I was using this because I don't know what the hell I'm doing <?php function create_slug($str) { $str = str_replace("'", '', $str); $str = str_replace('&', 'and', $str); $str = str_replace('!', '', $str); $str = str_replace('?', '', $str); $str = str_replace('(', '', $str); $str = str_replace(')', '', $str); $str = str_replace('.', '', $str); $str = preg_replace('[^\w]+', '-', $str); return strtolower($str); } ?> Throw that in with mod rewrite and you have an SEO gold mine!
  15. And how! Perfect. That leaves it wide open to add anything else I may need. Thanks!
  16. I'm working on stripping all of the special characters, etc so that I have SEO friendly urls. I'm not getting the results I want. Starting with the title Cheech & Chong's Nice Dreams. I would like for it to be 'Cheech-and-Chongs-Nice-Dreams Nothing I've tried is working. <?php function create_slug($string) { return ereg_replace("[^A-Za-z0-9]", "-", $string); } $title = "Cheech & Chong's Nice Dreams"; $title_slug = create_slug($title); echo $title_slug; // or return return preg_replace('/\s/', '-', $str); // i've tried more $return = ereg_replace("[^A-Za-z0-9]", "-", $string); $return = preg_replace('/\s/', '-', $return); return str_replace('--', '-', $return); ?> ugh.
  17. nope. inserting "" didn't fix it. This is print_r with empty fields. Array ( [1] => [2] => [3] => )
  18. inserting "" may have fixed it. Still testing here's the print_r($_POST['title']); Array ( [1] => test one [2] => test two [3] => test 3 )
  19. Well, what has me scratching my head is that if the field is empty, $_POST shouldn't recognize it, right? <?php function escape($value) { // strip slashes if(get_magic_quotes_gpc()) { $value = stripslashes($value); $value = mysql_real_escape_string($value); } // quote if not integer if(!get_magic_quotes_gpc()) { if(!is_numeric($value) || $value[0] == '0') { $value = mysql_real_escape_string($value); } } return convert_smart_quotes($value); } function convert_smart_quotes($string) { $search = array( chr(145), chr(146), chr(147), chr(148), chr(151)); $replace = array( "'", "'", '"', '"', '-'); return str_replace($search, $replace, $string); } ?>
  20. I have a form with a set amount of fields. If a user doesn't fill in a field it should insert nothing. Currently the word Array is being inserted How do I prevent this from inserting Array into the database if the field is left blank? escape() is just a function to clean the code (mysql_real_escape_string(), etc.) ucsmart() just capitalizes words. <?php foreach($_POST['title'] as $i => $ctitle){ $title = ucsmart(strip_tags(stripslashes($_POST['title'][$i]))); $sql = mysql_query("INSERT INTO titles (id,num,title,added_uid) VALUES (".escape($newid).",{$i},'".escape($title)."','".escape($_SESSION['uid'])."')") or die(mysql_error()); } ?>
  21. thank you. still making the first letter after a " lowercase. Perhaps I'm running this through the functions incorrectly? $title = ucsmart(strip_tags(stripslashes($_POST['title'][$i])));
  22. I'm using these functions to capitalize words, but in a clever way. I didn't write this, but am hoping somebody could help me make a small modification. If one of these words begins a sentence, or is after a double quote at the beginning of a sentence, the word still goes lowercase. Example Entering To The Market would return to the Market. Should be To the Market Entering "To The Market" would return "to the Market". Should be "To the Market" <?php function lower_articles($str) { return preg_replace("/(?<=(?<!:|’s)\W)(A|An|And|At|For|In|Of|On|Or|The|To|With|Vs)(?=\W)/e",'strtolower("$1")',$str); } function ucsmart($str) { $str = preg_replace('/([^a-z\']|^)([a-z])/e', '"$1".strtoupper("$2")', strtolower($str)); return lower_articles($str); } ?>
  23. Oops. I still had the id number in the checkbox name's brackets. name="item[2]" thanks for everything!
  24. Thank you. Something's not working correctly though. If I print_r($items) I get Array ( [0] => [1] => 1 ) I haven't been able to get it to show the item id numbers in the array. It always stops at 1. Also, I think this may have show a flaw in my plan. I want to be able to take the two items and insert them into mysql. INSERT INTO (table) VALUES ($item[$i],$item[$i])
  25. I have a page with tens, or hundreds of products on it. The user can only pick 2. I'm trying to figure out a way to limit the amount of items posted to two. The code below doesn't work properly (at least, I don't think it does!), but should give an idea of what I'm looking for. <?php if(isset($_POST['submit'])) { $items = array(); foreach($_POST['item'] as $i=>$item){ $c=0; while($c <= 2) { $items[$i] = $_POST['item'][$i]; $c++; } } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="checkbox" name="item[1]" value="1" /> lamp<br /> <input type="checkbox" name="item[2]" value="2" /> chair<br /> <input type="checkbox" name="item[3]" value="3" /> foobar<br /> <input type="submit" name="submit" value="submit" /> </form>
×
×
  • 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.