Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9287 > unrolled thread

isset not working with select

Started byrichard <noreply@example.com>
First post2013-05-13 07:01 -0400
Last post2013-05-15 22:15 +0100
Articles 18 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  isset not working with select richard <noreply@example.com> - 2013-05-13 07:01 -0400
    Re: isset not working with select Scott Johnson <noonehome@chalupasworld.com> - 2013-05-13 05:49 -0700
    Re: isset not working with select "Peter H. Coffin" <hellsop@ninehells.com> - 2013-05-13 07:43 -0500
      Re: isset not working with select The Natural Philosopher <tnp@invalid.invalid> - 2013-05-13 23:31 +0100
    Re: isset not working with select "J.O. Aho" <user@example.net> - 2013-05-13 20:10 +0200
      Re: isset not working with select The Natural Philosopher <tnp@invalid.invalid> - 2013-05-13 23:43 +0100
    Re: isset not working with select Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-13 19:54 +0000
      Re: isset not working with select richard <noreply@example.com> - 2013-05-14 17:38 -0400
      Re: isset not working with select richard <noreply@example.com> - 2013-05-15 16:23 -0400
        Re: isset not working with select Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-15 20:34 +0000
          Re: isset not working with select richard <noreply@example.com> - 2013-05-15 17:07 -0400
            Re: isset not working with select Christoph Becker <cmbecker69@gmx.de> - 2013-05-15 23:18 +0200
              Re: isset not working with select richard <noreply@example.com> - 2013-05-15 19:07 -0400
                Syntax Highlighting (was: isset not working with select) Christoph Becker <cmbecker69@gmx.de> - 2013-05-16 01:33 +0200
                Re: isset not working with select Tim Streater <timstreater@greenbee.net> - 2013-05-16 08:27 +0100
          Re: isset not working with select richard <noreply@example.com> - 2013-05-15 17:12 -0400
            Re: isset not working with select Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-15 23:54 +0000
        Re: isset not working with select Tim Streater <timstreater@greenbee.net> - 2013-05-15 22:15 +0100

#9287 — isset not working with select

Fromrichard <noreply@example.com>
Date2013-05-13 07:01 -0400
Subjectisset not working with select
Message-ID<zjgov1oukrit$.nu30chb74ox5.dlg@40tude.net>
http://mroldies.net/showtable.php?year=1960



