jeudi 26 août 2021

To create random first and last name. multiple pieces

I would like to ask for your help.

I want to create a script. The script will automatically list random firstname and lastname. There are two database tables. First: fake_name_id, fake_firstname Second: fake_name_id,fake_lastname

Unfortunately, I'm not very good at this.

So far I have made this:

controller file

$data['lastname'] = array();

$results = $this->getRandomLastNames();
    foreach ($results as $result) {
        $data['lastname'][] = array(
            'lastname'        => $result['lastname'],
        );
    }

$data['fullnames'] = array();
$results = $this->getRandomNames();

    foreach ($results as $result) {
        $data['fullnames'][] = array(
            'firstname'        => $result['firstname'],

        );
    }

model file >>>>> sql query firstname and lastname

public function getRandomName($fake_name_id) {
                
        $query = $this->db->query("SELECT DISTINCT *, fake_firstname FROM " . DB_PREFIX . " fakereviews_name WHERE fake_name_id = '" . (int)$fake_name_id . "'");
        
        if ($query->num_rows) {
            return array(
                'fake_name_id'             => $query->row['fake_name_id'],
                'firstname'             => $query->row['fake_firstname'],
            );
        } else {
            return false;
        }
    }
    
    public function getRandomNames($data = array()) {

            $sql = "SELECT * FROM " . DB_PREFIX . "fakereviews_name ORDER BY Rand() ASC LIMIT 0, 20";
            $fake_firstname_data = array(); 
            $query = $this->db->query($sql);
                       
            foreach ($query->rows as $result) {
                
                $fake_firstname_data[$result['fake_name_id']] = $this->getRandomName($result['fake_name_id']);
            }       
        return $fake_firstname_data;
    }   
    
    
    
    
 public function getRandomLastName($fake_name_id) {
                
        $query = $this->db->query("SELECT DISTINCT *, fake_lastname FROM " . DB_PREFIX . " fakereviews_lastname WHERE fake_name_id = '" . (int)$fake_name_id . "'");

        if ($query->num_rows) {
            return array(
                'fake_name_id'             => $query->row['fake_name_id'],
                'lastname'             => $query->row['fake_lastname'],
            );
        } else {
            return false;
        }
    }
        
    public function getRandomLastNames($data = array()) {

            $sql = "SELECT * FROM " . DB_PREFIX . "fakereviews_lastname ORDER BY Rand() ASC LIMIT 0, 20";
            
            $fake_lastname_data = array();  
            
            $query = $this->db->query($sql);
                       
            foreach ($query->rows as $result) {
                
                $fake_lastname_data[$result['fake_name_id']] = $this->getRandomLastName($result['fake_name_id']);
            }       
        return $fake_lastname_data;
    }   

twig file


When the page loads. well creates 20 pieces of firstname.

But I can't get it to display lastname correctly.

Please help me to create foreach random fullname (first and last name) with predefined quantity.




Aucun commentaire:

Enregistrer un commentaire