dynamic arrays?

So I’m newish to php. I can add, edit, delete, and move data around pretty well.

But I came across a problem today and I have not used arrays much so…

I have a PDF I’m trying to merge data into. I need that data in an array. I can get the data from a simple query but how do I get that query data into an array? Could I do something like this…
[php]
while($row = mysql_fetch_array($result))
{
$name=$row[‘name’];
$date=$row[‘date’];
}[/php]

then
[php]
$fields = array
(
“company_business_name” => “$name”,
“date” => “$date”
);[/php]

This is merging data into a PDF usig fpdf since the host does not allow me to use pdf_new().

Hi there,

Well if your query is only returning one result just do this:
[php]$result = mysql_query($sql);
$fields = mysql_fetch_assoc($result);[/php]

Or you can do something like this:
[php]$i = 0;
while(($row = mysql_fetch_assoc($result) !== false)
{
$fields[$i][‘name’] = $row[‘name’];
$fields[$i][‘date’] = $row[‘date’];
$i++;
}[/php]

Well that was simple you rock!!

Do you know anything about fpdf by any chance? I got the array to work but keep getting an error about my pdf “being empty”.

I’m afraid not. All I can suggest is checking online documentation for what it expects (make sure it’s an array and that the array is structurally correct).

Sponsor our Newsletter | Privacy Policy | Terms of Service