vendredi 21 mai 2021

How to show title and URL from SQL

I hope someone can help me with this puzzle!

I have this code:

    <?php

$user = 'myuser';
$pass = 'mypass';

try{
    $dbh = new PDO('mysql:host=localhost;dbname=mybase', $user, $pass);
    foreach($dbh->query('SELECT title FROM ads_listing') as $title);
    foreach($dbh->query('SELECT slug FROM ads_listing') as $slug){
    print_r($slug);
    print_r($title);
    }

    $dbh = null;
} catch (PDOException $e){
    print "ERROR!:" . $e->getMessage() . "<br/>";
    die();
}
?>

It display:

Array ( [slug] => laptop-dell-e6420-in-good-condition-tj304mkn910a8 [0] => laptop-dell-e6420-in-good-condition-tj304mkn910a8 ) 1Array ( [title] => VW POLO Comfortline [0] => VW POLO Comfortline ) 1Array ( [slug] => vw-polo-comfortline-rf839h9c9d065 [0] => vw-polo-comfortline-rf839h9c9d065 ) 1Array ( [title] => VW POLO Comfortline [0] => VW POLO Comfortline )

The goal is to display from my table 10 random titles as an URL with the slug like: VW POLO Comfortline, Laptop dell e6420 in good condition,.

How can I do it please?




Aucun commentaire:

Enregistrer un commentaire