Skip to main content
Participant
December 12, 2009
Answered

2 questions for MYSQL database>frontend Null values and Compass how to's

  • December 12, 2009
  • 1 reply
  • 343 views

Hi all,

I have a dreamweaver created frontend that pulls data from a MYSQL database and have come across a couple of sticking points. The database has multiple tables for variables and a central table per user record. I hope I don't need to go into too much detail about the who's, where's, when's and from's as I hope I have most of these bases covered. Basically I am trying to pull data from these MYSQL tables and produce the following;

1) If a value = 0 (Zero or Null) then the text "N/A" should show on the website. The complication with this is that a record is pulled from the main table that pulls the relevant text value from another table (e.g. MAINTABLE_CARMAKEDATA = 1, CARMAKETABLE.ID=1 Therefore CARMAKE = "Ford"). Without entering a new value in the database as a default value e.g. N/A =4 (The main MYSQL field is an integer value that I use to call another table with the  relevant value), is there a way within Dreamweaver to ask "IF VALUE = 0 or NONE then display "N/A" (or any other text).

2) I have degrees in the database to show wind direction. How best would I show the direction of wind in a graphical format? I don't have to be too exact (e.g. 0 - 45 degrees would show a picture of an arrow pointing NorthEast, 0 degrees would be North, 180 degrees would be South, etc...), but if a extact method exists all the better (As long as users don't have to download plug ins - Thinking it might be best to have 8 images e.g. N, NE, E, SE, S, SW, W, NW). The database holds an exact value so I might need to say IF DEGREES = 0 - 45 THEN SHOW "N-NE.jpg".

I hope that these questions are simple to answer (and make sense)?

Looking forward to any guidance that can be given.

PaladinDC

This topic has been closed for replies.
Correct answer David_Powers

This thread has been moved to the Dreamweaver Application Development forum, which deals with PHP/MySQL and other server-side issues.

The answer to both your questions lies in the use of PHP conditional logic.

<?php

if ($row_recordsetName['CARMAKE'] == 0) {

  echo 'N/A';

} else {

  echo $row_recordsetName['CARMAKE'];

}

?>

In the case of your compass points, you could create a PHP function like this:

<?php

function compassPoint($val) {
  if (($val >= 0 && $val < 30) || $val >= 330) {
    $dir = 'N';
  } elseif ($val >= 30 && $val < 60) {
    $dir = 'NE';
  } elseif ($val >= 60 && val < 120) {
     $dir = 'E';
  } elseif ($val >= 120 && val < 150) {
     $dir = 'SE';
  } elseif ($val >= 150 && val < 210) {
     $dir = 'S';
  } elseif ($val >= 210 && val < 240) {
     $dir = 'SW';
  } elseif ($val >= 240 && val < 300) {
     $dir = 'W';
  } elseif ($val >= 300 && val < 330) {
     $dir = 'NW';
  }
  echo '<img src="/images/' . $dir . '.jpg" alt="' . $dir .'" />';
}
?>

You can then display the image like this:

<?php compassPoint($row_recordsetName['direction']; ?>

1 reply

David_Powers
David_PowersCorrect answer
Inspiring
December 13, 2009

This thread has been moved to the Dreamweaver Application Development forum, which deals with PHP/MySQL and other server-side issues.

The answer to both your questions lies in the use of PHP conditional logic.

<?php

if ($row_recordsetName['CARMAKE'] == 0) {

  echo 'N/A';

} else {

  echo $row_recordsetName['CARMAKE'];

}

?>

In the case of your compass points, you could create a PHP function like this:

<?php

function compassPoint($val) {
  if (($val >= 0 && $val < 30) || $val >= 330) {
    $dir = 'N';
  } elseif ($val >= 30 && $val < 60) {
    $dir = 'NE';
  } elseif ($val >= 60 && val < 120) {
     $dir = 'E';
  } elseif ($val >= 120 && val < 150) {
     $dir = 'SE';
  } elseif ($val >= 150 && val < 210) {
     $dir = 'S';
  } elseif ($val >= 210 && val < 240) {
     $dir = 'SW';
  } elseif ($val >= 240 && val < 300) {
     $dir = 'W';
  } elseif ($val >= 300 && val < 330) {
     $dir = 'NW';
  }
  echo '<img src="/images/' . $dir . '.jpg" alt="' . $dir .'" />';
}
?>

You can then display the image like this:

<?php compassPoint($row_recordsetName['direction']; ?>