FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » isset not working with select
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: isset not working with select [message #181374 is a reply to message #181361] Mon, 13 May 2013 22:43 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
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=10 0&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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: mkdir no such file or directory
Next Topic: makes searching and booking applications airfares
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 05:51:48 GMT 2024

Total time taken to generate the page: 0.03895 seconds