Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sql select in a php file and write out in for cycle

I have a select in my php file, but the select result is have more rows, and i want to write out all rows with a for cycle.

I want to convert it after a qr code but i need only the writing out in the for cycle

//select command

$sql = "SELECT * FROM qr  
INNER JOIN eladott
ON qr.qr_eladott_id=eladott.eladott_id
WHERE qr.qr_eladott_id=$eladott_id";

    $result = mysqli_query($conn, $sql);
    
    if(mysqli_num_rows($result) > 0)
        
        $qr = mysqli_fetch_assoc($result);


 for ($i = 0; $i < $eladott_jegyek_db; $i++)
    {
        
        $pdf->Image($qr['qr_code']);
        
        
    }
    

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’ve not used mysqli for some time, but this solution might suit you.
Considering your database would be ‘your_db’ and the table ‘user’ exists within, consider the following code:

$link = mysqli_connect('localhost', 'root', '', 'your_db');

$result = mysqli_query($link, 'SELECT * FROM user');

while ($row = $result->fetch_assoc()) {
    echo $row['id'] . ' ';
}

My output would be:

28
29
32
35
45
46
48
53
55
56
57
59
61
62
63
65
66
67
70
71
74

The ‘while’ block will get all query selected rows as associative arrays under the $row variable.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading