dcsimg
www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Running code from a button in PHP?

  1. #1
    Join Date
    Dec 2004
    Posts
    28

    Question Running code from a button in PHP?

    Hi Folks,

    I'm wondeing if someone can help.

    What I want to do is the following:

    I have a PHP report that shows all comments within an oracle database for a specified date

    what i want to do is hide records that have offensive material in them by giving the user the ability to tick a checkbox next to the record and click a button that will then update a field in the database called $visible to a 1 thus hiding it when the report is next generated.

    How would i go about linking the button to the code?

  2. #2
    Join Date
    Oct 2006
    Posts
    1,297
    That generally requires a FORM to be submitted (especialy for reliability -- in case JavaScript is disabled), however (speculating), a little JavaScript can do the trick with just an image (no checkbox required).

    <img src="hide.gif" onclick="this.src='hideid.php?id=<?=$id?>'; return false;">

    The PHP page shown could also serve up a change in the image to indicate success.
    A little more JavaScrpit code could also immediately hide the current table row.

  3. #3
    Join Date
    Dec 2004
    Posts
    28
    sorry if i sound a bit daft but in the onclick part do i reference the section of code that I would like to run in the $id section?

    Also am trying to figure out how to get php to do the following:

    $ticked_string = "";
    $unticked_string = "";

    rowcount = count of rows

    for x = 1 to rowcount

    if row(x).checkbox is ticked then
    $ticked_sting = $ticked_string & row(x).contact_id & ","
    else
    $unticked_sting = $unticked_string & row(x).contact_id & ","
    end if

    Loop

    $update1_string "update sms_out_audit set visible = 0 where contact_id in (" & $unticked_string & ");"
    $update2_string "update sms_out_audit set visible = 1 where contact_id in (" & $ticked_string & ");"

    Can you give me any ideas?

    Cheers!!

  4. #4
    Join Date
    Oct 2006
    Posts
    1,297
    In this:

    hideid.php?id=<?=$id?>

    The piece of code you wish to run would be in a document called "hideid.php" -- and, obviously, you can use any document name here you wish. The $id part would be an identifier which tells you which section of the report needs to be omitted next time.

  5. #5
    Join Date
    Dec 2006
    Posts
    110
    it doesn't need to be a button or a post, on each row create a link <a href="hideid.php?id=<?=$id?>">Hide</a> then in hideid.php update the row with the given id and redirect back to the report page

  6. #6
    Join Date
    Dec 2004
    Posts
    28
    not sure if i have explained myself properly as am still confused

    I have a report that outputs comments from an oracle database into a PHP page.

    What I want to do is put checkboxes/radio buttons beside each record that it outputs so if an abusive comment comes in I can click the checkbox/radio button next to it, click update and it will hide the record.

    To hide it all i need to do is be able to send the value 1 from my result set to a column called $visible in my database and for it then to post back to the same page.

    Is it possible?? Am going crazy trying to figure it out

  7. #7
    Join Date
    Oct 2006
    Posts
    1,297
    All methods previously described will do that. Take your pick.

  8. #8
    Join Date
    Dec 2004
    Posts
    28
    could you give me an idea what i should put in my hideid.php? have been working on this all day and have a total mind blank!

  9. #9
    Join Date
    Oct 2006
    Posts
    1,297
    Give an example of the database key for the information you wish to hide.

  10. #10
    Join Date
    Dec 2004
    Posts
    28
    I want to update the $visible column in my database called bblq.sms_out_audit sms with a 1 in order to hide the record

  11. #11
    Join Date
    Oct 2006
    Posts
    1,297
    What is the key to that database row?

  12. #12
    Join Date
    Dec 2004
    Posts
    28
    Cont_id is the db row i need to update

    I think i might need to do something like this???

    Update sms_out_audit
    set visible = 1 where cont_id = "" ??

  13. #13
    Join Date
    Oct 2006
    Posts
    1,297
    OK, now show the loop where you're reading the database table and writing the rows out to the client.

  14. #14
    Join Date
    Dec 2004
    Posts
    28
    Ok I have managed to get the code to work but in my hideid.php i cant see how to pull in the contactid? It has it in the address bar but how to i get my code to run so that it just updates the record specified?

  15. #15
    Join Date
    Dec 2006
    Posts
    110
    You need to use the Querystring variable, PHP isn't really my thing but a quick google gave me this page which seems to be what you're looking for http://vdhri.net/webHostingNews/2005...ng_in_php.html

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles