我正在构建一个网站,本质上这个 PHP 算法要做的就是一次查看一个产品(MySQL 数据库中的行),并相应地执行一个过程。
我对此进行了大量研究,但找不到任何东西,任何帮助将不胜感激!
我的代码(当前没有为回显变量返回任何内容):
<?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;
?>
最佳答案
首先,有一天尝试一下 Jay Blanchard 提供的有关 PDO 和其他内容的建议。
其次,我已经尝试回答你的问题,并且我已经尝试解释你的完整意图。我在代码中添加了注释:
<?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
?>
关于PHP 和 MySQL 对数据库中的每一行执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35140456/