Jump to content

jamesmfarrow

New Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by jamesmfarrow

  1. I am new to php and 'giving it a go' - no doubt I will be here again asking daft questions.. Thanks to everyone who took the time to help me - it is appreciated!!
  2. Strider64 - thanks very much!! I used your solution and adapted it slightly to fit what I needed and it works!! The query results are returned. Thanks again!
  3. Hello everyone - I have picked dup a book on php and SQL and have been quaking through it. I have come across a problem with a foreach statement that I can not resolve. Any help and advice is greatly appreciated! <?php try { $pdo = new PDO('mysql:host=localhost;dbname=ijdb; charset=utf8', 'ijdbuser', 'mypassword'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = 'SELECT `joketext` FROM `joke`'; $result = $pdo->query($sql); while ($row = $result->fetch()) { $jokes[] = $row['joketext']; } } catch (PDOException $e) { $output = 'Unable to connect to the database server: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); } include __DIR__ . '/../templates/jokes.html.php'; and the other file <!doctype html> <html> <head> <meta charset="utf-8"> <title>List of jokes</title> </head> <body> <?php if (isset($error)): ?> <p> <?php echo $error; ?> </p> <?php else: ?> <?php foreach($jokes as $joke ): ?> <blockquote> <p> <?php echo htmlspecialchars($joke, ENT_QUOTES, 'UTF-8') ?> </p> </blockquote> <?php endforeach; ?> <?php endif; ?> </body> </html>
×
×
  • 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.