【发布时间】:2016-10-24 20:50:02
【问题描述】:
由于某种原因,我被困在以下不会进入 while 循环的代码中:
<?php
// get All data from company and set into table
if(!isset($_SESSION)){
session_start();
}
?>
<?php
$user_id1="";
if (isset($_SESSION['user_id']))
{$user_id1=$_SESSION['user_id'];}
?>
<script type="text/javascript" language="javascript">
var $j = jQuery.noConflict();
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="js/plugins/jquery.spincrement.js"></script>
<div id="container" class="row">
<div class="col-sm-8">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Trending Stocks List</h3>
</div> </div>
<ul class="grid">
<?php
include 'db.php';
$json = "";
//$json=array();
$con=GetMyConnection();
// check for sell if not holding any stocks
$comp_sell_id=array();
$query_2="select distinct(comp_id) from tbl_buy_sell_share where (reedim_status!='y' or reedim_status is null) and user_id='$user_id1'";
$retval = mysql_query( $query_2, $con );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$i=0;
while($row = mysql_fetch_assoc($retval))
{
$comp_sell_id[$i]=$row['comp_id'];
$i++;
}
//$queryt="SELECT id_com_manual,current_price,image_path,fb,twitter,instagram,profile_id,(current_price - close_price) as profit FROM tbl_company_manual where status='1' and //profile_id!='' ORDER BY profit desc company_name asc limit 40";
$queryt="SELECT id_com_manual,company_name,min_price,max_price,close_price,image_path,market_cap,profile_id,current_price,fb,twitter,instagram,ABS(current_price - close_price) as profit FROM tbl_company_manual where status='1' and profile_id!='' ORDER BY profit DESC,company_name ASC limit 40";
// get the data from database
$retval = mysql_query( $queryt, $con );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$countrow=0;
while($row = mysql_fetch_assoc($retval))
{
$comp_id=$row['id_com_manual'];
$countrow++;
$actualprices = ($row['current_price']);
$pr = ($row['profit']);
$closeprice = ($row['close_price']);
$imagepath = ($row['image_path']);
$fb = ($row['fb']);
$twitter = ($row['twitter']);
$insta = ($row['instagram']);
retval 在我回显它时返回一个资源 ID,所以我知道数据库已连接并且正在向 fetch_assoc 函数发送一些值。我尝试用 fetch_array 替换该函数,但这也不起作用。此外,在使用 php 的“or die”功能时,我看不到任何错误。
我尝试将 retval 重命名为不同的变量,也使用 mysqli 无济于事。有什么想法吗?
【问题讨论】:
-
停止使用已弃用的
mysql_*API。将mysqli_*或PDO与准备好的语句一起使用 -
除了not using mysql_ functions,PHP 5.3 是EOL for nearly 2 years。是时候升级了。
-
开始使用mysqli。到目前为止没有问题。仍然不知道为什么上面的代码不起作用
-
这个问题你解决了吗? :)
-
不,我没有。我重新排列了代码并使用了 mysqli,因此它起作用了。不知道为什么上面的代码为什么上面的代码是错误的