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.