I am stuck at the following piece of code that will not enter the while loop for some reason:
<?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
returns a resource id when i echo it, so i know that the db is connected and is sending some value to the fetch_assoc function. I have tried replacing the function with fetch_array, but that doesn't work either. Moreover, i cannot see any error when using 'or die' function of php.
I have tried renaming retval to different variables, and also used mysqli to no avail. Any ideas?