• User Attivo

    Piccola modifica rewriterule

    L'obiettivo del mio rewriting è fare pagine del tipo /articolo/nome-articolo.php

    Fino adesso sono arrivato a fare solo pagine del tipo /articolo/id/nome-articolo.php

    Cioè se vado ad eliminare l'ID nell'url mi errore:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ...

    vi allego il codice che uso

    index.php
    [php]<?php
    include('connessione_db.inc.php');

    $query = "SELECT * FROM tb_annunci ";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)) {

           echo "<a href=\"annunci/$row[id]/$row[titolo].php\">$row[titolo]</a>";
    

    }
    ?>[/php]view.php

    <?php
    include('../connessione.inc.php');
    
    $query = "SELECT * FROM `tb_annunci` WHERE id=".$_GET['titolo'];
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    ?>
    
    <html>
    <head>
    <title><?php echo $row['titolo']; ?></title>
    </head>
    <body>
    <h1><?php echo $row['titolo']; ?></h1>
    <p><?php echo $row['testo']; ?></p>
    <br><br>
    </body>
    </html>
    ```.htacces
    

    RewriteEngine On
    RewriteRule ^(.+)/(.+).php view.php?titolo=$1