Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. You are not running the query. Odd, since I would think you would get an error when trying to run mysql_fetch_row() on a string. Plus, the logic of reading the records is all wrong. Try this <?php $query = "SELECT section_title FROM section_main"; $result = mysql_query($query) or die(mysql_error()); $titleOptions = ''; while ($row = mysql_fetch_assoc($query)) { $titleOptions .= "<option value=\"{$row['section_title']}\">{$row['section_title']}</option>\n"; } ?> <form name="add_sub_section" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Sub Section Name <input type="text" name="sub_section_title" maxlength="200" /> <br /><br /> Sub Section desc <textarea name="sub_section_desc" rows="4" columns="30" /></textarea> <br /><br /> SECTION <select name="section_title"> <?php echo $titleOptions; ?> </select> <br/><br/> <input type="submit" name="submit" value="Add Section" /> </form>
  2. Hmm... here are some problems right off the top! if ($logUser= 1) else if ($logUser= 2) Need to use double equal signs for comparison. I also see that the variables used in most of your queries don't seem to be defined.
  3. Boy that helps, thanks a bunch man! It's all over the place because it's been edited 100 different times.. It may not be helpful in providing a "quick-fix" to your problem, but it does explain why you are having a difficult time in getting it to work. There are times when I think something is simple and just start writing code only to get myself boxed into corners and spend too much time debugging and find out that I have a logical error in the program flow and have to rewrite it. It is always a good idea to write out the logical flow of the code before you start coding. It takes a little more time up front but, ultimately, you will get done faster and have better, less buggy code in the end.
  4. If you have or die() after all of your queries then there is no error with the db queries. If you are certain that there are records in teh db for what you "expect" to be displayed, then the problem is likely that the queries are getting created incorrectly (but in a valid format). So the result of the query is that a valid record set is returned - but the record set is empty. An empty record set is NOT an error. You should add some debugging code to your page to echo the queries to the page along with a line that echos the count of the records returned from the query.
  5. That first block of code is invalid anyway. You can't use a header function after you have output other content to the browser (e.g. an echo statement). You would get errors if that code was run. I would assume that the condition for that code block is never true. I'm not sure what the intent of that code is. But, it wouldn't make sense to create a form then immediately redirect the user to another page. They would never have an opportunity to enter any data. Can you supply more code from the page in the correctr sequence and/or provide details on the expected flow of the script?
  6. Here is some example code based on what you posted: add_dates.php: (removed display portion and added redirect. You should also add validation. Previously it only checked if the values were set - which they always will be. Instead you should check if any are empty(). Plus you need to validate that the date is valid format) <?php require_once 'db.php'; $database = mysql_connect($dbhost, $dbuser, $dbpass); if (!$database) die("Unable to connect to mysql: " . mysql_error()); mysql_select_db($dbname); if (isset($_POST['date']) && isset($_POST['location']) && isset($_POST['time']) && isset($_POST['cost'])) { $date = trim($_POST['date']); $location = trim($_POST['location']); $time = trim($_POST['time']); $cost = trim($_POST['cost']); $query = "INSERT INTO tourdates (date, location, time, cost) VALUES ('{$date}', '{$location}', {'$time}', '{$cost}')"; $result = mysql_query($query, $database); } header ("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}/display_dates.php"); ?> display_dates.php (note, modified code to only need one query and process to create two outputs <?php //Create output for upcoming and past gigs $query = "SELECT date, location, time, cost, (date>=NOW, 1, 0) as future FROM tourdates ORDER BY futurepast DESC, date ASC"; $result = mysql_query($query); $futureOrPast = false; echo "<table border=\"1\" cellpadding=\"5\">\n"; while($row = mysql_fetch_array( $result )) { if($future!==$result['future']) { $future=$result['future']; $title = ($future==1) ? 'Upcoming Gigs:' : 'Past Gigs:' ; echo "<tr><th colspan=\"4\"><center><b>{$title}</b></center></th></tr>\n"; echo "<tr><th>Date</th><th>Location</th><th>Time</th><th>Cost</th></tr>\n"; } echo "<tr>\n"; echo " <td>{$row['date']}</td>\n"; echo " <td>{$row['location']}</td>\n"; echo " <td>{$row['time']}</td>\n"; echo " <td>{$row['cost']}</td>\n"; echo "</tr>\n"; } echo "</table>\n"; ?>
  7. There is an easy solution to this. It seems you have one page which checks if the user has submitted data and, if it has, inserts the new record. Then after it inserts the record (or if there is no record to insert) it then displays the records. You shoudl split up that logic. When a user submits a form to add a record it should point to the processign page that enters the new record. Then at the end of that script use a header() command to redirect to the display page. By using the header() function all POST data is destroyed. So, if the user refreshes the display page it will only refresh the display - it won't refresh (reexecute) the processing page.
  8. Even if you could "capture" a directory location through a form input, you couldn't use it to actually start a download to that directory. Once a download is initiated control goes to the users system and the Browser/OS settings take over from there. The only option I can think of would be to write a custom Java (not JavaScript) plug-in. Of course that would require the user to download and install that plug-in. Unless this is for an internal company solution where you could mandate something like that, the adoption rate of users who will install that plug-in will be low. Well, it *should* be low. I never install plug-ins unless I have 100% confidence in a site and even then I do some research to see if there is any information on the plug-in before I install it.
  9. If I am reading that correctly you would reference it thusly: echo $arrayName['mainframe']['requestTime']; //Output: 2010-08-31 23:19
  10. This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=308040.0
  11. Right, I did that on purpose knowing that Tara is thier most competent person. I deduced that the company would liek to end the year on a high note and start the year off running. jk. thanks for the catch.
  12. I've taken AlexWD's example and modified it to give you a list of the Weeks and Bug checkers for X number of weeks. I considered having it generate results for the entire year, but if you ever needed to add/remove a person the previous dates would not be correct. If you do ever remove/add a person just adjust the array positions as needed. The function takes 1 optional parameter for the number of week you want to see the assignments (starting from the current week). If the parameter is missing it only returns the current week's bug checker. The function returns an array with the first day of the week as the key and the staff person as the value. You can use it to output the day however you wish. function getBugCheckers($weeks=1) { //Array of staff $staff = array('Branda', 'Tara', 'Tom'); $bugCheckers = array(); //Get offset for monday of this week $offset = -1*(date('N')-1); for($week=0; $week<$weeks; $week++) { //Get total offset for the week iteration $startDayIdx = $offset + (7*$week); //Get timestamp for the Monday $startDayTS = strtotime("{$startDayIdx} day"); //Determine the responsible staff person $bugCheckers[date('F j, Y', $startDayTS)] = $staff[date('W', $startDayTS)%count($staff)]; } return $bugCheckers; } //Usage $responsibleStaff = getBugCheckers(7); print_r($responsibleStaff); Output: Array ( [August 23, 2010] => Tara [August 30, 2010] => Tom [september 6, 2010] => Branda [september 13, 2010] => Tara [september 20, 2010] => Tom [september 27, 2010] => Branda [October 4, 2010] => Tara )
  13. A bit simpler: $nameFull = strtolower($line['nameFirst']).strtolower($line['nameLast']); echo '<div><img src="/wp-content/gallery/head_shots/{$nameFull}.jpg"></div>';
  14. Seriously, all you need to do is convert a string to lower case? You really made this seem a much more difficult problem. Just use strtolower(). $fname = "Joe"; $lname = "Smith" $fullName = "{$lastName},{$firstName}"; echo $fullName; //Output: Smith,Joe echo strtolower($fullName); //Output: smith,joe
  15. Hmm, storing data in a database . . . what a novel idea! Yeah, here are always flat files, butif you have the ability to use a database you should absolutely go that route.
  16. I have no idea what Word Press is doing, but if some process is change capitals to lower case I highly doubt it has anything to do with the database. So, if the photo name is stored as "smithjoe.jpg" in the database you can query it using "SmithJoe.jpg" or "SMITHJOE.JPG" or any combination of upper/lowercase letters. However, if your problem is that you are querying the db and getting back "JoeSmith.jpg" and you are having a problem using that value to create an image tag, then just convert the values to lowercase using strtolower(). If neither of those is your problem, then I'm not understanding the problem. Have you TRIED changing the collation? Like I said, you can change it back if it doesn't work as expected. Edit: try a colation such as latin or utf8, the swedish one might be causing some of the problems.
  17. This isn't difficult at all. You just need to have an HTML page that is "designed" for printing. You have a few options. One solution is to have two different pages to present the data. One is used to display the "pretty" version that sits within the framework of the site graphics like all the other pages. The second is just for printing. So, you could have a button/link on the first page for "printable version" which will launch a new window of the second page without all the site graphics. Another solution is one that I almost never see used - which is a shame because it is really slick. Within the CSS framework there is a property to set the "media" for display properties. One use for this is to have the page display differently based upon whether it is displayed in a computer browser or a hand-held device. However, one of the supported "media" is the "print" device. using this property you can set different style properties for elements based upon whether they are in the browser or in the print device. What I have done in the past is set certain elements (header, navigation, footer, etc) to a display of "none" when the page is sent to the printer. So the user sees all the elements in the browser, but the printed page is not cluttered by those elements. Here is a sample page displaying how it is used. View the page in your bwser and you will see both lines of text. But if you go to Print Preview or actually print the page, the second line is not displayed. You can even do the reverse and have it print things that are not displayed in the page such as the date if it is a report. <html> <head> <style type="text/css"> /* media neutral styles go here */ @media print { .noprint { display: none; } } </style> </head> <body> <div>This will print</div> <div class="noprint">This will NOT print</div> </body> </html>
  18. It doesn't change the values. It gives MySQL a "Set of rules for comparing characters in a character set": http://www.sitebuddy.com/mssql_info/mysql_character_sets_and_collation_explained Do you have a need to do a query such as "WHERE name LIKE '%A%'" and ONLY find records where the name has a capital letter - excluding records with lower case letter "a"? If not, then change the collation to one that include the insensitive flag (i.e. the letter "i" at the end). You could always change the collation back if you find a problem. That what testing is for.
  19. After a second thought I think the first query can be simplified a bit by using UNION SELECT * FROM topics WHERE member_id IN (SELECT my_id as id FROM member_friends WHERE friend_id = '$user_id' UNION SELECT friend_id as id FROM member_friends WHERE my_id = '$user_id') None of these are tested, but should point you in the right direction if they don't work out of the box.
  20. The problem here is that the friend ID can be in the "my_id" column or the "friend_id" column depending upon who initiated the request. Regarding your query above, I see no reason to pull records from the "member_friends" since it doesn't look like you intend to use them. (I'd also suggest not using "a" and "b" as aliases. Aliases are supposed to make it easier for a human to interpret the code - use names that mean something. I see two soolutions. I'll let you do some testing to figure out which is more efficient. SELECT * FROM topics WHERE member_id IN (SELECT my_id FROM member_friends WHERE friend_id = '$user_id') OR member_id IN (SELECT friend_id FROM member_friends WHERE my_id = '$user_id') SELECT t.* FROM topics t JOIN member_friends mf1 ON mf1.my_id = t.member_id JOIN member_friends mf2 ON mf2.friend_id = t.member_id WHERE mf1.friend_id = '$user_id' OR mf2.my_id = '$user_id'
  21. You just need to change the "collation" for the first and last name fields in the database so queries are handled in a case-insensitive manner. The collations will sometimes end with an underscore and a letter or two. You need to use one that has an "i" at the end. For example: latin1_general_ci or utf8_general_ci FYI: I forget the term the "c" represents, it allows the queries to be run against accented characters. So, the letter "a" would match "à" or "ã".
  22. I don't see what sprintf() has anything to do with your problem. Just use mysql_insert_id() where you would you need the ID of the recently created record. The problem seems to be your queries. Example: $query = sprintf("INSERT INTO site_user_info (terms_and_conditions, name_on_card, credit_card_number) VALUES ('%s','%s','%s')", *mysql_real_escape_string($_SESSION['name']),* mysql_real_escape_string($_SESSION['terms_and_conditions']), mysql_real_escape_string($_POST['name_on_card']), mysql_real_escape_string($_POST['credit_card_number']), mysql_real_escape_string($_POST['credit_card_expiration_data']) ); The query is set to only insert three values, but you have five values! Ok, forgetting about the expiration date, I will assume that you want to insert the ID from the previously inserted record into the subscription table. You should NOT be using the "name" field to link records - you have to use an auto-incrementing ID field to use mysql_insert_id(). So, let's assume the sunscriptions table does have an auto-incrementing field called "subcription_id". The above query might look something like this $query = sprintf("INSERT INTO site_user_info (subscription_id, terms_and_conditions, name_on_card, credit_card_number) VALUES ('%s', '%s','%s','%s')", mysql_insert_id(), mysql_real_escape_string($_SESSION['terms_and_conditions']), mysql_real_escape_string($_POST['name_on_card']), mysql_real_escape_string($_POST['credit_card_number']), ); Remember, mysql_insert_id() will be the last inserted record for the currently running process.
  23. Here is the logic you need to use. It might not look right, but this will find any records where the from/to range in the record completely or partially overlaps the from/to range you are searching on: SELECT * FROM table WHERE salary_from <= $salary_to AND salary_to >= $salary_from
  24. OK, I think you are again having end of day confusion. The query is testing TWO separate, independant values. So, an OR does not mean all records will be returned. The "From" value can be above below some arbitrary value and that doesn't tell you if the To value will be above or below another arbitrary value. @An7hony: Why don't you exlain what you are trying to achieve. I suspect you are trying to find one of the two: 1. Records where the From and/or To values are within the range or 2. Records where the From / To values overlap the range (partially or entirely) There is a difference. If the search value are 10,000 and 15,000 a record with 5,000 and 20,000 would not start/end within the range, but it would overlap the range.
  25. Simple, you query states the "salary from" must be equal to or greater than 15001 (which 16000 is) AND that the "salary to" must be less than or equal to 20000 (which 22000 is NOT) Perhaps you want an OR statment - not sure since I don't know exactly what you are trying to find.
×
×
  • 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.