View Full Version : PHP + MySQL Question? (String Types)

11-17-2011, 03:39 AM
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?

11-17-2011, 03:41 AM
You mean JOIN the tables?

11-17-2011, 05:22 AM
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?

11-17-2011, 11:14 AM
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.

11-17-2011, 11:41 PM
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?

11-18-2011, 08:42 AM
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.