0

I have two tables i am using two quires to fetch data from them separately.

$query = mysql_query("SELECT * FROM offers");


$query1 = mysql_query("SELECT * FROM Offers_Dalia ") or die(mysql_error());

I am printing the result on one html-table. .... the problem is that i want to know that why the loop is running for 11 times both. 1). I am using two while loops. 2). each loop is running for row->mysql_fetch_object times. please help me to find error why my both loops are running for 11 times. total 22 rows are present in html table output. but my both table have so many rows. 100 of rows in both table. please check the code.

$query = mysql_query("SELECT * FROM offers");


 $query1 = mysql_query("SELECT * FROM Offers_Dalia ") or die(mysql_error());

 $x = 1;
 $n = 0;

 while($row = mysql_fetch_object($query))
 {
   $oid = $row->id;
   $name = stripslashes($row->name);
    $reward = stripslashes($row->credits);
   $network =   stripslashes($row->network);
   $hits  = $row->hits; //clicks;  $epc = $row->epc;
   $campid = stripslashes($row->campaign_id);
   $country = $row->countries;
   $url2=$row->link; 
   $desc=$row->description;





     if($x%2 == 0)
     {
       $trColor = "f1f0f0";    
      }else
 {
    $trColor = "ffffff";    
 }                  

if(stristr($country, ","))
{
       $country_arrs = explode(",", $country);
       $country = implode(", ", $country_arrs);       
}    

 ?>
     <tr style="background:#<?=$trColor?>" ><td><input type="checkbox" value="<?=$oid?>" name="ids[]"  onclick="uncheckCheckAllbox(this)" /></td><td><?=$campid?>- campId</td><td><?=$name?></td><td><?=$reward?><td><?=$network?><td><?=$desc?></td><td><a href="<?=$url2?>" target="_blank">Click Here</a></td></td><td><?=$country?></td></tr>

  $n++;
  while($row1 = mysql_fetch_object($query1))
  {
   $uuid = $row1->offers_uuid;
    $title1 = stripslashes($row1->title);
   $info1 = stripslashes($row1->info_short);
   $device_kind1 = stripslashes($row1->device_kinds);
   $country1 =      stripslashes($row1->target_groups_values);
   //  $status = toggleStatus($row->active);
     $reward_dollar1  = $row1->reward_dollar; //clicks;
   $url1 = $row1->url; 
   $network1 = 'Dalia';
    $url1 = urldecode($url1);


    if($x%2 == 0)
    {
      $trColor = "f1f0f0";    
    }else
     {
      $trColor = "ffffff";    
     }                  

    if(stristr($country, ","))
    {
       $country_arrs = explode(",", $country);
       $country = implode(", ", $country_arrs);       
    }    

     ?>


      <tr style="background:#<?=$trColor?>" ><td><input type="checkbox" value=""  onclick="uncheckCheckAllbox(this)" /></td><td><?=$uuid?></td><td><?=$title1?></td><td><?=$reward_dollar1?></td><td><?=$network1?></td><td><?=$info1?></td><td><a href="<?=$url1?>" target="_blank">Click Here</a></td><td><?=$country1?></td></tr>

    $n++;
    $x++;
    goto n;
  }

   n:  
       $x++;

   } 
Awais A.
  • 39
  • 1
  • 7
  • 2
    If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Jan 28 '18 at 18:38
  • ^... I'm not helping with code that uses mysql_* functions, please update your code and then update the question. – Spoody Jan 28 '18 at 18:41
  • i am editing in Website architecture. it is already build. i am not allowed to add database files. if i update mysql_ to PDO , i will need to update all the files :( – Awais A. Jan 28 '18 at 18:41
  • 1
    You urgently need to update to PDO at the absolute least. This code is full of serious problems like using `stripslashes`, which is extremely concerning, instead of `htmlentities`. Always, **always** use the proper escaping method for the context you're rendering in, be it HTML, JavaScript, SQL or otherwise. – tadman Jan 28 '18 at 19:14
  • 1
    Also, as a matter of being polite, please clean up your code before posting. This means removing huge chunks of blank lines which serve no purpose other than to make scrolling through your code harder than it otherwise would be. – tadman Jan 28 '18 at 19:16

0 Answers0