Jump to content

How to display mysql table row values PDO


Tje

Recommended Posts

Hi,

I want to display row 0   row 2  row 3 and row 4 values in to text field.this is my code.but it's display "Undefined offset: 1 in C:\wamp\www\member\sys-admin\groups.php on line 15 ,Undefined offset: 2 in C:\wamp\www\member\sys-admin\groups.php on line 16 ,Undefined offset: 3 in C:\wamp\www\member\sys-admin\groups.php on line 17".

 

  



      <?php
            $r_sql = "SELECT ugroup FROM ugroups ";
            $r_result = db::getInstance()->query($r_sql);
            $row = $r_result->fetch(PDO::FETCH_NUM);
            
            $g1 = $row['0'];
            $g2 = $row[1];
                 $g3 = $row[2];
                 $g4 = $row[3];
        ?>


 

html

 

    


<strong>G 1</strong><input name="g1" type="text" id="g1" style="width:300px;" value="<?php echo $g1;  ?>" />
<strong>G 2</strong>    <input name="g2" type="text" id="g2" style="width:300px;" value="<?php echo $g2;  ?>" />
<strong>G 3</strong><input name="g3" type="text" id="g3" style="width:300px;" value="<?php echo $g3;  ?>" />
<strong>G 4</strong><input name="g4" type="text" id="g4" style="width:300px;" value="<?php echo $g4;  ?>" />

post-170830-0-85925200-1412664118_thumb.jpg

given that in your previous threads on this forum, you successfully used a mysql_ fetch statement in a while(){} loop to loop over the rows that a query returned, why not try that same method now? just because you changed from using the mysql_ functions to PDO functions doesn't mean that the fundamental concepts used in the php code changed too.

Archived

This topic is now archived and is closed to further replies.

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