I am having trouble with ezpdf. it works fine for first row of recordset, however I am unable to get all rows of the recordset in ezpdf. it seems that ezpdf somehow ends working after the first record and just creates the pdf file anyway.
Here is what I am doing.
Getting order details from a transaction table and generating tickets based on the quantity in the order. So let's say it has 3 tickets to generate in an order, the pdf will only generate the ticket for first row. It does not accumulate the data of 2nd and 3rd row.
Here is my code.
http://pastebin.com/DMaZUpqw
Please help.
Thanks
Ali
Well if I got that correctly it is supposed to print multiple of those tickets onto on pdf document. Why is this line commented out?:
#$pdfid = $pdf->newPage(1, $pdfid, 'after');
wouldn't you have to add another page before going on printing stuff there?
If $RowsTkt actually returns multiple rows, there is no way, it only iterates once.
Have you checked (by dumping an index or such) that the loop actually does not execute three times as you implied?
Regards
STEFAN
Related
I would like to conditionally display table row in predefined Ms Office Word file. The solution I am using currently only allows to manage display of whole block and so on the whole tables according to different combination of displayed data. I find this solution obscure. This is why I need conditionally display table row.
Current solution works with:
$$nameofdesiredkey
the conditionally shown content
nameofdesiredkay$$
I was able to solve that issue by workaround using another data table as result of dynamic values from pontential spread of values in the original table.
During my reserach idea of using multiple tables, using one dynamic data table list in one TD or just using $$variablestart variableend$$ and the start and end of each of nearest surrounding TDs seemed potent also.
I'm currently using MySQL Workbench to write very complex SQL Queries. To compare between different approaches, I need to know how many records have been returned by my query very quickly.
So, is there any way I can see the number of records returned by my query in the result grid as soon as I execute it?
I know that I can go to the 'Form Editor' tab and click on next and it will show me something like (2/179). But that's a very tedious process for me.
The "Action Output" pane (the bottom vertical pane) has a "Response" column that tells you how many rows were returned.
Philip Olson's way is a good one; yet another way is look at Query Stats in the same panel:
Rows sent to client is the one of interest; note Rows examined is not, as it shows how many rows the engine read to generate the results. (In this case, the operation was an inner join.)
How do I echo out the first item of every table in a adatabase. I know how to do it in one, but not in all. Do I have to use mysql_list_tables() and then get first item with LIMIT? I tried mysql_list_tables(), but it didn't work for some reason.
Could someone help me please?
Make a query to information_schema.TABLES (itself a table) to get a list of tables in your database. Then use that list of tables in your PHP code to drive the generation of queries to each table.
Be careful here. The notion of "first" row in a table is surprisingly fuzzy in the world of RDMSs. If you include ORDER BY you'll have control over it..
I have a question about PHP foreach loops. I'm using it in Codeigniter.
Basically I have a list of items in a db and I'm using a foreach loop to run a script on each item in the db until the script has been run on every item.
My question is: If I had, for example, 45 items in the database and then initiated the loop, what would happen if additional items were added to the database list while the loop was still running, thus making a bigger list of items to be looped over?
Would it either:
Run all the items that were in the loop when it was initiated (in this case, 45).
or
Run all the items in the loop and when it gets down to the end (at number 45) continue to run the script on the additional ones I added after the loop was initiated.
I can't seem to find any answers for this, any info is most appreciated
When you fetch all items from the db with CodeIgniter, it puts the results in an result object or array, depending if you use $this->db->result(); or $this->db->result_array();
So when you loop over this result, any new records won't show up in this object or array. Only when you fire a new query, any new rows will be added to the result.
Initially when you fired a query their was 45 records in db and then record has been added , so there will be only 45 records which will be displayed
When a php script run for extracting records from DB table, it actually extract all the records from table according to u'r query & save it in a PHP variable. After that, foreach loop extract data one by one from that variable & execute it.
At the execution time, if any more records comes to u'r DB table then that'll get store in u'r table not in u'r PHP array. So, forloop execution will not get effected by those extra rows.
If u want to execute, all those extra records.. then again u've to make SELECT query to the DB table & extract those additional records.. Need to keep them a PHP array & execute them by foreach.
I'm quite new to php and mysql so hopefully someone with more experience will be able to give me some guidance here.
I have the following code:
<?php
$npcname = $_GET['npcname'];
$npcinfo="SELECT * from npcs where name='$npcname'";
$npcinfo2=mysql_query($npcinfo) or die("could not get npc!");
$npcinfo3=mysql_fetch_array($npcinfo2);
$listquests = "SELECT * from quests where npcid = '$npcinfo3[npcid]'";
$listquests2 = mysql_query($listquests) or die("No Quests to list");
$listquests3=mysql_fetch_array($listquests2);
echo "<b>Quests Available for ".$npcname."</b><br>";
while($row=mysql_fetch_array($listquests2)) {
echo $row['name'];
}
?>
To go with this I have some tables whcih look like this:
npcs
name|location|npcid
quests
name|qid|npcid
So a quest is associated to a NPC via the npcid field.
I have one entry in each table.
Bob|Scrapyard|1
AND
Sort Scrap Metal|1|1
As you can see the quest and Bob both share the npcid of 1.
In my loop I am trying to list all of the quests for Bob. However on running the code I do not get any quests listed.
If I put the code:
$listquests3['name'];
Outside of my loop it successfully displays "Sort Scrap Metal" as expected. The reason I have used the loop is to display multiple quests when I add them.
If somebody could be kind enough to take a look at the code and tell me what I have done wrong I would be grateful.
Thank You.
It may be a good idea to print out the SQL and run this against your database to see what results you get.
Looking at this it looks like there may only be one result which is fetched in the
$listquests3=mysql_fetch_array($listquests2);
line. Since there are no more results there is nothing to loop over.
The results are already fetched, since there is only one rule and you fetched it in $listquests3 :). It will work if you remove that line I think.
You need to do a INNER JOIN or a LEFT JOIN. Yes after carefully seeing the question again, I found that when doing the "mysql_fetch_array()" code for the first time (just before the "while" loop), the value of the variable "$listquests2" gets lost. So the "while" loop does nothing fruitful.
You must remove this single line for variable "$listquests3".
You only have one row, and you fetched that row when you called mysql_fetch_array the first time. When you call it the second time, there are no more rows to fetch in the result set, the function returns false and your loop exits.
This statement: "$listquests3=mysql_fetch_array($listquests2);" already fetches the first. Sicne you have only one, there's nothing more to fetch, so the next call to mysql_fetch_array will return nothing.
That should fix it, but for your own 'experience', this might be a good moment to start learning about MySQL joins (LEFT JOIN in particular). You can easily find a lot about it on the internet!