Jump to content

Leaderboard

  1. Barand

    Barand

    Moderators


    • Points

      150

    • Content Count

      19,206


  2. requinix

    requinix

    Administrators


    • Points

      138

    • Content Count

      11,073


  3. mac_gyver

    mac_gyver

    Staff Alumni


    • Points

      32

    • Content Count

      4,285


  4. ginerjm

    ginerjm

    Members


    • Points

      31

    • Content Count

      4,619



Popular Content

Showing content with the highest reputation since 05/26/2018 in all areas

  1. 1 point
    Long question short reply: No, the argument does not need to be casted from int to string. PHP will do it automatically.
  2. 1 point
    In addition to @ginerjm's advice Separate your php from your html as much as possible, avaiding your spaghetti-like code structure. Do your php processing first, followed by the html output Don't use "select star", specify the fields you want. Don't put user privided data directly into your query strings, use prepared statements I have rewritten your page to illustrate these points <?php $tdata = ''; $where = []; $whereclause = ''; $params = []; $class = $_GET['class'] ?? ''; $sex = $_GET['sex'] ?? ''; if (isset($_GET['todo']) && $_GET['todo']=='search') { if ($class) { $where[] = "class = ?"; $params[] = $class; } if ($sex) { $where[] = "sex = ?"; $params[] = $sex; } if ($where) { $whereclause = " WHERE " . join(' AND ', $where); } } $stmt = $dbo->prepare("SELECT name , class , session_based , mark , sex , phone , date FROM student $whereclause"); $stmt->execute($params); foreach ($stmt as $row) { $tdata .= "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n"; } function classOptions($dbo, $current='') { $opts = ''; $res = $dbo->query("SELECT DISTINCT class FROM student"); foreach ($res as $r) { $sel = $r['class']==$current ? 'selected' : ''; $opts .= "<option $sel value='{$r['class']}'>{$r['class']}</option>\n"; } return $opts; } function sexOptions($dbo, $current='') { $opts = ''; $res = $dbo->query("SELECT DISTINCT sex FROM student"); foreach ($res as $r) { $sel = $r['sex']==$current ? 'selected' : ''; $opts .= "<option $sel value='{$r['sex']}'>{$r['sex']}</option>\n"; } return $opts; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)"> <title>Example</title> <meta name="author" content="Barand"> <meta name="creation-date" content="09/23/2018"> </head> <body> <form method='get' action=''> <input type="hidden" name="todo" value="search"> Class <select class="form-control" name="class"> <option value=''>Any Class</option> <?=classOptions($dbo, $class)?> </select> <br> Sex <select class="form-control" name="sex"> <option value=''>All</option> <?=sexOptions($dbo, $sex)?> </select> <br> <input type="submit" value="Search"> <input type="reset" value="Reset"> </form> <br><br> <div class="container"> <table class="table table-bordered table-hover table-striped"> <thead> <tr> <th class="col-md-1">Name</th> <th class="col-md-1">Class</th> <th class="col-md-1">Session Based</th> <th class="col-md-1">Mark</th> <th class="col-md-2">Sex</th> <th class="col-md-2">Phone</th> <th class="col-md-2">Date</th> </tr> </thead> <tbody> <?=$tdata?> </tbody> </table> </div> </body> </html>
  3. 1 point
    Your html code is terribly flawed. Awful!!! Attributes must be enclosed in quotes. Here is one example of a corrected line of html. You wrote: "<form method=post action=''>" Should be: "<form method='post' action=''>" You have lots of learning to do apparently.
  4. 1 point
    In order to process the $_POST items as arrays, their names need to be of the form "txtname[X]". Your javascript is giving them the form "txtnameX"
  5. 1 point
    On reflection, I concur with Gizmola on the url and double quotes issue (There is a possibilty that a url could contain an apostrophe). In which case echo "<p><a href=\"$url\">Link here</a></p>"; It still avoids concatenation, which as you have demonstrated, can be error prone.
  6. 1 point
    This comes close to your desired results, although our arithmetic differs SELECT t.scheduled_date , t.time_period , SUM(tt.task_time) as scheduled_time FROM tasks t INNER JOIN task_types tt ON t.task_type_id = tt.task_type_id INNER JOIN users u ON u.user_id = t.user_id INNER JOIN user_role_mappings urm ON urm.user_id = u.user_id INNER JOIN user_roles ur ON ur.user_role_id = urm.user_role_id AND ur.role = 'gas_service_engineer' INNER JOIN employee_working_days ewd ON ewd.user_id = u.user_id GROUP BY t.scheduled_date, t.time_period; +----------------+-------------+----------------+ | scheduled_date | time_period | scheduled_time | +----------------+-------------+----------------+ | 2018-08-21 | AM | 120 | | 2018-08-21 | PM | 120 | | 2018-09-24 | AM | 180 | +----------------+-------------+----------------+ This only shows two dates and not those with no time et scheduled. That assumption of "never" may come back to bite you one day.
  7. 1 point
    I'm not following. You first state that you are using a regular expression to remove all but numbers from the values. Then you state that you want a value such as "Tnex>=40" to return Null or empty (as opposed to "40"). So, I'm not sure what you really want returned. Then you state that when you try to add the logic to your query you are not getting the rows that don't match the criteria. But, the query you provided doesn't have any where clause. If you had, I might have a better understanding of what you are really wanting from above. Lastly, the most important question is WHY are you doing this? If that data is not valid, then you should fix the data instead of creating complex process to handle the bad data on the output. I would update all the values in the database to just the number (or empty if you prefer) and implement logic when saving new values to ensure only valid data is entered. Although I would NOT advise the approach you are wanting, one of these will do what I think you are wanting Return the value if it is only a number - else return an empty string SELECT Date, Tnex, Mode, IF(Snex*1 = 0, "", Snex) as Snex FROM datatb Return the value with all non-numeric characters removed SELECT Date, Tnex, Mode, REGEXP_REPLACE(Snex, '[^0-9]+', '') as Snex FROM datatb
  8. 1 point
    It doesn't have to be at the beginning of the php code, it just has to be before any output is sent to the browser.
  9. 1 point
    This section of the manual may be of interest https://dev.mysql.com/doc/refman/5.7/en/load-xml.html
  10. 0 points
    I hope you two will be very happy together 😀
This leaderboard is set to New York/GMT-04:00
  • Newsletter

    Want to keep up to date with all our latest news and information?

    Sign Up
×

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.