Re: Can't figure out a difficult conditional statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



if ('$picture_filename1' !== "('<NULL>' or ''")" )

!== means equal and same variable type.

NULL in the datatbase returns null in the variable. Not the string 'NULL' and not empty string (''), but actual null and I'm not sure what you mean with the <> around NULL.

Do it like this:

if ($picture_filename1)

Is the easiest way, or if you want to make sure that garbage in the field doesn't trigger it, do this:

if (stristr($picture_filename1, '.jpg'))

Sent from my magic iPhone,
Keith Davis 214-906-5183

On Jun 3, 2010, at 10:48 PM, "Bill Mudry" <billmudry@xxxxxxxxxx> wrote:

You would think that a relatively simple conditional statement should be quite easy to get working --- but after many retries and reworks, this has got me stumped. I look forward to being shown why and (even better) what actually will work.

First, lets give everyone access to the knowledge base that I am building so you can
see what users now see versus what I want them to see.
The site URL is http://www.prowebcanada.com/taxa/.

However, the data pages are within a Frames environment which makes it hard to read what each page really is. Therefore I will escape these frames so I can list the actual files I am
working on and make it easier to follow and understand.

Lets say a reader has chosen to view information on the wood genus of "acer" (ie. all maples).
The URL would be http://www.prowebcanada.com/taxa/displaygenera2.php?&genus_name=Acer
and information on that genus would show on the top half of the page. Ignore that and look at
the second part of the page under "Woody Species of Acer".

The Objective - Notice how a reader can choose a particular Acer species (ie. Maple) and let it follow out to a data page that would show data on the chosen wood. If you would have chosen Acer barbatum, the URL for this data page works out to a successful:
  http://www.prowebcanada.com/taxa/displayspecies.php?&species_name=Acer%20barbatum

In recent times, I have been able to add code to show off actual scans of a limited number of woods ---- including a decent scan for Acer barbatum. Showing off actual scans on a species
data page is working quite fine now.

Now go back to the genus page where we started from. What I am trying to do is to have the code look ahead to show a small camera icon in front of the species listings but ONLY for those that will offer a scan (ie. photo) of each wood that has one displaying. I do not have
scans for every wood.

You should think that should be an easy job to set up but after reading up and many tries with different configurations, I still cannot seem to get this to work right. At this point, I don't know why. Either I get no camera icons at all OR icons in front of every listing when they should
show up only where there are photos installed.

The photos are stored as a path and file name in the picture_filename1 column of table 'species'. The cells in this column either have a scan filename and path to the file name stored or a "<NULL>". The camera icon should show only if there is a valid (.jpg) picture stored.

I have echoed all the scan file names for now:
       - to show that they do show up and that is not the problem
       - to show which species have photos and which don't
- and finally, to show that the camera icon is showing up even when there is a NULL
         stored. That is what should not happen.
Once this is working properly I would comment out or even erase that statement

Assume a successful connection to the database (named taxa by the way). No use displaying the code for showing data on one genus. That part is working fine, so I will list the code for the lower part. Just so the code is easier to understand, the loop not only displays all the woody species but has provisions to start another column if the column gets too large. The code I am
trying to develop to work properly is inside that loop.

..... Where it seems like a file name is not showing, it actually is but showing a NULL is the same as showing ---- nothing(!). Just ignore all the statements commented out. They have all been efforts during earlier development and debugging. I can clean that up some later.

Here, then is the code I have so far (that should work and does not).

As the code will show, $showcamera is set up to display one instance of a camera icon but it is in a loop that shows all species of a genus.

Thanks in advance for your suggestions,

Bill Mudry,

=====================================================================
< Upper code left out for relevance and brevity>

/// /// /// /// /// /// /// ////////////////////////////////////////////////////////////////////
//           LISTING SPECIES OF THE CHOSEN WOODY GENUS
//           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// A query now runs to display relevant woody species of the chosen genus. Choosing a // species will take the user to a page detailing information on the chosen species.
//
/// /// /// /// /// /// /// ////////////////////////////////////////////////////////////////////


echo "<H2 align = 'center'>Woody Species of $genus_name</H2>";
       //echo "\$generaID is - $generaID";

echo "<H4 align='center'>Each link leads to more information on the chosen botanical species</h4>";

mysql_connect($hostname, $username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db(taxa)
       or die(mysql_error());

$query5 = "SELECT * from species where generaID = '$generaID' order by species_name";

$result5 = mysql_query($query5)
       or die(mysql_error());

//var_dump($result5);
$l=-0;
$m=1;



echo "<table border='3' bgcolor='ivory' cellpadding='20' align='center'><tr>";
echo "<td valign='top' style='white-space: nowrap'>";


/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ////////////////////////////////////////////////////////////////////// // Now as each species is generated in a list of the woody species of the chosen genus, we want to show a small camera // icon (as images/cameraicon01.jpg) in front of each listed species ONLY if the species has a scan or photo // stored in the 'species' table under column 'picture_filename1'. The program has to look ahead in the 'species' // table for all of them to see which ones should and which should not have a camera icon beside them. The whole // idea is to let readers be informed on which choices include a scan or photo before choosing. If there is no // null or empty value in that location, it is assumed that there is a scan to view. /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// //////////////////////////////////////////////////////////////////////

$camera_icon = "images/cameraicon01.jpg";
$showcamera = "<img src = $camera_icon>...";



if($result5) {
   while($row5 = mysql_fetch_array($result5))
          {
               //echo "\$genus_name is - $genus_name";
       extract($row5);
               //Echo "extract($row5)";
               //Echo "\$row5 is - %row5";
               $l++; // counter to set maximum columns lengths

       //echo "'\$m is - '.$m";

               if ($l>60)
                       {
                       echo "</td>";
echo "<td valign='top' style='white-space: nowrap'>";
                       $l=0;
                       };

               $picture_filename1 = trim($picture_filename1);

echo "$picture_filename1<br />"; // Debug statement to show which entries do have photos attached.

       // Here is the main conditional statement area:
               if ('$picture_filename1' !== "('<NULL>' or ''")" )
                  {
echo $showcamera; // the only time it should show a camera icon
                       }
               else if ('$picture_filename1' == "('<NULL>' or ''")
                       echo "No scan<br />";

echo '<a href="displayspecies.php?&species_name='. $species_name.'">';
               //echo "$picture_filename1<br />";


               echo "$m - $species_name";
               echo"</a><br>\n";
               $m++; // counter to increment for the next species


           }
}
   else echo "No species found";

       $species_name="";
echo "<br></td></tr></table><br>";


// End of display table.
   Echo "<br><hr width='400'>";

echo "<H3 align = 'center'>End of Listing for Woody Species of $genus_name</H3>";

echo "</body>";
echo








This message (including any attachments) may contain confidential or otherwise privileged information and is intended only for the individual(s) to which it is addressed. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secured or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message or that arise as a result of e-mail transmission. If verification is required please request a hard-copy version from the sender.

www.pridedallas.com


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux