0%

💬 Prompt piemēri web izstrādē

Labs prompt = labs rezultāts. Šeit atrodami konkrēti prompt piemēri HTML, CSS, JavaScript, PHP, SQL un Python uzdevumiem — vienkārši nokopē, pielāgo savam projektam un sūti ChatGPT, Claude vai Copilot. Visi piemēri ir angļu valodā — tā tiek patērēti mazāk tokeni, un MI sniedz precīzākas atbildes.

ai

Kā izskatās labs prompt?

Efektīvs prompt parasti satur 4 elementus:

  • Loma / konteksts — "You are an experienced PHP developer…"
  • Uzdevums — precīzi un konkrēti
  • Ierobežojumi — valoda, versija, bibliotēkas, stils
  • Izvades formāts — "Reply with code only", "Explain each line"

🌐 Raksti promptus angliski — taupīsi tokenus

Latvisks teksts aizņem ~2× vairāk tokenu nekā angļu ekvivalents, jo latviskas rakstzīmes (ā, ē, ī, ū, ķ, ļ, ņ, ģ, č, š, ž) bieži tiek sadalītas vairākos tokenus. Mazāk tokenu nozīmē:

  • Zemākas izmaksas maksas API lietošanā
  • Lielāks konteksta logs — vairāk vietas kodam un paskaidrojumiem
  • Precīzāki atbildes — MI ir apmācīts galvenokārt uz angļu datiem

Lai saņemtu atbildi latviski, pievieno beigās: Respond in Latvian.

You are an experienced PHP 8.2 developer. Write a function that validates a Latvian national ID number (personas kods). Use only vanilla PHP without external libraries. Add PHPDoc comments and 3 usage examples.

HTML / CSS prompt piemēri

Write a semantically correct HTML5 structure for a tutorial website. The page must have: header with navigation, aside sidebar with a list, main content with article list, footer with copyright. Use only semantic elements (nav, section, article, aside, etc.). Do not add CSS — HTML only. Help me with CSS Flexbox. I have a nav element with a list (ul > li > a). Requirements: - Horizontal layout on large screens - Vertical layout on mobile (max-width: 768px) - Active item gets an orange bottom border Reply with CSS code only, no HTML. Create a CSS Grid layout for a card grid: - 3 columns on desktop (>1024px) - 2 columns on tablet (768px–1024px) - 1 column on mobile (<768px) - 16px gap between cards - Cards with equal height per row Use CSS custom properties for breakpoints. Write a CSS animation for a button that: 1. Changes background from #dc6b2f to #b45220 on hover 2. Slightly scales up (scale 1.03) on hover 3. Shows a "loading" spinner after click (button gets class .loading) Use CSS transitions and @keyframes. No JavaScript.

JavaScript prompt piemēri

Write vanilla JavaScript (no jQuery) that: - On page load, finds all elements with class .code-block - Adds a "Copy" button to the top-right corner of each - On click, copies the code text to clipboard - Button shows "Copied! ✓" for 2 seconds Use async/await Clipboard API. Write a JavaScript function fetchTopics(url) that: - Makes a GET request to the given URL - Expects a JSON response with structure: { data: [...], total: number } - Renders each item from the data array as <li> in a list with id="topics-list" - Shows a spinner element with id="spinner" while loading - On error, displays the message in an element with id="error-zone" Use try/catch error handling. Write a JavaScript validation script for a registration form. Form (id="register-form") has fields: name, email, password, password2. Validation rules: - Name: at least 2 characters, letters and hyphens only - Email: valid format - Password: at least 8 characters, 1 digit, 1 uppercase letter - Password2: must match password Show errors below each field in .field-error elements. Do not submit the form if there are errors. Vanilla JS only.

PHP prompt piemēri

