Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Is this what you are trying to do? <?php $db = mysqli_connect(HOST, USERNAME, PASSWORD, DATABASE); // i'm using predefined constants if (isset($_GET['id']) && $_GET['id'] != '') { // // find selected user // $id = $_GET['id']; $userid = $name = $email = ''; $sql = "SELECT id, username, email FROM users WHERE id = ?"; $stmt = mysqli_prepare($db, $sql); mysqli_stmt_bind_param($stmt, 'i', $id); mysqli_execute($stmt); mysqli_bind_result($stmt, $userid, $name, $email); mysqli_fetch($stmt); $found = "ID: $userid<br>Name: $name<br>Email: $email<hr>"; mysqli_stmt_free_result($stmt); } /************************ * build dropdown of users *************************/ $sql = "SELECT id, username FROM users ORDER BY fullname"; $result = mysqli_query($db, $sql) or die($db->error); $dropdown = "<select name='id'>\n<option value=''> - select name -</option>\n"; while (list($id, $name) = mysqli_fetch_row($result)) { $dropdown .= "<option value='$id'> $name</option>\n"; } $dropdown .= "</select>\n"; ?> <html> <body> <?php echo $found; ?> <form method="get"> <h3>Users</h3> <?php echo $dropdown; ?> <br><br> <input type="submit" name="btnSubmit" value="Submit"> </form> </body> </html> As you are just learning stop using the mysql library and learn mysqli (improved). Next time you upgrade your php version you will find the mysql library is no longer there. In the above I have given an example of using prepared statements to prevent injection when using user inputs in your query (ie GET, POST, COOKIE data) and also a method just using mysqli_query().
  2. Just a thought. You will need to change the WHERE clause to restrict the search to the current month otherwise it's finding them for every month and not present in previous month. (Is that question 3?) WHERE my2.student_id IS NULL AND EXTRACT(YEAR_MONTH FROM my1.Lesson_Booking_Date) = EXTRACT(YEAR_MONTH FROM CURDATE())
  3. If that's what it needs. Your data and application. I did say "try something like this" to demonstrate the method. Why are you running all your queries on that bloated view?
  4. try $d = new DateTime(); // today by default $di = DateInterval::createFromDateString("next saturday"); $d->add($di); echo $d->format('Y-m-d'); // --> 2013-10-19 edit: nm. I just noticed this the is the MySQL forum tab in my browser and not PHP Help mysql> SELECT '2013-10-15' + INTERVAL 7 - DAYOFWEEK('2013-10-15') DAY as saturday; +------------+ | saturday | +------------+ | 2013-10-19 | +------------+
  5. You believe wrong. When you do a table join it joins data from one table to the matching rows in the other. With A INNER JOIN B only data from rows which match in both tables are returned. With A LEFT JOIN B all rows from A are returned with data from matching B rows where there is a match. If there is no match, data from the B table contains NULL values. Therefore those in my1 with no match in my2 contain NULL in the columns that come from the my2 table. As those are the ones we are looking for we have the WHERE clause. Your second query is the reverse of that one. Give the others a go based on what I have given you so far. I won't just spoonfeed all the answers to you
  6. Selecting too much data. Change first line of query to SELECT DISTINCT my1.student_id, my1.student_Firstname, my1.student_Lastname Probably better to this kind of query on the original tables rather than your include-everything view
  7. Instead of all the CONCAT of date items it's easier just to EXTRACT(YEAR_MONTH FROM my1.date - INTERVAL 1 MONTH) = EXTRACT(YEAR_MONTH FROM my2.date) so try something like SELECT DISTINCT my1.* FROM lessons_master_001 my1 LEFT JOIN lessons_master_001 my2 ON my1.student_id = my2.student_id AND EXTRACT(YEAR_MONTH FROM my1.date - INTERVAL 1 MONTH) = EXTRACT(YEAR_MONTH FROM my2.date) WHERE my2.student_id IS NULL
  8. if you started with this array you have a problem, even if you add 100 $array = array(1 => 'second', 3 => 'first', 2 => 'first', 4 => 'second');
  9. You can't. Array key values must be unique and you cannot guarantee that when you start adding them. You need to to rethink your array structure
  10. Or it may require the absolute path on the server $info_test_file = realpath("../php/info_test.txt") ; if (file_exists($info_test_file)) {
  11. This thread is in real danger of getting silly!
  12. mysql> SELECT * FROM test.exp_submissions -> WHERE entry_id IN (342,354,343,353); +----+----------+-----------+--------------+-------------+---------+------------------+ | id | entry_id | member_id | member_group | category_id | type_id | portfolio_number | +----+----------+-----------+--------------+-------------+---------+------------------+ | 30 | 342 | 1 | 5 | 2 | 2 | 0 | | 31 | 343 | 1 | 5 | 1 | 1 | 2 | | 35 | 353 | 1 | 5 | 1 | 1 | 2 | | 36 | 354 | 1 | 5 | 1 | 1 | 2 | +----+----------+-----------+--------------+-------------+---------+------------------+ But with the list in quotes mysql> SELECT * FROM test.exp_submissions -> WHERE entry_id IN ('342,354,343,353'); +----+----------+-----------+--------------+-------------+---------+------------------+ | id | entry_id | member_id | member_group | category_id | type_id | portfolio_number | +----+----------+-----------+--------------+-------------+---------+------------------+ | 30 | 342 | 1 | 5 | 2 | 2 | 0 | +----+----------+-----------+--------------+-------------+---------+------------------+ 1 row in set, 1 warning (0.00 sec) which is why the total is 1 instead of 4
  13. How about $body = $email_message;
  14. Normally you would use it to put characters in a string that are not readily available from a keyboard, eg echo "\xA9 Barand 2013"; //--> © Barand 2013
  15. Again, lose the quotes. WHERE sub.entry_id IN ($variable)
  16. Don't put the entry_id list in single quotes WHERE sub.entry_id IN (342,354,343,353) edit: '342,354,343,353' is a single string with a numeric value of 342 (ie as far as the first non-numeric character)
  17. Thanks for the images - they're real easy to load into a test database
  18. Can you attach a dump of those tables and tell us what your expected count should be?
  19. or instead of of writing to file you can write to STDOUT $fp = fopen('php://output', 'w'); // so you can fputcsv to STDOUT
  20. You can use a custom sort function function mysort($a,$b) { return strcmp($a['carrier'], $b['carrier']); } usort(myarray, 'mysort'); or you can just sort it normally sort(myarray); By default, a 2 dim array should sort on the arrays' first elements.
  21. There is no problem using COUNT() like that. What are you trying to count exactly? A left join selects all rows in exp_judging, not just matching rows. If you want to count matches only, use inner join
  22. I suspected that that were the case, which would make the object versions minimally more efficient than the procedural ones.
  23. Easy ways are mis-spell a column/table name or add an extra comma somewhere so the query fails.
  24. $users_pass = $_POST['pass']; $users_email = $_POST['email']; $check_users = "select * from users where users_pass='$password' AND users_email='$email'"; You also need to execute the query. All you have done is define a string value;
  25. If there are only then there will be just two urls in the array <?php $brokers = array ( 'www.broker1.co.uk', 'www.broker2.com' ); $numbrokers = count($brokers); $dayofyear = date('z'); $todaysURL = 'http://'.$brokers[$dayofyear%$numbrokers]; ?> <div id="iframe"><iframe id="iframeHome" src="<?php echo $todaysURL ?>" frameborder="0">Browser Not Compatible</iframe></div> If a third broker comes along, just add it to the array
×
×
  • 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.