While loop for TCPDF - php

I have problem to loop the data in TCPDF..The output should be display like this
Output :
Chair x 3
Table x 5
LCD X 2
but output now just show : Chair x 3
It only display the first record. Can anyone explain
how to loop the data based on output above?
$result_1=mysql_query($query_1);
while($row1=mysql_fetch_array($result_1)){
$item = $row1['item'];
$qty = $row1['SUM(qty)'];
$data = $item.' x '.$qty;
$tbl.='<td align="center">'.$data.'</td>';
$data='';
}
$tbl.='</tr>';
}
This picture output I get based on coding above

This is answer for my question. I just add $data. at $data = $item.' x '.$qty; and my problem has been solved.
$result_1=mysql_query($query_1);
while($row1=mysql_fetch_array($result_1)){
$item = $row1['item'];
$qty = $row1['SUM(qty)'];
$data = $data.$item.' x '.$qty.'<br>';
}
$tbl.='<td align="center">'.$data.'</td>';
$data='';
$tbl.='</tr>';
}

Related

Calculating Size Dimensions in PHP

I'm trying to put together a simple calculation.
I have a size dimension of 100 x 100 x 100 which is a box.
I have individual items of 50 x 50 x 50.
If I keep adding items, I want to work out how many boxes is required to hold those items.
For example:
If I have 1 item of (50x50x50) then I will need 1 box to hold that item.
If I have 2 items of (50x50x50) then I will need 1 box to hold those 2 items.
If I have 3 items of (50x50x50) then I will need 2 boxes to hold those 3 items.
Any help would be greatly appreciated.
<?php
function GetItemsInBoxQuantity ($boxsize = array(100, 100,100), $verifiable_item = array(50,50,50)) { # here we pass default values of box size and verifable items
$boxspace = array_product($boxsize);
$verifiable_item_space = array_product($verifiable_item);
$count_boxes_in_boxspace = floor($boxspace / $verifiable_item_space);
return $count_boxes_in_boxspace;
}
# Now we putting new values of box size and size of items
$box = array(200,100,100);
$verifiable_item= array(40,40,40);
$result = GetItemsInBoxQuantity($box, $verifiable_item);
echo 'We can put into box '.$result.' items.';
?>
Output:
We can put into box 31 items.

How to count JSON response and output how many lines there are

Hello fellow developers,
I have been trying to manipulate the output and display the total amount of workers there are instead of outputting the workers name as a string.
Bellow you will find the data that i am receiving and further down i will explain how i would like to handle the JSON response.
{
"result":
{
"addr":"ADDRESS_HERE",
"workers":
[
["worker1080",{},2,1,"200000",0,22],
["worker1080",{"a":"899.4"},3,1,"512",0,24]
],
"algo":-1
},
"method":"stats.provider.workers"
}
So basically as you can see from the above response that there are 2 workers named "worker1080" active on that address.
The bellow php code is how i retrieve the data and output only the names of the workers:
<?php
$btcwallet = get_btc_addy();
if (isset($cur_addy)) {
$method4 = new methods();
$worker_stats = new urls();
$get_data = file_get_contents(utf8_encode($worker_stats->nice_url.$method4->m4.$cur_addy));
$get_json = json_decode($get_data, true);
foreach ($get_json['result']['workers'] as $v) {
$i = 0;
print $v[$i++]."<br />";
}
}
?>
$get_json is the variable that decodes the data from $get_data and displays the worker names and increments every time a worker is added or online.
now i currently have 2 workers online as shown in the JSON response.
it outputs:
worker1080
worker1080
which is perfect although if i try using a foreach statement and try to display the the total amount of workers online it should display 2 instead of the names, it has to also increment for each worker that the json repsonse outputs.
EG: i have 2 workers online now, but in an hour i will connect 10 more it would display the following:
worker1080
worker1080
worker1070
worker1070
worker1080ti
worker1080ti
workerASIC
workerASIC
workerASIC
workerCPU
workerCPU
workerCPU
Now i try to use the following to display the total:
count($v[$i++]);
and i have tried using a foreach within the foreach, and both count and the foreach both will either display "0" by all the workers or "1"
bellow is an example of the output.
0
0
0
0
0
How would i go about counting each line in the output and display the total number of workers ?
Thanks #symcbean for the solution.
<?php
$btcwallet = get_btc_addy();
if (isset($cur_addy)) {
$method4 = new methods();
$worker_stats = new urls();
$get_data = file_get_contents(utf8_encode($worker_stats->nice_url.$method4->m4.$cur_addy));
$get_json = json_decode($get_data, true);
print count($get_json['result']['workers'])."<br />"; // <-- solution *removed foreach and $i incrementation as its not needed for count
}
?>
it now displays the correct number of workers :)

