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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.