I have a mysql query for a field that is a long text but the query does not return anything.

I have tried replacing the field with a 'short' text to see if it would work. It did return the short text. It just doesn't when I turn it back to the long text

Here is my php code

$sql = "SELECT * FROM fact WHERE id = ".$id;
$tmp = $this->con->query($sql); 
return $tmp->fetch_assoc();

And here is my mysql table

-- Dumping structure for table tb_system.fact
CREATE TABLE IF NOT EXISTS `fact` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fact` longtext NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1;

-- Dumping data for table tb_system.fact: ~2 rows (approximately)
/*!40000 ALTER TABLE `fact` DISABLE KEYS */;
INSERT INTO `fact` (`id`, `fact`) VALUES
    (1, 'People with TB disease can pass TB germs to others. But if they take the TB medicine the right way, they won’t pass TB germs to others'),
    (2, 'To reduce exposure in households, houses should be adequately ventilated'),
    (3, 'To reduce exposure in households, while patients are smear positive, they should spend as little time as possible in places with large crowds'),
    (4, 'To reduce exposure in households, while patients are smear positive, they should spend as much time as possible outdoors'),
    (5, 'To reduce exposure in households, while patients are smear positive, they should, if possible, sleep alone in a separate, adequately ventilated room'),
    (6, 'To reduce exposure in households, while patients are smear positive, they should spend as little time as possible on public transport'),
    (7, 'If you forget your medicine more than one time, call your doctor or healthcare provider BEFORE you take the next dose'),
    (8, 'If you miss one dose or forget to take the pills ONE TIME, don’t worry. Just take the next dose when you are scheduled'),
    (9, 'Tip to stay on track with medicine plan from past tb patient James: “What kept me on track? I put a note in my wallet next to a picture of my family that said “James—stay healthy for your family.”'),
    (10, 'Taking medicine each day can be difficult. Remind yourself you are staying on your treatment plan to kill all the TB germs. You have done other tough things in your life and you can do this too!'),
    (11, 'You can pass TB germs to your family, friends, and others around you if you don’t take TB medicine the right way'),
    (12, 'You will need to take TB medicine correctly for at least 6 months to be cured'),
    (13, 'TB germs die very slowly. Staying on your medicine the way you are supposed to is the only way to cure TB'),
    (14, 'TB germs are strong and take a long time to die. Complete the treatment and take ALL of the doses of medicine to be cured of TB'),
    (15, 'Make sure you tell your doctor if you have HIV/AIDS or any other health problem. Sometimes taking certain medicines together can make you have a reaction'),
    (16, 'If you stop taking medicines for TB disease early or do not take them the right way, you can become sick again and stay sick for a longer time'),
    (17, 'If you stop taking medicines early or do not take them the right way, the medicines can stop working and you may have to take different medicines that have more side effects'),
    (18, 'If you stop taking medicines early or do not take them the right way, even the new medicines may not work to cure the TB'),
    (19, 'If you stop taking medicines early or do not take them the right way, you can pass TB germs on to others again'),
    (20, 'Keep windows open in your home, if possible, until your doctor says you cannot pass TB germs to others');
/*!40000 ALTER TABLE `fact` ENABLE KEYS */;

I expect the output to be the actual 'fact' value which is the long text

1 Answers

-1
K. P. On

The following code: $sql = "SELECT * FROM fact WHERE id = ".$id; is not correct, the variable should be inside the query, between the quote marks like this:

$sql = "SELECT * FROM fact WHERE id = '$id'";

Also, the return statement doesn't actually print the result, you need to use echo for it.