Jump to content

PHP / SQL problem


tr3gi

Recommended Posts

Hi

 

Here's my problem:

 

I have a database full of staff members. My problem is that some of the staff members have for example medical training and others don't. When I'm creating the list I don't know how to display when the staffmember has medical training.

Hope it makes sense..

 

Here's the lame code :) I'm an real beginner in PHP so the code might be totally wrong ;)

 

<?php
$sql = "SELECT id, firstname, lastname, medic FROM staff";
$medic = "SELECT id, firstname, lastname, medic FROM staff where medic='1'";
$query = mysql_query($sql);
$query_medic = mysql_query($medic);

while($row = mysql_fetch_array($query))
{
if ($query_medic)
{
echo "{$row['firstname']} {$row['lastname']}<img src=\"img/redcross.jpg\"><br />";
}
else
{
echo "{$row['firstname']} {$row['lastname']}<br />";
}
}
?>

Can anyone help?

thanks

Link to comment
https://forums.phpfreaks.com/topic/94869-php-sql-problem/
Share on other sites

Please use code tags.

 

<?php

$sql = "SELECT id, firstname, lastname, medic FROM staff";
$medic = "SELECT id, firstname, lastname, medic FROM staff where medic='1'";
$query = mysql_query($sql);
$query_medic = mysql_query($medic);

while($row = mysql_fetch_array($query))
{
if ($query_medic)
{
echo "{$row['firstname']} {$row['lastname']}<img src=\"img/redcross.jpg\">";
}
else
{
echo "{$row['firstname']} {$row['lastname']}";
}
}

?>

 

THIS is the answer:

 

<?php

$sql = "SELECT id, firstname, lastname, medic FROM staff";
$query = mysql_query($sql);

while($row = mysql_fetch_array($query))
{
  echo "{$row['firstname']} {$row['lastname']}";
  
  if($row['medic'] != "" AND isset($row['medic']))
  {
    echo "<img src=\"img/redcross.jpg\">";
  }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/94869-php-sql-problem/#findComment-485947
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.