$result = mysql_query("SELECT acover,bcover FROM A$year WHERE id =
$number");
if (!$result) { echo 'Could not run query: ' . mysql_error();  exit; }
$cov = mysql_fetch_row($result);


if (isset($cov[0]))
 {echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>";}
echo "<img src='http://mroldies.net/covers/$year/".$cov[1]."'>";

On item  #1 in the table, the panel appears with the desired images as
wanted.
On item #2 image place holders appear because I do not have them online
yet.
I do not want to see the place holders if there is not an image.
What to use to do that?

Also, if you click on 1961, or any other year, and then any item in the
table, you will get a message below the videos stating the column does not
exist so it can't continue processing.
How can I bypass this when that database does not have that column?

[toc] | [next] | [standalone]


#9290

FromScott Johnson <noonehome@chalupasworld.com>
Date2013-05-13 05:49 -0700
Message-ID<kmqnba$icm$1@dont-email.me>
In reply to#9287
On 5/13/2013 4:01 AM, richard wrote:
> http://mroldies.net/showtable.php?year=1960
>
>
>
> $result = mysql_query("SELECT acover,bcover FROM A$year WHERE id =
> $number");
> if (!$result) { echo 'Could not run query: ' . mysql_error();  exit; }
> $cov = mysql_fetch_row($result);
>
>
> if (isset($cov[0]))
>   {echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>";}
> echo "<img src='http://mroldies.net/covers/$year/".$cov[1]."'>";
>
> On item  #1 in the table, the panel appears with the desired images as
> wanted.
> On item #2 image place holders appear because I do not have them online
> yet.
> I do not want to see the place holders if there is not an image.
> What to use to do that?
>
> Also, if you click on 1961, or any other year, and then any item in the
> table, you will get a message below the videos stating the column does not
> exist so it can't continue processing.
> How can I bypass this when that database does not have that column?
>

First off you should stop using the mysql extensions and start using a 
PDO or MySQLi. (read up on the extensions to find out why, specifically 
mysql_fetch_row)

2. Is your query indeed returning cov[1].  Have you done any debugging 
techniques to determine the variables contents.

C. Your display logic is not very sound.  The second row will ALWAYS try 
to display regardless of cov[0] and whether or not cov[1] is set.

In fact you must have error 'notices' suppressed or you would of gotten 
an undefined index for the second row cov[1] and may have given you an 
idea why it is not working.   When developing have all your errors tuned 
on.  I won't repeat how since it has been explained many times prior.

Here is some homework.

* Begin updating your code to use mysqli or your pdo.
* Learn some debugging techniques such as var_export, print_f, echo....
* Turn ALL your errors on

The first one will prevent your scripts from shutting down once the 
mysql extensions are turned off on future PHP releases.

The last 2 will go a long way in you finding many issues that you will 
have in the future on your own.

Good luck.

[toc] | [prev] | [next] | [standalone]


#9291

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2013-05-13 07:43 -0500
Message-ID<slrnkp1nvo.kvj.hellsop@nibelheim.ninehells.com>
In reply to#9287
On Mon, 13 May 2013 07:01:46 -0400, richard wrote:
> http://mroldies.net/showtable.php?year=1960
>
>
>
> $result = mysql_query("SELECT acover,bcover FROM A$year WHERE id =
> $number");
> if (!$result) { echo 'Could not run query: ' . mysql_error();  exit; }
> $cov = mysql_fetch_row($result);
>
>
> if (isset($cov[0]))
>  {echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>";}
> echo "<img src='http://mroldies.net/covers/$year/".$cov[1]."'>";
>
> On item  #1 in the table, the panel appears with the desired images as
> wanted.
> On item #2 image place holders appear because I do not have them online
> yet.
> I do not want to see the place holders if there is not an image.
> What to use to do that?

If the first one works and the second one doesn't, maybe you should just
do them both like the first one?

> Also, if you click on 1961, or any other year, and then any item in the
> table, you will get a message below the videos stating the column does not
> exist so it can't continue processing.
> How can I bypass this when that database does not have that column?

Again, check for zero rows being returned in your program and build code
to handle that circumstance. die() is NOT your friend.

-- 
I wish there was a knob on the TV to turn up the intelligence. There's a
knob called "brightness", but it doesn't work. 
		-- Gallagher

[toc] | [prev] | [next] | [standalone]


#9318

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-05-13 23:31 +0100
Message-ID<kmrpjt$ejd$3@news.albasani.net>
In reply to#9291
On 13/05/13 13:43, Peter H. Coffin wrote:
> On Mon, 13 May 2013 07:01:46 -0400, richard wrote:
>> http://mroldies.net/showtable.php?year=1960
>>
>>
>>
>> $result = mysql_query("SELECT acover,bcover FROM A$year WHERE id =
>> $number");
>> if (!$result) { echo 'Could not run query: ' . mysql_error();  exit; }
>> $cov = mysql_fetch_row($result);
>>
>>
>> if (isset($cov[0]))
>>   {echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>";}
>> echo "<img src='http://mroldies.net/covers/$year/".$cov[1]."'>";
>>
>> On item  #1 in the table, the panel appears with the desired images as
>> wanted.
>> On item #2 image place holders appear because I do not have them online
>> yet.
>> I do not want to see the place holders if there is not an image.
>> What to use to do that?
> If the first one works and the second one doesn't, maybe you should just
> do them both like the first one?
>
>> Also, if you click on 1961, or any other year, and then any item in the
>> table, you will get a message below the videos stating the column does not
>> exist so it can't continue processing.
>> How can I bypass this when that database does not have that column?
> Again, check for zero rows being returned in your program and build code
> to handle that circumstance. die() is NOT your friend.
>
if (mysql_numrows($result)) // there is some date to process

...

else

// there isn't.
...

-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#9306

From"J.O. Aho" <user@example.net>
Date2013-05-13 20:10 +0200
Message-ID<avcokgFb7ihU1@mid.individual.net>
In reply to#9287
On 13/05/13 13:01, richard wrote:
> http://mroldies.net/showtable.php?year=1960
>
>
>
> $result = mysql_query("SELECT acover,bcover FROM A$year WHERE id =
> $number");
> if (!$result) { echo 'Could not run query: ' . mysql_error();  exit; }
> $cov = mysql_fetch_row($result);
>
>
> if (isset($cov[0]))
>   {echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>";}
> echo "<img src='http://mroldies.net/covers/$year/".$cov[1]."'>";
>
> On item  #1 in the table, the panel appears with the desired images as
> wanted.
> On item #2 image place holders appear because I do not have them online
> yet.
> I do not want to see the place holders if there is not an image.
> What to use to do that?

isset() will not work in this case, as both cells will always be set.
I recommend you try empty() which will give you indication if the cell 
is empty or not.

$value_to_use = empty($cov[0])?$cov[1]:$cov[0];
echo "<img src='http://mroldies.net/covers/$year/".$value_to_use."'>";


IMHO it's not good to echo things, build up what you want to do and echo 
out everything when you are finished, this way you get out only what you 
want to show to the user, as you can remove parts completely if they fail.


> Also, if you click on 1961, or any other year, and then any item in the
> table, you will get a message below the videos stating the column does not
> exist so it can't continue processing.
> How can I bypass this when that database does not have that column?

Don't know what you mean, didn't see any such message, but I guess that 
is a question to a javascript newsgroup.


-- 

  //Aho

[toc] | [prev] | [next] | [standalone]


#9319

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-05-13 23:43 +0100
Message-ID<kmrqad$gdk$1@news.albasani.net>
In reply to#9306
On 13/05/13 19:10, J.O. Aho wrote:
> On 13/05/13 13:01, richard wrote:
>> http://mroldies.net/showtable.php?year=1960
>>
>>
>>
>> $result = mysql_query("SELECT acover,bcover FROM A$year WHERE id =
>> $number");
>> if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }
>> $cov = mysql_fetch_row($result);
>>
>>
>> if (isset($cov[0]))
>>   {echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>";}
>> echo "<img src='http://mroldies.net/covers/$year/".$cov[1]."'>";
>>
>> On item  #1 in the table, the panel appears with the desired images as
>> wanted.
>> On item #2 image place holders appear because I do not have them online
>> yet.
>> I do not want to see the place holders if there is not an image.
>> What to use to do that?
>
> isset() will not work in this case, as both cells will always be set.
> I recommend you try empty() which will give you indication if the cell 
> is empty or not.
>
another trick I have used is to assign another variable at the mysql 
level so you can have a query that sets a flag..
select...if(isnull(bcover) 0,1) as bcoverflag...

I use that so see whether the database actually contains an image at 
all. So if bcoverflag is false, then I don't even attempt to display a 
non existent image

i.e. (cut from code that works)

$query=sprintf("select name, details, type, hour(time) as hour, 
minute(time) as minute, year(date) as year, monthname(date) as month, 
day(date) as day, if(isnull(picture1),0,1) as pic1flag, 
if(isnull(picture2),0,1) as pic2flag,if(isnull(picture3),0,1) as 
pic3flag from %s where id='%d'",$table,$id);
  $result=mysql_query($query);
     if(!$result || (mysql_numrows($result)==0)) // bad query or 
nonexistent data
         {
         echo("</div>\n");
         return; //nothing to see here. Move along now please.
         }
  ....

if(mysql_result($result,0,'pic1flag')) // have a picture 1
         {
         $url=sprintf('<IMG 
src="../send_eventpik.php?id=%d&picture=picture1&height=200&width=100&ie6fool=%d" 
alt="picture1" style="float:left; margin-right: 30px; margin-bottom: 
30px;">',$id,rand(5,25));
          }
(send_eventpik.php is a php script that sends a picture when called as a 
URL.

> $value_to_use = empty($cov[0])?$cov[1]:$cov[0];
> echo "<img src='http://mroldies.net/covers/$year/".$value_to_use."'>";
>
>
> IMHO it's not good to echo things, build up what you want to do and 
> echo out everything when you are finished, this way you get out only 
> what you want to show to the user, as you can remove parts completely 
> if they fail.
>
+1
>
>> Also, if you click on 1961, or any other year, and then any item in the
>> table, you will get a message below the videos stating the column 
>> does not
>> exist so it can't continue processing.
>> How can I bypass this when that database does not have that column?
>
> Don't know what you mean, didn't see any such message, but I guess 
> that is a question to a javascript newsgroup.
>
>
see the use of mysql_numrows() to not process nonexistent data.



-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#9308

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-05-13 19:54 +0000
Message-ID<kmrged$mqd$3@dont-email.me>
In reply to#9287
On Mon, 13 May 2013 07:01:46 -0400, richard wrote:

> What to use to do that?

Programming skills and logic.

Perhaps you could check that the returned elements contain some viable 
data after checking if they're set, and if they don't contain such 
expected viable data, then you could output something else?

Given:

$cov = mysql_fetch_row($result);

Then:

if ( isset( $cov[0], $cov[1] ) && is_string( $cov[0] ) && is_string( $cov
[1] ) && strlen( $cov[0] ) > 4 && strlen( $cov[1] ) > 4 ) {

// here you use $cov[0] and $cov[1] in the output

} else {

// here you have an alternative output

}

Now please note carefully:

The order of multiple tests in an if statement as shown above can be 
critical to prevent errors. Don't change it around!

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#9329

Fromrichard <noreply@example.com>
Date2013-05-14 17:38 -0400
Message-ID<1tje0v7f4cdfq.olb8wct8tuaq.dlg@40tude.net>
In reply to#9308
On Mon, 13 May 2013 19:54:53 +0000 (UTC), Denis McMahon wrote:

> On Mon, 13 May 2013 07:01:46 -0400, richard wrote:
> 
>> What to use to do that?
> 
> Programming skills and logic.
> 
> Perhaps you could check that the returned elements contain some viable 
> data after checking if they're set, and if they don't contain such 
> expected viable data, then you could output something else?
> 
> Given:
> 
> $cov = mysql_fetch_row($result);
> 
> Then:
> 
> if ( isset( $cov[0], $cov[1] ) && is_string( $cov[0] ) && is_string( $cov
> [1] ) && strlen( $cov[0] ) > 4 && strlen( $cov[1] ) > 4 ) {
> 
> // here you use $cov[0] and $cov[1] in the output
> 
> } else {
> 
> // here you have an alternative output
> 
> }
> 
> Now please note carefully:
> 
> The order of multiple tests in an if statement as shown above can be 
> critical to prevent errors. Don't change it around!

Thanks I'll give that one a try.

[toc] | [prev] | [next] | [standalone]


#9364

Fromrichard <noreply@example.com>
Date2013-05-15 16:23 -0400
Message-ID<195lftw1ts4is.1wz8p6f1a44my$.dlg@40tude.net>
In reply to#9308
On Mon, 13 May 2013 19:54:53 +0000 (UTC), Denis McMahon wrote:

> On Mon, 13 May 2013 07:01:46 -0400, richard wrote:
> 
>> What to use to do that?
> 
> Programming skills and logic.
> 
> Perhaps you could check that the returned elements contain some viable 
> data after checking if they're set, and if they don't contain such 
> expected viable data, then you could output something else?
> 
> Given:
> 
> $cov = mysql_fetch_row($result);
> 
> Then:
> 
> if ( isset( $cov[0], $cov[1] ) && is_string( $cov[0] ) && is_string( $cov
> [1] ) && strlen( $cov[0] ) > 4 && strlen( $cov[1] ) > 4 ) {
> 
> // here you use $cov[0] and $cov[1] in the output
> 
> } else {
> 
> // here you have an alternative output
> 
> }
> 
> Now please note carefully:
> 
> The order of multiple tests in an if statement as shown above can be 
> critical to prevent errors. Don't change it around!

if (isset($cov[0]) && is_string($cov[0]) && strlen(cov[0])>4)
  { echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>"; }

Returns a parse error of unexpected '['.
where did I screw up at?

I want to check both images seperately as I may have one set, but not both.

[toc] | [prev] | [next] | [standalone]


#9365

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-05-15 20:34 +0000
Message-ID<kn0rgl$8so$6@dont-email.me>
In reply to#9364
On Wed, 15 May 2013 16:23:35 -0400, richard wrote:

> if (isset($cov[0]) && is_string($cov[0]) && strlen(cov[0])>4)
>   { echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>"; }
> 
> Returns a parse error of unexpected '['.
> where did I screw up at?

I wrote: strlen( $cov[0] ) > 4
You wrote: strlen(cov[0])>4

You missed a $ in the "strlen( $cov[0] ) > 4" test. That missing "$" 
character is significant!

> I want to check both images seperately as I may have one set, but not
> both.

Not unreasonable

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#9367

Fromrichard <noreply@example.com>
Date2013-05-15 17:07 -0400
Message-ID<eww75rf2misb.e7lrwks9so3n$.dlg@40tude.net>
In reply to#9365
On Wed, 15 May 2013 20:34:30 +0000 (UTC), Denis McMahon wrote:

> On Wed, 15 May 2013 16:23:35 -0400, richard wrote:
> 
>> if (isset($cov[0]) && is_string($cov[0]) && strlen(cov[0])>4)
>>   { echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>"; }
>> 
>> Returns a parse error of unexpected '['.
>> where did I screw up at?
> 
> I wrote: strlen( $cov[0] ) > 4
> You wrote: strlen(cov[0])>4
> 
> You missed a $ in the "strlen( $cov[0] ) > 4" test. That missing "$" 
> character is significant!
> 
>> I want to check both images seperately as I may have one set, but not
>> both.
> 
> Not unreasonable

Thanks. I just couldn't see it for nuthin.

[toc] | [prev] | [next] | [standalone]


#9370

FromChristoph Becker <cmbecker69@gmx.de>
Date2013-05-15 23:18 +0200
Message-ID<kn0u09$du8$1@speranza.aioe.org>
In reply to#9367
richard wrote:
> Thanks. I just couldn't see it for nuthin.

You may consider using an editor with (better) syntax highlighting; that
should help spotting such typos more easily.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#9374

Fromrichard <noreply@example.com>
Date2013-05-15 19:07 -0400
Message-ID<v4hd79nxpfj8$.70pezduov2p.dlg@40tude.net>
In reply to#9370
On Wed, 15 May 2013 23:18:04 +0200, Christoph Becker wrote:

> richard wrote:
>> Thanks. I just couldn't see it for nuthin.
> 
> You may consider using an editor with (better) syntax highlighting; that
> should help spotting such typos more easily.

I use notepad++ for that reason.
What editor would know that YOU wanted $cov and not just cov?

[toc] | [prev] | [next] | [standalone]


#9376 — Syntax Highlighting (was: isset not working with select)

FromChristoph Becker <cmbecker69@gmx.de>
Date2013-05-16 01:33 +0200
SubjectSyntax Highlighting (was: isset not working with select)
Message-ID<kn1604$51g$1@speranza.aioe.org>
In reply to#9374
richard wrote:
> On Wed, 15 May 2013 23:18:04 +0200, Christoph Becker wrote:
> 
>> richard wrote:
>>> Thanks. I just couldn't see it for nuthin.
>>
>> You may consider using an editor with (better) syntax highlighting; that
>> should help spotting such typos more easily.
> 
> I use notepad++ for that reason.
> What editor would know that YOU wanted $cov and not just cov?

I am using Active State's Komodo Edit, and there "$cov" is highlighted
differently than "cov" (black vs. cyan in the default configuration).  I
assume there are other editors/IDEs around that offer this also (it
shouldn't be hard for the lexer to distinguish between the two cases);
maybe Notepad++ can be configured this way too.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#9383

FromTim Streater <timstreater@greenbee.net>
Date2013-05-16 08:27 +0100
Message-ID<timstreater-39C817.08274116052013@news.individual.net>
In reply to#9374
In article <v4hd79nxpfj8$.70pezduov2p.dlg@40tude.net>,
 richard <noreply@example.com> wrote:

> On Wed, 15 May 2013 23:18:04 +0200, Christoph Becker wrote:
> 
> > richard wrote:
> >> Thanks. I just couldn't see it for nuthin.
> > 
> > You may consider using an editor with (better) syntax highlighting; that
> > should help spotting such typos more easily.
> 
> I use notepad++ for that reason.
> What editor would know that YOU wanted $cov and not just cov?

Obviously the editor isn't gonna *know* that, just it will be more 
obvious when you do an eyeball scan, that you have $cov in purple (say), 
then again in purple, but over here where the third $cov should be it's 
in black, so that stands out.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#9369

Fromrichard <noreply@example.com>
Date2013-05-15 17:12 -0400
Message-ID<1j6pljoakm4p9$.rlhgdvtgdltb$.dlg@40tude.net>
In reply to#9365
On Wed, 15 May 2013 20:34:30 +0000 (UTC), Denis McMahon wrote:

> On Wed, 15 May 2013 16:23:35 -0400, richard wrote:
> 
>> if (isset($cov[0]) && is_string($cov[0]) && strlen(cov[0])>4)
>>   { echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>"; }
>> 
>> Returns a parse error of unexpected '['.
>> where did I screw up at?
> 
> I wrote: strlen( $cov[0] ) > 4
> You wrote: strlen(cov[0])>4
> 
> You missed a $ in the "strlen( $cov[0] ) > 4" test. That missing "$" 
> character is significant!
> 
>> I want to check both images seperately as I may have one set, but not
>> both.
> 
> Not unreasonable

Ok so the code still shows the place holders for both.

[toc] | [prev] | [next] | [standalone]


#9377

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-05-15 23:54 +0000
Message-ID<kn178g$8so$7@dont-email.me>
In reply to#9369
On Wed, 15 May 2013 17:12:36 -0400, richard wrote:

> On Wed, 15 May 2013 20:34:30 +0000 (UTC), Denis McMahon wrote:
> 
>> On Wed, 15 May 2013 16:23:35 -0400, richard wrote:
>> 
>>> if (isset($cov[0]) && is_string($cov[0]) && strlen(cov[0])>4)
>>>   { echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>"; }
>>> 
>>> Returns a parse error of unexpected '['.
>>> where did I screw up at?
>> 
>> I wrote: strlen( $cov[0] ) > 4 You wrote: strlen(cov[0])>4
>> 
>> You missed a $ in the "strlen( $cov[0] ) > 4" test. That missing "$"
>> character is significant!
>> 
>>> I want to check both images separately as I may have one set, but not
>>> both.
>> 
>> Not unreasonable
> 
> Ok so the code still shows the place holders for both.

I'm not 100% sure on how you have implemented the code.

Let me expand on the previous example - this generates separate images 
for the two covers:

Given:

$cov = mysql_fetch_row($result);

Then:

if ( isset( $cov[0] ) && is_string( $cov[0] ) && strlen( $cov[0] ) > 4 ) {

// here you use $cov[0] in the output

echo "<img src='http://mroldies.net/covers/{$year}/{$cov[0]}'>";

/* --- in here --- */

} else {

// here you have an alternative output for $cov[0]

echo "Image 1 Not Available"

}

/* --- from here --- */
if ( isset( $cov[1] ) && is_string( $cov[1] ) && strlen( $cov[1] ) > 4 ) {

// here you use $cov[1] in the output

echo "<img src='http://mroldies.net/covers/{$year}/{$cov[1]}'>";

} else {

// here you have an alternative output $cov[1]

echo "Image 2 Not Available"

}
/* --- to here --- */

If however you only want the second image to display if the first image 
is also present, then all the lines from the comment "/* --- from here 
--- */" to the comment "/* --- to here --- */" should be moved up to the 
place held by the comment "/* --- in here --- */"

You might in that case want to change the text output "Image 1 Not 
Available" to "Images Not Available"

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#9368

FromTim Streater <timstreater@greenbee.net>
Date2013-05-15 22:15 +0100
Message-ID<timstreater-25473E.22151315052013@news.individual.net>
In reply to#9364
In article <195lftw1ts4is.1wz8p6f1a44my$.dlg@40tude.net>,
 richard <noreply@example.com> wrote:

> On Mon, 13 May 2013 19:54:53 +0000 (UTC), Denis McMahon wrote:
> 
> > On Mon, 13 May 2013 07:01:46 -0400, richard wrote:
> > 
> >> What to use to do that?
> > 
> > Programming skills and logic.
> > 
> > Perhaps you could check that the returned elements contain some viable 
> > data after checking if they're set, and if they don't contain such 
> > expected viable data, then you could output something else?
> > 
> > Given:
> > 
> > $cov = mysql_fetch_row($result);
> > 
> > Then:
> > 
> > if ( isset( $cov[0], $cov[1] ) && is_string( $cov[0] ) && is_string( $cov
> > [1] ) && strlen( $cov[0] ) > 4 && strlen( $cov[1] ) > 4 ) {
> > 
> > // here you use $cov[0] and $cov[1] in the output
> > 
> > } else {
> > 
> > // here you have an alternative output
> > 
> > }
> > 
> > Now please note carefully:
> > 
> > The order of multiple tests in an if statement as shown above can be 
> > critical to prevent errors. Don't change it around!
> 
> if (isset($cov[0]) && is_string($cov[0]) && strlen(cov[0])>4)
                                                  ~~~~~~~~
Missing $ sign.

>   { echo "<img src='http://mroldies.net/covers/$year/".$cov[0]."'>"; }
> 
> Returns a parse error of unexpected '['.
> where did I screw up at?
> 
> I want to check both images seperately as I may have one set, but not both.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web