Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

PHP Help needed
New on LowEndTalk? Please Register and read our Community Rules.

PHP Help needed

AlexBarakovAlexBarakov Member, Patron Provider
edited August 2012 in General

Hey guys,

So I haven't done any coding in PHP the last...7 years. So I need some help with something:
I need some loop that will go through every record in a table and perform the same action for a variable on each role. I will give a simple example of what I need to do:

I have a table with the following colums: ID, A, B, C .
ID is autofilled, A and B are some variables that are already in the DB. And C will be C=A+B .
So I need some kind of a cycle that will go through each line and fill the C column.

Hope this makes sence, I tried to explain it the best i could with a simple example. I can do this with ASP.NET, however I need to do it in PHP and I am in a dead end at the moment. This should eb something incredibly simple, however I can not manage to do it correctly.


  • You could just run the following query:

    UPDATE `table_name` SET `C` = (`A`+`B`);

    Of course, this will have to be run again every time A or B changes in any row. Ideally, if A and B are going to change often, then C really should be calculated when you're going to use it.

    SELECT (`A`+`B`) AS `C` FROM `table_name`
    Thanked by 1AlexBarakov
  • AlexBarakovAlexBarakov Member, Patron Provider

    Oh, I was just giving an example. I need some foreach (maybe) loop that will execute a specific script for each of the lines of the database, asigning different variables values from each role. I was just giving an example with A, B and C as it is easy to understand.

  • so.... something like this?

    $items = mysql_query('SELECT * FROM table');
    while ($item = mysql_fetch_assoc($items)) {
        exec('/path/to/your/script '.$item['col1'].' '.$item['col2']);
    Thanked by 1AlexBarakov
  • AlexBarakovAlexBarakov Member, Patron Provider

    Yup, that while cycle should do the trick. I will update this thread once I get this working or if I need some more help. Thanks Nick, it is apreciated :)

Sign In or Register to comment.