Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Posts posted by benanamen

  1. @scootstah, Excellent starting point.

     

     

    @rashidpathiyil, Stop crying   :happy-04: and go through that tutorial as well as the one for HTML & CSS https://www.codecademy.com/tracks/web How to make a website https://www.codecademy.com/skills/make-a-website and when your down on all that,  the SQL tutorial https://www.codecademy.com/courses/learn-sql

     

    After you understand all that, your likely to come back providing answers for people rather than asking for answers. Code on my brutha!

  2. First things first. You are using obsolete Mysql code that will not work at all in the current version of Php. You need to use PDO with parameterized queries.

     

    Second, the whole thing can be done in ONE sql statement.

     

    Third, your active and exempt columns should be tinyint with a lenth of 1 and use the values 1  or 0 for yes/no

     

    Fourth, why are you re-selecting your database. 

  3. Typos is but a minute issue but is worth mentioning.

     

     

     

    not worried about accidentally mixing up the order of parameters? It would be a very easy thing to do with more complicated queries.

     

    Actually, on longer queries I have done exactly that so you got me there. Working on my own stuff easy enough with question marks. Other peoples stuff the named parameters would definitely be the better option. I guess I have been lucky, I rarely work on someone else's application. All my projects are ground up builds.  Even if they have an existing app, it ALWAYS has mysql_* and other bad code and is faster and cheaper to start from scratch.

  4. That is a whole mess of echoing and escaping. Here ya go...

     

    Option One

    echo <<<EOT
    <tr valign='top'>
       <td width='45%'><b>
          House District: </b><font color='red'>{$row['district']}</font><br>
          {row['first_name']} {$row['last_name']}<br>
          {row['address']}<br>
          {row['csz']}
       </td>
       <td width='55%'>
          <b>County(ies): </b><font color='red'>{$row['county']}</font><br>
          Capitol Phone: <font color='green'>{$row['cap_phone']}</font><br>
          Office Phone: <font color='green'>{$row['bus_phone']}</font><br>
          Home Phone: <font color='green'>{$row['home_phone']}</font><br>
          Email: <a href='mailto:{$row['email']}'>{$row['email']}</a>
       </td>
    </tr>
    EOT;
    

    Option Two

    <?php while ($row = $result->fetch_array(MYSQLI_ASSOC)): ?>
    <tr valign='top'>
       <td width='45%'>
          <b>House District: </b>
          <font color='red'><?= $row['district'] ?></font><br>
          <?= $row['first_name'] ?> <?= $row['last_name'] ?><br>
          <?= $row['address'] ?><br>
          <?= $row['csz'] ?>
       </td>
       <td width='55%'>
          <b>County(ies): </b><font color='red'><?= $row['county'] ?></font><br>
          Capitol Phone: <font color='green'><?= $row['cap_phone'] ?></font><br>
          Office Phone: <font color='green'><?= $row['bus_phone'] ?></font><br>
          Home Phone: <font color='green'><?= $row['home_phone'] ?></font><br>
          Email: <a href='mailto:$row['email']'><?= $row['email'] ?></a>
       </td>
    </tr>
    <?php endwhile;?>
    
  5. To answer your question, the first example by far. The values of the second example is just throwing a bunch of duplicate data at me. All I need to know is that in the first example, their needs to be the same amount of question marks. There is no need to "read" question marks, only count them.

     

    It is also, 112 characters vs 170 characters. Times that over an entire application and that is a whole lot of extra typing. Also, your not likely to misspell a question mark.

  6.  

     

    I recommend you use named parameters in PDO instead of ?'s. Once you have a bunch of parameters it's a huge pain to keep track of the order of them and such.

     

     

    Could you elaborate on that please. I use question marks and have no problems whatsoever regardless of how much data is being inserted. Either way, you still have to know the order and if your POST data names/variablenames are the same as the DB columns it is clear what your dealing with. And if there are 20 pieces of data going in, you just count 20 question marks. Mysql is more than happy to tell you if your question mark count is off. Named parameters is just more typing which means more prone to typos. I also never create extra variables out of the post data as I see many doing, the OP included. It is just not necessary whatsoever. Nevertheless, this one really comes down to the coders preference IMO, they are both the right way to do it.

     

    I am just happy our brother @jiros1 is not using Mysql_*. :happy-04:

     

    EDIT* Uh, my response more geared to doing insert. OP is doing an update. Still not a problem ever for me.

  7. The problem with your code for starters as a you're using obsolete code that will not work in the latest version of PHP. You need to use PDO or mysqli. The second problem is you're creating your own problem. Just echo out the full string you want without creating all those variables with the commas. That sure doesn't look like javaScript.

×
×
  • 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.