Jump to content

CamW

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Posts posted by CamW

  1. PHP can interpret data submitted through forms as arrays, so it's pretty easy to treat a series of checkboxes as one array.  You just need to add [] to the end of the element name.  If we assume you have the ids for all your rows when building your checkbox list, it's pretty easy to generate checkboxes that will pass an array of ids to be deleted on a submit.

    [code]$ids = getListOfIds();

    foreach($ids as $id) {
      echo "<input type=\"checkBox\" name=\"deleteItems[]\" value=\"$id\" /> Row id: $id<br />";
    }[/code]

    (You can also specify the key name within the brackets, but not specifying is handy here, because PHP will just automatically add the value of a form item to the next index in the array if it isn't specified)

    Once the user submits that form, you'll have the list of ids the user checked in either $_GET or $_POST, and you can delete accordingly.  Let's assume it's in $_POST.

    [code]foreach($_POST['deleteItems'] as $deleteItem) {
      executeSQL("DELETE FROM yourTable WHERE id = $deleteItem");
    }[/code]

    (Of course, executeSQL isn't a real command.  You'll need to execute that query using whatever method you use to talk to the database.)

    Hope that helps!

    -Cameron
  2. Hi all,

    I'm having a peculiar problem where PHP is occasionally returning incorrect results on a query.  I'm connecting to the db like so:

    [code]$conn =& ADONewConnection('odbc_mssql');
    $dsn = "Driver={SQL Server};Server=$server;Database=$db;";

    $conn->Connect($dsn, $dBUser, $dBPass);[/code]

    This works fine.  Then, I execute a sql statement like so:

    [code]$result = $conn->Execute($query);[/code]

    Again, this works fine, and these code snippets exist in a function that I've been using for months now, and I've had no problems with any other scripts accessing the database.  However, today I noticed some database results that looks suspicious, and upon further inspection, the query was indeed returing returning results inconsistent with the data in the database.  To debug, I threw in some echo commands to see what was going on:

    [code]echo $query . "<br />";
    $result = $conn->Execute($query);
    echo "<pre>";
    print_r($result->fields);
    echo "</pre>";[/code]

    One of the queries that was returning incorrect data was this:

    [code]SELECT COUNT(id) AS theCount FROM ccwilki2.tblAnswer WHERE answer = 'Natalie Poole' AND survey_id = 17 AND question_id = 31[/code]

    Upon executing this query, the print_r of the $result->fields array revealed that $conn->Execute had returned an incorrect number (0).  The really weird thing is, if I cut and paste this query directly into the SQL Server Management Studio and execute it, it gives the correct result (6)!  That is without changing the query a bit.  To me, it looks like the problem is coming from the $conn->Execute() function.  Is this a bug?  Have any of you encountered this problem before?

    The problem only occurs with a small minority of the queries, but the problem queries are always the same.  I am certain that the connection created in PHP points to the same database as SQL Server Management Studio was accessing when I checked the results.  The script username only has access to one mssql database, and I signed on to management studio with that username.

    Any help would be most appreciated!  This is making me go prematurely gray!  Thanks in advance.

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