Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP + MySQL Question? (String Types)

    Hello, I am working on a web application and I was wondering if I have a table that consists of columns type and value, where both are varchars, and I was wondering if I could have a row with the data: sidinc, 0001
    Then can I write that number fetched from the varchar column to another table where that value would be written to a numeric column and vice versa?

    Another Question:
    If I have a column named SIDS and all data is stored like this: "0001:0003:0009", how do I remove lets say 0003 automatically so that it will convert to:
    "0001:0009", I'm guessing It will involve explode and implode, but I do not know how to do this, also is there a way I can perform a similar function but instead of removing, adding to it?
    Last edited by Wolf95; 11-17-2011 at 02:51 AM.

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts
    You mean JOIN the tables?
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, so for example:
    A query writes the following to Table (sysdata) with columns: type(varchar), data(varchar)
    inside of that table there is a row containing data lets say incrementport, 7358
    I need to read that data increment it, and save it to another table and update the existing table. However the part I see having issues is this:
    Will the type of output for (7538, varchar) cause a error for when I put the output from that query directly into another table?

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,286
    Thanks
    12
    Thanked 344 Times in 340 Posts
    you should definitely type cast the result before using it in the other table. but why using VARCHAR? if you intend to put it in a INTEGER field, why not using that to begin with? if you’re concerned about havig output with leading zeroes, this can be done via output formatting (PHP and SQL have sufficient possibilities for that). despite that there is also error handling in (My)SQL.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That column will be used to store miscellaneous data that doesn't fit nicely in any other table. So if I took the direct output and wrote that to a SQL database it would result in an error?

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,286
    Thanks
    12
    Thanked 344 Times in 340 Posts
    it depends whether you want to do it via PHP or directly in SQL. when using PHP you can make sure the aquired data does match the requirements of the other table.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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