由于某些原因,以下代码无法进入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,因此我知道db是连接的,并且正在向fetch_assoc函数发送一些值。我尝试过用fetch_array替换函数,但这也不起作用。此外,在使用php的'or die‘函数时,我看不到任何错误。
我尝试将retval重命名为不同的变量,并且使用mysqli也没有效果。有什么想法吗?
发布于 2016-07-19 10:46:59
所以你有这个:
while($row = mysql_fetch_assoc($retval))是否输入循环与JavaScript、jQuery、代码编译或PHP版本完全无关。同时循环的工作方式如下:
时间(费用)陈述 while语句的含义很简单。它告诉执行嵌套语句反复,只要表达式的计算结果为表达式的值每次在循环开始时被检查,所以即使在嵌套语句的执行过程中这个值发生了变化,执行也不会在迭代结束之前停止(每次PHP在循环中运行语句是一个迭代)。有时,如果while表达式从一开始就计算为
FALSE,那么嵌套语句甚至不会在运行一次。
因为你的expr是助理署长()
返回值 返回对应于获取行的字符串关联数组,如果没有更多行,则返回FALSE。
..。所发生的情况是您的SQL查询不返回任何行。
您现在可以忘掉PHP并启动您最喜欢的MySQL客户机(MySQL工作台、HeidiSQL等)。在那里尝试SQL代码,直到它按预期工作为止。
https://stackoverflow.com/questions/37976038
复制相似问题