PHP and Phpmyadmin multiplication

I want to hit 2 values with the same id on PhpMyAdmin. According to the codes below, only the aggregation is running in the outputs I receive. I get a value of 0 when I multiply instead of adding.
<?php
$a = 0;
$oran = new sorgu;
$k_id = $kuponlar->veri->id;
$oran->select("*","matches","kid=$k_id");
while($oran->verioku()){
$a = $a+ floatval($oran->veri->oran);
}
echo $a;
?>
Screenshots:
It is necessary to multiply the "oran" values in there. But those with the same "kid" value are at least struck for that table.
That's the code that's running
Action Required:
1,25 x 1,5 x 1,3 x 1,55

PHP: "While" loop returns same value for each iteration of the variable

Thanks in advance for any help offered.
I'm performing a query that returns something like this:
route | busnumber
2 300
4 123
2 455
12 934
My goal is to print/echo a list of all "busnumber" were "route" = 2.
I know I can do a query on the DB to do this but I don't want to run this query for each and every route. The result set is actually part of one master, complex query so I need to accomplish my goal using the array.
The query works correctly and does display the appropriate info. I also return the results into an array. i.e ...
$query=("SELECT * from foo")
$result=mysql_fetch_assoc($query);
My current code looks like this (note my comments):
mysql_data_seek( $result,0); // because I'm previously iterating through $result
while ($i2=mysql_fetch_assoc($result)) {
$busnumber=$i2['busnumber'];
$busroute=$i2['route'];
echo "<div class='businfo'>";
if ($busroute='2'){ // I only want this to happen if $busroute=2
echo "Current Route = $busroute</br>";
echo "Bus Number : $busnumber </br>";
}
echo "</div>";
}
What I'm getting, however, it is echoing the same '$busroute' (2) but different '$busnumber' for each row as such:
Current Route = 2
Bus Number : 194
Current Route = 2
Bus Number : 196
Current Route = 2
Bus Number : 2002
Current Route = 2
Bus Number : 2010
Current Route = 2
Bus Number : 2013
The problem is that all of those bus numbers are not part of route 2. It is a listing of bus numbers from all routes. I only want it to perform the foreach loop if $routenumber=2.
Thanks again for the help :)
if ($busroute='2'){
The problem is that you're not checking whether it's equal to 2 here, you're assigning it to equal 2. Change it to this and you'll be fine:
if ($busroute=='2'){
$query = "SELECT * from foo";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
if ($row['route'] == 2) {
// do your stuff
}
}

Json Decode,Access, show and separate names with ID, every 9 names

Hello :) I give you the Json Decode below.
http://pastebin.com/XqhTMWCS
It presents my last 10 games. I need to get my 4 teamates for every game,and my 5 enemies.(names) When someone is a teamate, his "teamId" is 100 and when someone is an enemy,the "teamId" is 200. I need to separate and show them.
Like: You were playing Vayne. Your team was:
sirjack1101 playing champion ID 89
blablaa playing ID 22
blablaaa playing ID 23
blablaaaa playing ID 24
The enemy team was:
blablsaa playing ID 31
bsadaaas playing ID 12
basdasdb playing ID 53
blablsad playing ID 67
blablsav playing ID 121
I can find only the first username using this :
$recent = "My json" ;
$rec = file_get_contents($recent);
$recdat = json_decode($rec, true);
$fellow = $recdat[gameStatistics][0][fellowPlayers][0][summonerName];
echo $fellow;
And I can get only my 1st champion name using the same code... I need your help! :)
Thanks in advance!
Sounds like you just need a foreach loop to iterate over all players.
<?php
define('TEAMMATE_ID', 100);
define('ENEMY_ID', 200);
$teammates = $enemies = array();
foreach ($data['gameStatistics'][0]['fellowPlayers'] as $player) {
if ($player['teamId'] == TEAMMATE_ID) {
$teammates[] = $player['summonerName'] .' playing ID '. $player['championId'];
}
else if ($player['teamId'] == ENEMY_ID) {
$enemies[] = $player['summonerName'] .' playing ID '. $player['championId'];
}
}
// List of teammates.
print "Teammates:\n";
print implode("\n", array_slice($teammates, 0, 4));
// List of enemies.
print "Enemies:\n";
print implode("\n", array_slice($enemies, 0, 5));
?>
Hopefully I'm not way off base...

Categories