I am trying to create website that has questions with drop down options. Do I need to know MySQL for that?

Dani AI

Generated

asked whether MySQL is required to build a page with question dropdowns. correctly pointed out a manual-HTML approach works for small, static sets; recommended a database for maintainability. The right choice depends on how dynamic the questions must be and whether you need to store or manage responses.

If questions are fixed and rarely change, static HTML or a small JSON file loaded by JavaScript is simplest. If you need an admin interface, to save user answers, randomize or paginate questions, support many users, or run queries and reports, use a database (MySQL, PostgreSQL, or lightweight SQLite). SQLite is a good low-overhead alternative for single-server sites (SQLite docs). For client-side loading, the Fetch API is useful (Fetch API).

Example patterns to apply immediately:

<?php
$pdo = new PDO('mysql:host=localhost;dbname=survey;charset=utf8mb4','user','pass',
    [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
foreach ($pdo->query('SELECT id, label FROM options WHERE question_id=1') as $row) {
    echo '<option value="' . htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8') . '">' .
         htmlspecialchars($row['label'], ENT_QUOTES, 'UTF-8') . '</option>';
}
?>
fetch('/data/options.json')
  .then(r => r.json())
  .then(list => {
    const sel = document.getElementById('q1');
    list.forEach(i => { const o = document.createElement('option'); o.value = i.id; o.textContent = i.label; sel.appendChild(o); });
  });

Notes: always escape output to prevent XSS, use prepared statements for any user input, test queries separately, and start with JSON/static files if unsure—migrating to MySQL later is straightforward. For PHP DB patterns see the PDO manual (PHP PDO).

Recommended Answers

All 2 Replies

If you update your questions manually in the HTML you may not need mysql.
It depends on your goals.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.