PHP和MySQL对数据库中的每一行执行操作

I am building a site, and essentially what this PHP algorithm will do is look at a product (row in MySQL database) one at a time, and do a process accordingly.

I put a lot of research into this but couldn't find anything, any help would be greatly appreciated!

My Code (currently returning nothing for echo variables):

<?php
include_once 'dbconnect.php';


$query = "SELECT * FROM track"; 
$result = mysql_query($query);


while($row = mysql_fetch_array($result)){ 
    $pro_code = mysql_result(mysql_fetch_array(mysql_query('SELECT product_code FROM track')));
    $currency = mysql_fetch_array(mysql_query('SELECT currency FROM track'));
    $cc = mysql_fetch_array(mysql_query('SELECT cctld FROM track'));
    $initial_price = mysql_fetch_array(mysql_query('SELECT initial_price FROM track'));

    $url = 'test';
}

echo $pro_code;
echo $currency;
echo $initial_price;

?>

Why do you query the same table multiple times, your code should be written like this:

include_once 'dbconnect.php';


$query = "SELECT product_code, currency, cctld, initial_price FROM track"; 
$result = mysql_query($query);


while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
    echo $row['product_code'];
    echo $row['currency'];
    echo $row['cctld'];
    echo $row['initial_price'];
}

and please upgrade to mysqli or PDO

First of all, try the advice about PDO and stuff from Jay Blanchard some day.

Secondly I've tried to answer your question anyway and I've tried to interpret your complete intention. I put comments in the code:

    <?php
    include_once 'dbconnect.php';

    $query = "SELECT * FROM track"; 
    $result = mysql_query($query);

    while($row = mysql_fetch_array($result)){ 

        //You need to read the row variable as an array
        $pro_code       = $row['product_code'];
        $currency       = $row['currency'];
        $cc             = $row['cctld'];
        $initial_price  = $row['initial_price'];

        //$url is not used.. I asume a test to get the external source ;-)
        $url = 'test';

        if ($url == $cc) {
            //if you want to print every row, you must echo inside the while loop
            echo $pro_code;
            echo $currency;
            echo $initial_price;    
        } elseif ($url == 'test') {
            //do something else here
        } else {
            //do something for all the other cases here
        }//end if

    }//end while
    ?>