Write a PHP 8.2 class Database that: - Uses PDO to connect to MySQL - Implements the Singleton design pattern (single instance only) - Contains methods: query($sql, $params), fetchAll($sql, $params), fetchOne($sql, $params), execute($sql, $params) - All methods use prepared statements - Throws DatabaseException on error Use constructor property promotion and PHP 8 named arguments. Add a comment explaining each method. Write a PHP script for contact form processing. Form sends POST: name (string), email (email), message (text). The script must: 1. Validate all fields (name 2–50 chars, valid email, message 10–500 chars) 2. Sanitize input with htmlspecialchars and trim 3. Save to database in table "contacts" (PDO, prepared statements) 4. Send a confirmation email with PHP mail() or PHPMailer 5. Return JSON {"status": "ok"} or {"status": "error", "message": "..."} Use PHP 8.1+. No external frameworks. Create a simple PHP user authentication system: - login.php: form + handler (session_start, password check with password_verify) - logout.php: session_destroy + redirect - auth_check.php: include file that redirects to login.php if no session - Users stored in MySQL table users (id, email, password_hash, created_at) Use PDO. Hash passwords with password_hash(PASSWORD_BCRYPT). Protect against session fixation with session_regenerate_id.

SQL / MySQL prompt piemēri

Create a MySQL database schema for a learning platform (similar to Webpamati.lv). Required tables: - users (registered users) - topics (learning topics with categories) - progress (which user completed which topic) - comments (user comments on topics) Use: INT AUTO_INCREMENT, VARCHAR, TEXT, BOOLEAN, TIMESTAMP DEFAULT CURRENT_TIMESTAMP. Add FOREIGN KEY constraints with ON DELETE CASCADE. Create INDEX on frequently queried fields. Write a MySQL query that returns the TOP 5 authors by comment count in the last 30 days. Tables: users (id, name, email), comments (id, user_id, topic_id, text, created_at). Result must include: user name, first 3 chars of email + "***", comment count. Show only users with at least 3 comments. Sort descending by comment count. This MySQL query is slow (5+ seconds) on a 500,000-row table: SELECT u.name, COUNT(k.id) as total FROM comments k LEFT JOIN users u ON k.user_id = u.id WHERE k.created_at > DATE_SUB(NOW(), INTERVAL 7 DAY) GROUP BY k.user_id ORDER BY total DESC; Explain why it is slow and suggest optimization with INDEX. Show an explanation of the EXPLAIN output.

Python / Flask prompt piemēri

Write a Flask REST API with the following endpoints: GET /api/topics → all topics (JSON array) GET /api/topics/<id> → single topic by ID POST /api/topics → new topic (Body: {title, description, category}) PUT /api/topics/<id> → update topic DELETE /api/topics/<id> → delete topic Use Flask-SQLAlchemy ORM with SQLite for development. Add API key authentication (X-API-Key header). Return JSON with HTTP status codes (200, 201, 404, 401). No external auth libraries — Flask and SQLAlchemy only. Write a Python script using BeautifulSoup4 and requests that: - Loads page HTML from a given URL - Extracts all article headings (h2 elements with class .article-title) - For each heading also retrieves the link (href) and publication date (time elements) - Saves results to a CSV file with columns: title, url, date - Handles errors: timeout, 404, connection error Use Python 3.11+.

Debugošanas prompt piemēri

PHP returns this error: "Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails" My code: [paste the problematic code fragment] Explain: 1. What this error means 2. Why it occurs in my case 3. How to fix it 4. How to avoid such errors in the future Review this PHP code for security vulnerabilities: [paste code] Check for: - SQL injection - XSS (Cross-Site Scripting) - CSRF - Password storage (is it hashed?) - Sensitive data exposure in error messages - Insufficient input validation For each issue found, show a fixed version. This PHP code is slow — takes 4 seconds to load 1000 records. Find the N+1 query problem and suggest a fix: [paste code with database queries] Show: 1. Where the N+1 problem occurs 2. Optimized version with JOIN or eager loading 3. How many database queries there were before and after the fix

Ātrie prompt paraugi (kopēšanai)

Šos prompt vari tūlīt adaptatīvi izmantot — aizstāj [...] ar savu kodu/uzdevumu:

Explain this [PHP/JS/Python/SQL] code line by line: [paste code] Respond in Latvian. Convert this [PHP] code to [Python/JavaScript]: [paste code] Keep the same logic but use the target language's idioms. Write unit tests for this function (use [PHPUnit/Jest]): [paste function] Cover: normal case, edge cases, error case. Improve the readability of this code without changing the logic. Use [PHP 8.2] best practices: named arguments, null coalescing, match expression, etc. [paste code] Write a MySQL CREATE TABLE for: Entity: [name] Fields: [list fields with types] Related to tables: [other tables] Add INDEX and FOREIGN KEY constraints.