mysql - php replace database result with an image -


this first time have ever posted question. newbie, , hope formatting correct in message. love stack overflow. has helped me through many challenging situations. 1 has me stymied.

i replace mysql database result image. have plant database i'm querying show lists of plants. results table consists of plant type, botanical name, common name, , whether native plant.

the result native plant comes in database letter 'y' (for yes). replace 'y' image of oak leaf. code i'm using displays oak leaf on plants, not ones native plants.

what do? feel need insert if statement in while loop, never works when try it. i've tried tons of different solutions few days now, , ask this.

here's latest code i've got displays image every plant, not natives:

while ($row = mysqli_fetch_array($r, mysqli_assoc)) {      $native_image = $row['native'];     $image = $native_image;     $image = "images/oak_icon.png";      echo '<tr><td>' .          $row['plant_type'] .       '</td><td>' .          $row['botanical_name'] .                $row['common_name'] .                '</td><td>' .          $image .       '</td></table>';   } 

i hope understood question.

some of rows in mysql have $row['native'], equals 'y'. if so, on right way - have put if statement in loop. try it

while ($row = mysqli_fetch_array($r, mysqli_assoc)) {     if ($row['native'] == "y") {         //we show our image         $image = "images/oak_icon.png";     } else {         //we don't have show our image         $image = "";     }       echo '<tr><td>' .          $row['plant_type'] .       '</td><td>' .          $row['botanical_name'] .            $row['common_name'] .                '</td><td>' .          $image .       '</td></table>';    } 

and img tag? =) future: in projects, if want save information image, belongs row in mysql, save name of picture, has be, , if not, save name of empty 1x1 png image (usual "blank.png"). if put blank.png in img tag, has fixed height , width, img takes place on page.

i hope helped you, , first answer! =)

p.s. sorry english...


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -