Solved

Doesnt show all the select value on the screen

Posted on 2008-06-15
4
190 Views
Last Modified: 2008-06-16
PHP
I received ouput value that doesnt show all the result i want on the screen

The data output i WANT to received is shown below
supermarketname  | miloAmountstock  |horlickAmountstock| candy.. |chocolate.. | stock..  | chips..
"coles"                   |"21546"                  |"54685"                   |"54658" |"24367"      |"no stock"|"85496"|
"giant"                    |"84564"                  |"87956"                   |"478546"|"45754"    |"no stock"|"78954"|

but the output i get is this
"coles"|"21546"|
"giant"|"54685"|

It looks like it cant read the rest of the data and continue the data in the row of giant 84564
my code is in code snippet


function GetAmount()

{

$ItemID = array(1234,6545,5468,9856,4578,"no stock",4561);

$arrayElement[5] = "no stock";

$supermarketID = array(21,32);

 

 $cnt=count($supermarketID);

 for($x=0; $x<$cnt; $x++)

{

 $supermarketID_value = $supermarketID[$x]; 
 

for ($j = 0; $j < sizeof($ItemID); $j++)

  {

 if (($ItemID[$j] != $arrayElement[5]) 

	{

	 $query = mysql_query("SELECT getitem_std_amountstock( \"$supermarketID_value\",  \"ItemID[$j]\") AS AMOUNT");

     

	 $j = 0; 

         $temp="";

         while($row = mysql_fetch_array($query))

	      {

              $temp .= '"'.$row['AMOUNT'].'"'; 

              }

          $this->GetAmountStockReturn[$i++] .= $temp; 

        }  

	else

        {

      $this->GetAmountStockReturn[$i++] .=  "\"no stock\" |";

  	}

   }

 

 

function joinSUPERMARKETNAMEnAMOUNTSTOCK()

{

//SUPERMARKETNAME select value is from another function

 

 foreach(($this->GetSupermarketReturn_value as $i => $datas)

	 {

           $data1 = "{$datas} | {$this->GetAmountStockReturn[$i]}  "; 

	   print_r( $data1);

	 }

}

Open in new window

0
Comment
Question by:firekiller15
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Xorlev
ID: 21790673
Your query seems to only be retrieving a single column.

         $query = mysql_query("SELECT getitem_std_amountstock( \"$supermarketID_value\",  \"ItemID[$j]\") AS AMOUNT");

And:

$temp .= '"'.$row['AMOUNT'].'"';

If you want candy, chocolate, bluechips and what not, you'll need to select them from the database.
0
 

Author Comment

by:firekiller15
ID: 21790741
if i output my result in function GetAmount() i can get the result and the result is correct as follow

Array ( [] => "21546" |[1] => "54685" |[2] => "54658" |[3] => "24367" |[4] => "no stock" |[5] => "85496" |[6] => "84564" |[7] => "87956" |[8] => "478546" |[9] => "no stock" |[10] => "78954"

>>If you want candy, chocolate, bluechips and what not, you'll need to select them from the database
i am select them from the database just that im using SQL function.

i dont think i have problem in the first function  GetAmount()
Maybe is because of the join in joinSUPERMARKETNAMEnAMOUNTSTOCK()

Anyone really know pls help
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 250 total points
ID: 21791344
your joinSuperMarketNameEnAmountStock function only determines the row labels. The columns are returned from getAmountStockReturn.

I think something is going wrong in lines:
$this->GetAmountStockReturn[$i++] .= $temp;
or
$this->GetAmountStockReturn[$i++] .=  "\"no stock\" |";

You try to append some data, but every time in a new array element. That doesn't make sense.

As a sidenote, I am getting somewhat worried on your program structure. I don't see why you don't use mysql joins, why you are using all these ugly functions that do nothing more that filling internal arrays. I worry that you are not using oop as it is intended to, or at least have chosen the wrong path.
Your program will get slugish with all this for-eaching, looping, looping in looping and use heaps of memory from all those internal arrays.
0
 

Author Comment

by:firekiller15
ID: 21791605
yah you are right something worng in $this->GetAmountStockReturn[$i++] .= $temp;
i get rid of increament then everything seems find
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
calculated column 12 74
php ssh2_scp_send 1 48
Form Processing in PHP 11 31
myqsl update statement on phpMyAdmin 8 21
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now