Jump to content

omardavinci

Members
  • Posts

    32
  • Joined

  • Last visited

Posts posted by omardavinci

  1. Nowadays, it seems that frameworks are a best environement for advanced developers. On the other hand, it could be argued that they really are not necessary when you develop some website in php. However, this environements speed up a lot the appearing of many projects. So my question is: You recomend some novice developer to use frameworks? Any suggestions or dissapointments are good received. Thanks in advance.

  2. At first i create the form very easy with php:

     

     

    $content = '
    <h4>Title 1</h4>
    <form method="POST">
    <table>
    <tr>
    <td><input id ="1" type="text" name="valueToSearch" placeholder="Value To Search"></td><br><br>
    </tr>

    <tr><td><input type="submit" name="search" value="Filter"></td></tr>
    </form></table>

    <br>
    '
    ;

    Obviously since if(isset[$_POST]) i did the query like this:

     

     

    $query = "SELECT id FROM `user` WHERE CONCAT(`id`) LIKE '%".$valueToSearch."%'";

    But in my case i want to update $articles ($articles are the articles ordered by pages), i mean this:

     

     

    $page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
    $perPage = 2;
    //Positioning
    $start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
    $art = $database_connection->query("SELECT id FROM user");
    //Query
    $articles = $database_connection->prepare("SELECT id FROM user LIMIT $start,$perPage");

    $articles->execute();
    $articles = $articles->fetchAll();

    $resultado = $database_connection->query("SELECT COUNT(*) AS total FROM user");
    $fila = $resultado->fetch(PDO::FETCH_ASSOC);
    $total = $fila["total"];
    $pages = ceil($total/$perPage);

    In conclusion, my question is very short. how i can update $articles when someone use filter to filter the table. In other words, i am trying to search some way to update $articles and i am little lost. Thanks in advance.

  3. Hi i am trying to do a simple pagination in php but when i try for example go to some page like localhost/page=1 i get this result:The requested URL /www/page=2 was not found on this server. Obviously this is because i did some mistake in the code. I share with members the php and html file for if someone has some suggestion. Thanks in advance:

     

    html:

     

    <!DOCTYPE html>

    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title><?php echo $title; ?></title>
            <link rel="stylesheet" type="text/css" href="Styles/Stylesheet.css" />
        </head>
        <body>
            <div id="wrapper">
                <div id="banner">             
                </div>
                
                <nav id="navigation">
                    <ul id="nav">
                        <li><a href="index.php">Home</a></li>
                        <li><a href="tool.php">Coffee</a></li>
                        <li><a href="manager.php">Shop</a></li>
                        <li><a href="#">About</a></li>
                    </ul>
                </nav>
                
                <div id="content_area">
                    <?php
                    require_once("tool.php");
                    foreach ($articles as $article):
                        echo $article['id'];
                    endforeach;?></br><?php
                    for($x=1;$x<=$pages;$x++):?>
                        <a href="page=<?php echo $x;?>"><?php echo $x;?></a>
                  <?php  endfor;?>
                </div>
                
                <div id="sidebar">
                    
                </div>
                
                <footer>
                    <p>All rights reserved</p>
                </footer>
            </div>
        </body>
    </html>
     

     

    php:
     

     

    <?php

     
    require_once 'database.php';
    $database_connection = database_connect();
    $title='hola';
     
    $content='<div>';
     
    //user input
    $page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
    $perPage = 1;
    //Positioning
    $start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
    $art = $database_connection->query("SELECT id FROM coffee");
    //Query
    $articles = $database_connection->prepare("SELECT id FROM coffee LIMIT 0,5");
     
    $articles->execute();
    $articles = $articles->fetchAll();
     
    $resultado = $database_connection->query("SELECT COUNT(*) AS total FROM coffee");
    $fila = $resultado->fetch(PDO::FETCH_ASSOC);
    $total = $fila["total"];
    $pages = ceil($total/$perPage);
     
    echo $pages;
    $content .= '<div>';
     
     
    include 'Template_1.php';
    ?>
     

    any suggestion, dissapointment is good received

  4. Hi sorry but i tried to use of many ways and i use prepare etc, But i cant create one without vars. But when i use one form and check the post method to save this new row. It is empty. Code:

    <?php
     
    require_once 'database.php';
    $database_connection = database_connect();
     
    $users = $database_connection->query('SELECT * FROM coffee')->fetchAll();
    $title = 'Home';
    $content = '
    <h4>Title 1</h4>
    <form method="POST">
    <table>
    <tr>
        <td><input type="number" name="fname" required placeholder="First Name"></td>
     
    </tr>
    <tr>
        <td><input type="text" name="lname" required placeholder="Last Name"></td>
     
    </tr>
    <tr>
         <td><input type="text" name="age" required placeholder="Age" min="10" > </td>
     
    </tr>
    <tr>
        <td><input type="submit" name="insert"></input></td>
    </br>
    </tr>
    </form></table>
    <br>
    ';
    $content .=  '<br><table>';
    if(isset($_POST['submit']) == "insert")
    {
     
     
    // get values form input text and number
        $fname = $_POST['fname'];
        $lname = $_POST['lname'];
        $age = $_POST['age'];
     
    $uso = $database_connection->query('INSERT INTO coffee (id) VALUES (:fname)');
     
     
    }else{
        echo "nothing";
    }
     
     
    foreach($users as $user) {
     
        $content .= '<tr>';
        $content .= '<td>' . $user["id"] . '</td>';
        $content .= '<td>' . $user["type"] . '</td>';
        $content .= '<td>' . $user["price"] . '</td>';
        $content .= '<td><a href="index.php">' . $user["price"] . '<a/></td>';
        $content .= '<td><a href="index.php">' . $user["price"] . '<a/></td>';
        $content .= '</tr>';
    }
     
     
    $content .=  '</table>';
     
    include 'Template.php';
    ?>

     

    I am trying to do easy things. Like insert,update,delete,search but with a form.

     

  5. Ok sorry i will learn more. Sorry again. But my question is very short sir: I did one content var in php because i want to do my webpage in php only and there i include my html content. So i couldn't include my querys since there? This is my question nothing more. Maybe i dont know nothing about php and mysql but this is not my question. Anyways thx for your help

  6. Sorry for the mistake i created the rows with insert into, i was confused sorry again. I confused rows with columns;

    I fixed this mistake now:

     

    My question is very short, some way to include rows since content php, I could only do outside of my template like this:

    <?php
     
    require_once 'database.php';
     
     
     
    $database_connection = database_connect();
     
    $users = $database_connection->query('SELECT id FROM coffee')->fetchAll();
    var_dump($users);
     
     
     
    $title = 'Home';
    $content = '
    <h4>Title 1</h4>
    <table>
    <th>
    <td>&nbsp&nbsp&nbspName&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspTitle&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspola&nbsp&nbsp&nbsp</td>
    </th>
           
        <tr>
            <?php foreach($users as $user): ?>
            <td><?php echo $user["id"]?></td>
            <?php endforeach;?>
        </tr>
     
     
    </table>
    ';
    ?>
            
    <?php foreach($users as $user): ?>
            <td><?php echo $user['id']?></td>
            <?php endforeach;?>

     

     

    Some way to include in content of php? Or some way that show me the table inside of my template thxx

  7. when i do:

    var_dump($users);

     

     

    i get this message:

    C:\wamp\www\www\tabla.php:10:

    array (size=0)
    empty

     

    But it is strange because i created one table called tabla and it have content. And when i select one column like Nombre:

     

     

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Nombre' in 'field list'' in C:\wamp\www\www\tabla.php on line 9

    PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Nombre' in 'field list' in C:\wamp\www\www\tabla.php on line 9

     

     

    And the table i created since database of users, since phpmyadmin, all is right. So maybe i did something wrong.

    The table exists like you can see in this image:

    https://i.imgsafe.org/5391e48b22.png

     

    the code of tabla for you need to check:

    <?php
     
    require_once 'database.php';
     
     
     
    $database_connection = database_connect();
     
    $users = $database_connection->query('SELECT # FROM tabla')->fetchAll();
    var_dump($users);
     
     
     
    $title = 'Home';
    $content = '
    <h4>Title 1</h4>
    <table>
    <th>
    <td>&nbsp&nbsp&nbspName&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspTitle&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspola&nbsp&nbsp&nbsp</td>
    </th>
           
        <tr>
            <?php foreach($users as $user): ?>
            <td><?php echo $user["id"]?></td>
            <?php endforeach;?>
        </tr>
     
     
    </table>
    ';
    include 'Template.php';
    ?>
            

     

     

    Sorry again for all

  8. ok sorry

    so when i do this:

    $users = $database_connection->query('SELECT * FROM users')->fetchAll();

     

    <?php foreach($users as $users): ?>
        <tr>
            <td><?php echo $user['id']?></td>
        </tr>
    <?php endforeach;?>
     
    i included this for showing the tables but not show me nothing i will check more tutorials thx
     
    The code finally:
    <?php
     
    require_once 'database.php';
     
     
     
    $database_connection = database_connect();
     
    $users = $database_connection->query('SELECT * FROM tabla')->fetchAll();
     
     
     
     
    $title = 'Home';
    $content = '
    <h4>Title 1</h4>
    <table>
    <th>
    <td>&nbsp&nbsp&nbspName&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspTitle&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspola&nbsp&nbsp&nbsp</td>
    </th>
    <?php foreach($users as $users): ?>
        <tr>
            <td><?php echo $user["id"]?></td>
        </tr>
    <?php endforeach;?>
    </table>
    ';
    include 'Template.php';
    ?>

     

     

    Any suggestion is good received, dissapointments too

  9. sir i tried to call again fetchall and take me error:

    <?php
     
    require_once 'database.php';
     
     
     
    $database_connection = database_connect();
     
    $users = $database_connection->query('SELECT * FROM tabla')->fetchAll();
     
    $rows = $users->fetchAll();
     
     
     
    $title = 'Home';
    $content = '
    <h4>Title 1</h4>
    <table>
    <th>
    <td>&nbsp&nbsp&nbspName&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspTitle&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspola&nbsp&nbsp&nbsp</td>
    </th>
    <?php foreach($rows as $row): ?>
        <tr>
            <td>echo $row["id"]</td>
        </tr>
    <?php endforeach;?>
    </table>
    ';
    include 'Template.php';
    ?>

     

     

  10. Hi i get the follow error.

    Fatal error: Call to a member function fetchALL()

    Code:

    <?php
    $db = new PDO("mysql:host=localhost;dbname=dwn;cahset=UTF","root","");
     
    $sql = "SELECT * FROM 'users'";
    $stmt = $db -> query($sql);
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
     
     
    $title = "Home";
    $content = '
    <h4>Title 1</h4>
    <table>
    <th>
    <td>&nbsp&nbsp&nbspName&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspTitle&nbsp&nbsp&nbsp&nbsp</td>
    <td>&nbsp&nbsp&nbspola&nbsp&nbsp&nbsp</td>
    </th>
    </table>
    ';
     
    include 'Template.php';
    ?>
     

     

     

     

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