PDA

View Full Version : Problem mimicking ASP's GetRow function in PHP


gemillam
09-21-2009, 01:17 AM
(I posted this in Adobe's Dreamweaver Developer's forum as well.)

I am new to PHP but not to scripting. I am developing a web app using PHP/MySql that will let a particular client's employees set up and order their business cards. I have a Mac running InDesign CS4 and a set of scripts that will take a text file and make a business card out of it automatically. I also have a MySQL database and a PHP-based Dreamweaver site that does everything other than make the text file I need.

For clarity, let me give you the rundown on what happens with this app. What I want to do is have the client login with generic credentials, go through an initial setup where they develop new credentials, as well as all the data to be used later in their business cards and possibly other printed materials. After they submit that info they are taken to another login page where they use their new credentials to go to the main page for them, with links for ordering business cards, updating their personal information, and looking at all their previous orders. When they choose to order more cards, they go to a page that lets them see how the data will look on their card. If they don't like the way it looks, there is a link that lets them update their info and leads them back to the order page. If they like it and want to see a PDF preview of their card, they can click a button that will export out a text file, which should have a name with a reference in it as being temporary plus a counter that make it unique, into a hot folder on the server that the mac with InDesign picks up, formats, and outputs a PDF that is then mailed to the client. If they like the preview, they choose a quantity for their order and submit a form with hidden fields that not only posts an entry to the database but also generates another text file that makes the final PDF for the business card. This final PDF gets mailed back to the client as well as the CSR handling the account so they can enter a job ticket to get it printed. This final text file contains references to the order number in its name.

Of all the stuff I just mentioned, the two things I am having problems with is making the text files for the preview and the final PDFs. I have already written code that will save a file using fopen(). The problem I am having is passing user data from the database into an array so I can use it to fill the file with relevant information for the InDesign scripts. The other is passing the new order number to the final text files name, and getting a number for the temporary text file's counter. I assume that I can merely ask the database for the greatest order number and temporary number. But I have to get those things into variables that I can use to concatenate a string for the file names.

In my research I found that ASP has a great command called GetRow that will make pass a row of data into a 2d array. I also found a nice piece of code where you can get PHP to mimc the same trick. Here it is (written by a user named bastion at http://www.codewalkers.com/c/a/Database-Code/Mimic-ASPs-GetRows-functionality-in-PHP/).

<?
function GetRows($handle)
{
/*
This function emulates the ASP GetRows function. It creates a 2 dimensional
array of the data set where the :

1st dimension is the row number of the data
2nd dimension are the data fields

Returns a two dimensional array if there are record or false if no records
come out of the query
*/

if (mysql_num_rows($handle)>0){

//initialize the array
$RsArray1 = array();

//loop thru the recordset
while ($rows = mysql_fetch_array($handle))
{
$RsArray1[] = $rows;
} //wend
return $RsArray1;
}else{
//no records in recordset so return false
return false;
} //end if
//close the connection
mysql_close($handle);

} //end function
?>

My problem now is figuring out what he means by the variable $handle. What is this a reference to? Is it the name of the database connection? The recordset? One of the other many variables Adobe's code for a recordset has in it? If my database connection is called dbconnection, and the recordset in the Recordset palette for the user data from that connection is called rsUsers, what do I literally put into this function's parameters when I call it in my code for the page? When I call this function and return its value into a new array called $user_data_arr, how do I reference its values so I can create a string to save into the text file? Can I use this same function to call rsOrders, get the latest order number and put it into an array, and add 1 to it so I can generate the file name? Or is there a better way to do this that I don't know about?