Tje Posted October 7, 2014 Share Posted October 7, 2014 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; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/291482-how-to-display-mysql-table-row-values-pdo/ Share on other sites More sharing options...
Barand Posted October 7, 2014 Share Posted October 7, 2014 You want to output 4 values yet you only select 1 column value from the table. Therefore only $row[0] exists, containing the value from the ugroup column. Quote Link to comment https://forums.phpfreaks.com/topic/291482-how-to-display-mysql-table-row-values-pdo/#findComment-1492928 Share on other sites More sharing options...
mac_gyver Posted October 7, 2014 Share Posted October 7, 2014 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/291482-how-to-display-mysql-table-row-values-pdo/#findComment-1492929 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.