Connecting Tech Pros Worldwide Forums | Help | Site Map

Trouble with implode.

Andreas Paasch
Guest
 
Posts: n/a
#1: Jul 16 '05
I'm having trouble with the implode function and need some help here.
I've been reading at php.net but that didn't solve my problem.

I'm having the below code:

$query = "SELECT top1, top2, top3, top4, top5, top6,
top7, top8, top9, pricesmall, pricelarge
FROM esperia
WHERE productnumber = '$bestil'";

include "connection.inc";
$row = @ mysql_fetch_row($result);

$original = implode(", ", $row);

that keeps on crashing on me.
"Warning: implode() [function.implode]: Bad arguments"

But I can't seem to locate my error at all.
It happens once in a while using single words, but mostly breaks of when the
value is space seperated double words or words with special danish
characters.
I've tried to locate it and fix it, but my knowledge of PHP limits me a lot.
I've attempted to locate some MySQL syntax that allows me to perform the
above operation - checking for a special value in a specific MySQL row -
but haven't found anything that can do that easily.

Any ideas ?

I'm running linux mandrake 9.1, with PHP 4.3.1, apache 1.3.27. No funny
business with my PHP.ini, just default settings, register_globals off.

/Andreas

--
Registeret Linux user #292411
Jean-Baptiste Nizet
Guest
 
Posts: n/a
#2: Jul 16 '05

re: Trouble with implode.


Andreas Paasch wrote:

[color=blue]
> BTW, connection does not run the queries, just establishes the connection to
> the DBMS.
>[/color]

Just FYI, I would use require_once for this kind of include: if the
included file defines a function, it will make sure the function is not
defined twice, and there is no need to connect twice to the database.
I use require_once to include function definitions or initialization
code (session_start(), database connection, etc.), and I use include to
include visual components (parts of a page).

JB.
[color=blue]
> Thanks again.
>
> /Andreas[/color]

Andy Hassall
Guest
 
Posts: n/a
#3: Jul 16 '05

re: Trouble with implode.


On Tue, 22 Jul 2003 14:19:07 +0200, Andreas Paasch <Andreas@Paasch.Net> wrote:
[color=blue][color=green][color=darkred]
>>> $row = @ mysql_fetch_row($result);[/color]
>>
>> Unless the included connection.inc file executes the query, $result is
>> an uninitialized variable. You define the query, but you don't execute
>> it.[/color]
>
>Thanks a lot, you are right, that did it.
>I have looked it over for days now trying to locate this one error.
>I really didn't see it. I tried to stay away from the code as that often
>clears ones mind, but even that didn't make me see my error.[/color]

You should avoid the use of @, particularly during development, as this
suppresses errors.

If you had not had that there, the warning that would have been produced would
likely have lead you to the problem.

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Andreas Paasch
Guest
 
Posts: n/a
#4: Jul 16 '05

re: Trouble with implode.


Andy Hassall wrote:
[color=blue]
> On Tue, 22 Jul 2003 14:19:07 +0200, Andreas Paasch <Andreas@Paasch.Net>
> wrote:
>[color=green][color=darkred]
>>>> $row = @ mysql_fetch_row($result);
>>>
>>> Unless the included connection.inc file executes the query, $result is
>>> an uninitialized variable. You define the query, but you don't execute
>>> it.[/color]
>>
>>Thanks a lot, you are right, that did it.
>>I have looked it over for days now trying to locate this one error.
>>I really didn't see it. I tried to stay away from the code as that often
>>clears ones mind, but even that didn't make me see my error.[/color]
>
> You should avoid the use of @, particularly during development, as this
> suppresses errors.
>
> If you had not had that there, the warning that would have been produced
> would
> likely have lead you to the problem.[/color]

I learn new tricks every day, thanks.
The basic code is from my PHP book and I modify it for my specific needs,
that causes trouble at times.
But I learn ...

Thanks.

/Andreas

--
Registeret Linux user #292411
Andy Hassall
Guest
 
Posts: n/a
#5: Jul 16 '05

re: Trouble with implode.


