Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Yes but you need InnoDB check first your table uses InnoDB and not MyISAM. Syntax is like: field TYPE REFERENCES table (field) ON UPDATE CASCADE ON DELETE CASCADE More information can be found here: http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html If you provide me your db schema I'll re-write the code to match InnoDB Don't forget to export the data first (you'll need the insert into lines afterwards)
  2. You need curl there is no doubt about it Twitter's API is RESTful based meaning that you can get the information you want in the format you want (if available). $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://twitter.com/direct_messages.xml');//note the extension can be either xml, json, rss or atom curl_setopt($curl, CURLOPT_USERPWD, 'username:password'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $xml = curl_exec($curl);
  3. What do you mean by the $row key? $row['columnName'] or $row[0]?
  4. Check your source code they probably have added javascript which redirects you to that page.
  5. You could create one field of start_date and start_time of type DATETIME and the same for end_date, end_time afterwards you can perform a query like: SELECT * FROM table WHERE username = $username AND password = $password AND now() BETWEEN start AND end I'm currently looking for a function that can combine a date and time field as a datetime field. Edit: This should work using the start_date, start_time, end_date, end_time: SELECT * FROM table WHERE username = $username AND password = $password AND now() BETWEEN date_add(start_date, interval start_time HOUR_SECOND) AND date_add(end_date, interval end_time HOUR_SECOND)
  6. No but in order to provide a complete example I had to make up some tables so you would get a feel for the workflow of my code
  7. Can you post this script, thank you.
  8. From the manual: Thus strstr returns an empty string as there isn't anything left after .co.uk therefor use type comparison: if (false !== strstr($var1, $var2)) {
  9. You can use an array for that but you would have to use it in reverse order (date first) or you would only get the last week as this will be the last to overwrite Monday through Sunday thus: $days = array('1/1/09' => 'Monday', '2/1/09' => 'Tuesday', ..);
  10. You already know that, it's $searchDb. The query finds economy because you passed econom% where % matches any arbitrary number of characters meaning that it would also return economist if you wanted to limit your search to one character after econom you would use _ which would match economy but not economist the same applies for the preceding % more information about pattern matching can be found at http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html If you are familiar with regex you may find more information about the regex implementation in mysql at http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp
  11. Possibly you got this from a db and IMO it would then be better to handle this in your query: SELECT name, sum(amount) sum_amount FROM table GROUP BY name
  12. The schema would suffice I suppose unless my INSERT INTO doesn't work like I would like
  13. Well you did: $email = is_valid_email($_POST['email']); Which stores the result of your function into $email thus 1 (true) or 0 (false). ? and : are called ternary operator's and their operation is the same as if you wrote an if and an else like: if (is_valid_email($_POST['email'])) { $email = $_POST['email']; } else { $email = null; } Where I would write (and is the same as the above if/else statement): $email = null; if (is_valid_email($_POST['email'])) { $email = $_POST['email']; }
  14. $words = str_word_count('the dog jumps over the lazy sheep', 1); $sizeof = sizeof($words); for ($k = 0; $k < $sizeof; ++$k) {//specifies offset for ($i = $k; $i < $sizeof; ++$i) { for ($j = $k; $j <= $i; ++$j) { echo $words[$j]; } echo '<br>'; } } Outputs: the thedog thedogjumps thedogjumpsover thedogjumpsoverthe thedogjumpsoverthelazy thedogjumpsoverthelazysheep dog dogjumps dogjumpsover dogjumpsoverthe dogjumpsoverthelazy dogjumpsoverthelazysheep jumps jumpsover jumpsoverthe jumpsoverthelazy jumpsoverthelazysheep over overthe overthelazy overthelazysheep the thelazy thelazysheep lazy lazysheep sheep
  15. Not entirely sure but I think this may work: $maxWidth = 800; $maxHeight = 600; list($width, $height) = getimagesize('path/to/image'); $ratio = 1; if ($maxWidth < $width) { $ratio = $maxWidth / $width; } else if ($maxHeight < $height) { $ratio = $maxHeight / $height; } $newWidth = $width * $ratio; $newHeight = $height * $ratio;
  16. $email = is_valid_email($_POST['email']) ? $_POST['email'] : null; PS eregi is deprecated consider using preg_match
  17. Don't know I was just asking what he meant with similarities.
  18. Well using the array_intersect and explode will give you the words both strings have in common. But maybe the OP wants the substrings both strings have in common and want to do something else if it isn't: "Does the dog jump over the lazy sheep or the spotted cow?" "The lazy dog jumps over the sheep." "over the lazy sheep" is only present in the first sentence and not in the second.
  19. This is more a CSS thing then a PHP thing: <body id="page1"> #page1 { background-color: #FF22FF } #page1 .someClass { background-color: #22FFFF } #page2 { background-color: #FFFF22 } #page2 .someClass { background-color: #2F2F2F } The menu itself: #homepage { background-color: #F2F2F2 } #contact { background-color: #F22FF2 } ..
  20. Can also be written as (and may depending on the PHP implementation even be better): $first_components = str_word_count($first_sentence, 1); $second_components = str_word_count($second_sentence, 1);
  21. What do you exactly mean by similarities? Just if one string contains a word another string has in common?
  22. I don't know how your code works nor how your database looks like except for the time table and one field from employee so this is only what I can suggest at the moment: INSERT INTO txn SELECT time.id, time.hours * employee.rate FROM time JOIN employee ON time.employee_id = employee.id
  23. echo '<h2>Departments</h2>'; $query = 'SELECT * FROM departments'; $result = mysql_query($query); if ($result && mysql_num_rows($result)) {// make sure query succeeded and it contains atleast one row echo '<select name="departements">'; $department = abs(!empty($_POST['departments']) ? (int) $_POST['departments'] : 0); while ($row = mysql_fetch_assoc($result)) { echo '<option value="', $row['departments_id'], '"', $department === $row['departments_id'] ? ' selected="selected"' : '', '>', $row['departments_title'], '</option>'; } echo '</select>'; if ($department) {// a department was selected echo '<h2>Courses</h2>'; $query = 'SELECT * FROM courses JOIN courses_departments ON courses_id = courses_departments_courses_id WHERE courses_departments_departments_id = %d'; $fquery = sprintf($query, $department); $result = mysql_query($fquery); if ($result && mysql_num_rows($result)) { echo '<select name="courses">'; $course = abs(!empty($_POST['courses']) ? (int) $_POST['courses'] : 0); while ($row = mysql_fetch_assoc($result)) { echo '<option value="', $row['courses_id'], '"', $course === $row['courses_id'] ? ' selected="selected"' : '', '>', $row['courses_title'], '</option>'; } echo '</select>'; if ($course) {// a course was selected echo '<h2>Sections</h2>'; $query = 'SELECT * FROM sections JOIN courses_sections ON sections_id = courses_sections_sections_id WHERE courses_sections_courses_id = %d'; $fquery = sprintf($query, $course); $result = mysql_query($fquery); if ($result && mysql_num_rows($result)) { echo '<select name="sections">'; $section = abs(!empty($_POST['sections']) ? (int) $_POST['sections'] : 0); while ($row = mysql_fetch_assoc($result)) { echo '<option value="', $row['sections_id'], '"', $course === $row['sections_id'] ? ' selected="selected"' : '', '>', $row['sections_title'], '</option>'; } echo '</select>'; if ($section) {// a section was selected // send the user to the new page and provide the section id // in section-info.php: // SELECT * FROM sections WHERE sections_id = %d header('Location: section-info.php?id=' . $section); } } } else { echo '<h2>Sections</h2>', '<select name="sections" disabled="disabled"></select>'; } } } else {// no department was yet selected therefor both courses and sections are disabled echo '<h2>Courses</h2>', '<select name="courses" disabled="disabled"></select>', '<h2>Sections</h2>', '<select name="sections" disabled="disabled"></select>'; } }
  24. Assuming a table structure like: CREATE TABLE users ( users_id INTEGER NOT NULL AUTO_INCREMENT, users_last_click_at DATETIME, PRIMARY KEY (users_id) ); Your update code would be: if (isset($_SESSION['users_id'])) { $id = abs((int) $_SESSION['users_id']);//set at login if (!$id) // do something: $id was 0 $query = 'UPDATE users SET users_last_click_at = now() WHERE users_id = %d'; $fquery = sprintf($query, $id); mysql_query($fquery/*, $db*/); } Your members online: $query = 'SELECT count(*) users_online FROM users WHERE users_last_click_at BETWEEN now() - 300 AND now()'; if ($result = mysql_query($query/*, $db*/)) { list($users_online) = mysql_fetch_row($result); }
×
×
  • 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.