RE: [PHP-DB] help with file downloads from MySQL

2006-03-24 Thread David Robley
Mickey Martin wrote:

> I guessed that 0a is the code for a new line, but cannot find where it is
> in my code. This is the entire code that I'm using for the download:
> 
>  if ($id_files) {
> 
> mysql_select_db($database_ctnwww, $ctnwww);
> $query_Attachment = sprintf("SELECT bin_data, filetype, filename, filesize
> FROM IssueAttach WHERE id_files=%s", $_GET['id_files']);
> $Attachment = mysql_query($query_Attachment, $ctnwww) or
> die(mysql_error()); $row_Attachment = mysql_fetch_array($Attachment);
> 
>   $data = $row_Attachment['bin_data'];
>   $name = $row_Attachment['filename'];
>   $size = $row_Attachment['filesize'];
>   $type = $row_Attachment['filetype'];
> 
>   header("Content-type: $type");
>   header("Content-length: $size");
>   header("Content-Disposition: attachment; filename=\"$name\"");
>   header("Content-Description: PHP Generated Data");
>   echo $data;
> }
> ?>
> 
> I have also tried putting a string in front of the file on the echo line:
> echo "TEST TEXT", $data;
> 
> When the file is saved, it begins with 0a followed by TEST TEXT and then
> the start of the file without another instance of 0a.
> 
> Mickey
> 
> 
> -Original Message-
> From: Oskar [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 24, 2006 1:59 AM
> To: Mickey Martin; PHP db
> Subject: Re: [PHP-DB] help with file downloads from MySQL
> 
> Mickey Martin wrote:
> 
>> From what I can tell, the 0a is not in the file, but is being inserted
>>either with the echo or by the browser when it receives the file. Does
>>anyone know if a proxy server would cause this? There shouldn't be one
>>involved, but I am going to contact my IT department to find out how it
>>is configured today.
>>
>>Thanks,
>>Mickey
>>  
>>
>>
>>  
>>
> 0a is new line character code. Check your script you must be somewhere
> displaying it.

For a wild guess - is http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] help with file downloads from MySQL

2006-03-24 Thread Mickey Martin
I guessed that 0a is the code for a new line, but cannot find where it is in
my code. This is the entire code that I'm using for the download:

 

I have also tried putting a string in front of the file on the echo line:
echo "TEST TEXT", $data;

When the file is saved, it begins with 0a followed by TEST TEXT and then the
start of the file without another instance of 0a.

Mickey


-Original Message-
From: Oskar [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 24, 2006 1:59 AM
To: Mickey Martin; PHP db
Subject: Re: [PHP-DB] help with file downloads from MySQL

Mickey Martin wrote:

> From what I can tell, the 0a is not in the file, but is being inserted 
>either with the echo or by the browser when it receives the file. Does 
>anyone know if a proxy server would cause this? There shouldn't be one 
>involved, but I am going to contact my IT department to find out how it 
>is configured today.
>
>Thanks,
>Mickey
>  
>
>
>  
>
0a is new line character code. Check your script you must be somewhere
displaying it.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Displaying results from a query properly.

2006-03-24 Thread Alex Major
Thanks, works like a charm (had to make is -2 instead of -1 as it added a
space after each result). Hadn't thought of something so simple.

Regards,
Alex.


On 24/3/06 16:22, "Bastien Koert" <[EMAIL PROTECTED]> wrote:

> Build it up as a string and remove the trailing comma at the end of the loop
> 
> do { $sHTML .= ''.$administrators['username'].', ';}
> while ($administrators = mysql_fetch_assoc($administrators_result))
> 
> $sHTML = substr($sHTML, 0, strlen($sHTML)-1);
> 
> echo $sHTML;
> 
> ?>
> 
> Bastien
> 
> 
> 
>> From: Alex Major <[EMAIL PROTECTED]>
>> To: 
>> Subject: [PHP-DB] Displaying results from a query properly.
>> Date: Fri, 24 Mar 2006 16:19:10 +
>> 
>> Hi there.
>> This isn't a major problem, more of a matter of aesthetics.
>> Basically, I have a query which pulls a list of usernames from the database
>> (based on their user level).
>> 
>> These users should then listed in this fashion.
>> 
>> Administrators: allydm, alex, mike, dave
>> Moderators: big 'd', frank, william
>> 
>> However, the loop that I have returns the results like this...
>> 
>> Administrators: allydm, alex, mike, dave,
>> Moderators: big 'd', frank, william,
>> 
>> There is a , after each username, including the last one in that list. I'm
>> after a way of making the usernames display with a , after them, apart from
>> the last username in that set of results.
>> 
>> My current display code is:
>> 
>> > do {echo ''.$administrators['username'].', ';}
>> while ($administrators = mysql_fetch_assoc($administrators_result))
>> ?>
>> 
>> How could I change to display the results in the fashion that I'd like?
>> Many thanks for any suggestions.
>> 
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Displaying results from a query properly.

2006-03-24 Thread Bastien Koert

Build it up as a string and remove the trailing comma at the end of the loop

do { $sHTML .= ''.$administrators['username'].', ';}
while ($administrators = mysql_fetch_assoc($administrators_result))

$sHTML = substr($sHTML, 0, strlen($sHTML)-1);

echo $sHTML;

?>

Bastien




From: Alex Major <[EMAIL PROTECTED]>
To: 
Subject: [PHP-DB] Displaying results from a query properly.
Date: Fri, 24 Mar 2006 16:19:10 +

Hi there.
This isn't a major problem, more of a matter of aesthetics.
Basically, I have a query which pulls a list of usernames from the database
(based on their user level).

These users should then listed in this fashion.

Administrators: allydm, alex, mike, dave
Moderators: big 'd', frank, william

However, the loop that I have returns the results like this...

Administrators: allydm, alex, mike, dave,
Moderators: big 'd', frank, william,

There is a , after each username, including the last one in that list. I'm
after a way of making the usernames display with a , after them, apart from
the last username in that set of results.

My current display code is:



How could I change to display the results in the fashion that I'd like?
Many thanks for any suggestions.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Displaying results from a query properly.

2006-03-24 Thread Alex Major
Hi there. 
This isn't a major problem, more of a matter of aesthetics.
Basically, I have a query which pulls a list of usernames from the database
(based on their user level).

These users should then listed in this fashion.

Administrators: allydm, alex, mike, dave
Moderators: big 'd', frank, william

However, the loop that I have returns the results like this...

Administrators: allydm, alex, mike, dave,
Moderators: big 'd', frank, william,

There is a , after each username, including the last one in that list. I'm
after a way of making the usernames display with a , after them, apart from
the last username in that set of results.

My current display code is:



How could I change to display the results in the fashion that I'd like?
Many thanks for any suggestions.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re-arranging elements in an associative array

2006-03-24 Thread Fred Riley
Hi

This is my first question to these NGs, so please be gentle with me in any 
replies :). I've crossposted it as I'm not sure which is the more appropriate 
group. 

I'm a relative newbie to PHP, and my Q in short is: is there an easy way to 
manually change the arrangement of elements in an associative array? 

I'll use an example from the PHP manual:

$a = array( 'color' => 'red',
'taste' => 'sweet',
'shape' => 'round',
'name'  => 'apple',
  );

If you then iterate through this with foreach() to print it out then the keys 
and values will be printed in the order above. What I'd like to do is, say, 
move $a['name'] up to 2nd place, so that it would print in the order:

'color'
'name'
'shape'
'name'

I don't want to sort the array, just rearrange it a bit. I've looked in the 
array function list in TFM but can't see anything appropriate, and I couldn't 
see anything on PX or phpbuilder. 

The reason I want to do this is to arrange the values in a row extracted from 
mySQL. If you click on any of the titles in my test database browse page at 
http://www.nottingham.ac.uk/~ntzfr/rlos/database/rlo_titles.php you should get 
a 'full record' page. The fields from "RLO No." down to "Record last updated" 
are extracted from a single table 'RLO' with a simple SELECT query and their 
names and values are stuck into the associative array $record. The fields below 
(Author, Developer, etc) are extracted from junction tables by separate join 
queries, and also assigned to $record. The table is then printed with a simple 
foreach loop. What I'd like to do is shift, say, "Author" after "RLO title", 
"Developer" after "Stage", and so on.

I could do this the clunky way, by manually assigning each key and value from 
the queries into an array with the elements in the required order, and I'll do 
that if there's no easy way of rearranging elements. I suppose I could use some 
complex combination of shift(), pop(), merge() and whatnot, but that would 
probably take up more time than the clunky way. TIA for any suggestions/tips.

Cheers

Fred
Learning Technologist
School of Nursing, University of Nottingham

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php