On Tue, 22 Jul 2003 23:48:47 +0200, Andreas Paasch <Andreas@Paasch.Net> wrote:
[color=blue]
>Andy Hassall wrote:
>[color=green]
>> On Tue, 22 Jul 2003 14:19:07 +0200, Andreas Paasch <Andreas@Paasch.Net>
>> wrote:
>>[color=darkred]
>>>>> $row = @ mysql_fetch_row($result);
>>>>
>>>> Unless the included connection.inc file executes the query, $result is
>>>> an uninitialized variable. You define the query, but you don't execute
>>>> it.
>>>
>>>Thanks a lot, you are right, that did it.
>>>I have looked it over for days now trying to locate this one error.
>>>I really didn't see it. I tried to stay away from the code as that often
>>>clears ones mind, but even that didn't make me see my error.[/color]
>>
>> You should avoid the use of @, particularly during development, as this
>> suppresses errors.
>>
>> If you had not had that there, the warning that would have been produced
>> would
>> likely have lead you to the problem.[/color]
>
>I learn new tricks every day, thanks.
>The basic code is from my PHP book and I modify it for my specific needs,
>that causes trouble at times.
>But I learn ...[/color]

There seems to be a lot of code posted from books (in various programming
groups) that is:

(a) out of date
(b) poorly written
(c) both :-(

So I would be very careful with what you read in books, as it appears that
there are a number of authors that churn out poor code just to get their books
on the shelves as quickly as possible so they can "make money fast".

This isn't in any way to say that they're of no use; but you should read the
books in very close conjunction with the latest version of the PHP manual pages
itself so that you can spot any inconsistencies or potential problems early on.

PHP is a fairly fast evolving language compared with some others, so books
tend to get out of date quite quickly (just see the number of
'register_globals' based posts as an example).

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Andreas Paasch
Guest
 
Posts: n/a
#6: Jul 16 '05

re: Trouble with implode.


Andy Hassall wrote:
[color=blue]
> On Tue, 22 Jul 2003 23:48:47 +0200, Andreas Paasch <Andreas@Paasch.Net>
> wrote:
>[color=green]
>>Andy Hassall wrote:
>>[color=darkred]
>>> On Tue, 22 Jul 2003 14:19:07 +0200, Andreas Paasch <Andreas@Paasch.Net>
>>> wrote:
>>>
>>>>>> $row = @ mysql_fetch_row($result);
>>>>>
>>>>> Unless the included connection.inc file executes the query, $result is
>>>>> an uninitialized variable. You define the query, but you don't execute
>>>>> it.
>>>>
>>>>Thanks a lot, you are right, that did it.
>>>>I have looked it over for days now trying to locate this one error.
>>>>I really didn't see it. I tried to stay away from the code as that often
>>>>clears ones mind, but even that didn't make me see my error.
>>>
>>> You should avoid the use of @, particularly during development, as this
>>> suppresses errors.
>>>
>>> If you had not had that there, the warning that would have been
>>> produced would
>>> likely have lead you to the problem.[/color]
>>
>>I learn new tricks every day, thanks.
>>The basic code is from my PHP book and I modify it for my specific needs,
>>that causes trouble at times.
>>But I learn ...[/color]
>
> There seems to be a lot of code posted from books (in various programming
> groups) that is:
>
> (a) out of date
> (b) poorly written
> (c) both :-(
>
> So I would be very careful with what you read in books, as it appears
> that
> there are a number of authors that churn out poor code just to get their
> books on the shelves as quickly as possible so they can "make money fast".
>
> This isn't in any way to say that they're of no use; but you should read
> the
> books in very close conjunction with the latest version of the PHP manual
> pages itself so that you can spot any inconsistencies or potential
> problems early on.
>
> PHP is a fairly fast evolving language compared with some others, so
> books
> tend to get out of date quite quickly (just see the number of
> 'register_globals' based posts as an example).
>
> --
> Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
> Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)[/color]

I'm fully aware of these facts. The one I use for this specific solution is
O'Reilly's Webdatabase applications with PHP and MySQL.
In fact, I don't actually read the book and try out the examples, I just got
their code, analyzed it and modify it - I go by "Learning by doing". Not
the perfect way, but my way.

Alongside this, I read at www.php.net and www.mysql.com to get info as much
as possible.
Books are for me a way to start of, but only by doing I learn.
Books have sometimes valuable information about doing things in a better
way. Doesn't mean the code is perfected, but it might often be better then
whats in my mind. That's a learning process for me.
I have learned in time, that O'Reillys books are brilliant and thats the
reason for me to prefer them to start with.
There is always a development going on but If you always want up-to-date
stuff, you never buy a book, you never buy a computer, you never buy a car.
At some point you have to take a decision and go from there. That's what I
do here.
I've learned for the past 20 years, I'm still going strong.

I never reject input nor ideas. Why should I ?

/Andreas

--
Registeret Linux user #292411
Closed Thread