I want to select data from database what is the error in my code ,

I want to select data from database what is the error in my code ,


<center>
<table align="center">
<tr>
<th><a href="phpfirstpjroject.php">Add data here</a></th>
<th> Name</th>
<th>City_Name</th>
<th colspan="2">Operation</th>
</tr>
<?php
include_once'dbconfiguration.php';
$sql_query="SELECT * FROM usertable";
$result_set=$con->query($sql_query);
while($row=$result_set->fetch_assoc())
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td align="center"><a href="javascript:edt_id('<?php echo $row[0]; ?>')">
<img src="b_edit.png" align="EDIT" /></a></td>
<td align="center"><a href="javascript:delete_id('<?php echo $row[0]; ?
>')"><img src="b_drop.png" align="DELETE" /></a></td>
</tr>
<?php

?>
}
?>
</table>
</center>



HERE IS THE OUT PUT
Add data here Name City_Name Operation



Notice: Undefined offset: 1 in C:xampphtdocsprojectphpread.php on line 24



Notice: Undefined offset: 2 in C:xampphtdocsprojectphpread.php on line 25



Notice: Undefined offset: 3 in C:xampphtdocsprojectphpread.php on line 26



Notice: Undefined offset: 1 in C:xampphtdocsprojectphpread.php on line 24



Notice: Undefined offset: 2 in C:xampphtdocsprojectphpread.php on line 25



Notice: Undefined offset: 3 in C:xampphtdocsprojectphpread.php on line 26



Notice: Undefined offset: 1 in C:xampphtdocsprojectphpread.php on line 24



Notice: Undefined offset: 2 in C:xampphtdocsprojectphpread.php on line 25



Notice: Undefined offset: 3 in C:xampphtdocsprojectphpread.php on line 26



Notice: Undefined offset: 1 in C:xampphtdocsprojectphpread.php on line 24



Notice: Undefined offset: 2 in C:xampphtdocsprojectphpread.php on line 25



Notice: Undefined offset: 3 in C:xampphtdocsprojectphpread.php on line 26



Notice: Undefined offset: 1 in C:xampphtdocsprojectphpread.php on line 24



Notice: Undefined offset: 2 in C:xampphtdocsprojectphpread.php on line 25



Notice: Undefined offset: 3 in C:xampphtdocsprojectphpread.php on line 26



Notice: Undefined offset: 1 in C:xampphtdocsprojectphpread.php on line 24



Notice: Undefined offset: 2 in C:xampphtdocsprojectphpread.php on line 25



Notice: Undefined offset: 3 in C:xampphtdocsprojectphpread.php on line 26






if you do var_dump( $result_set ); do you get a meaningful result displayed?

– RamRaider
Sep 16 '18 at 6:39


var_dump( $result_set );






@RamRaider No, i am not get any result but show me another error undefined variable result_set

– Muhammad kashif
Sep 16 '18 at 6:47







has the database connection script been included correctly - ie: is the db available? The db connection is definitely called $con?

– RamRaider
Sep 16 '18 at 6:51



$con






yes the database is available.

– Muhammad kashif
Sep 16 '18 at 6:53






ok - so if you run that exact same query in your mysql client program or cmd line does it run correctly?

– RamRaider
Sep 16 '18 at 6:55


mysql client




1 Answer
1



If you use fetch_assoc you should access tho the values using the related column name


while($row=$result_set->fetch_array()) {
?>
<tr>
<td><?php echo $row['my_col1']; ?></td>
<td><?php echo $row['my_col2']; ?></td>
<td><?php echo $row['my_col3']; ?></td>
...................



if you want access by position you should use fetch_array()


$result_set=$con->query($sql_query);
while($row=$result_set->fetch_array()) {
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
.......



rememamber tha the index start form 0 in the way you are using you are accessing to the column in position 1,2,3 (skipping the first at position zero






thank you so much it work correctly @scaisEdge

– Muhammad kashif
Sep 16 '18 at 7:15







@Muhammadkashif .well if my answer is right please mark it as accepted ...(past 15 minutes) see how here meta.stackexchange.com/questions/5234/…

– scaisEdge
Sep 16 '18 at 7:18






it is correct i give u accept mark but it cant show because i have less then 15 reputation

– Muhammad kashif
Sep 16 '18 at 7:31






@Muhammadkashif .. thanks .. i see the mark ..

– scaisEdge
Sep 16 '18 at 7:32







you welcome Have a nice day

– Muhammad kashif
Sep 16 '18 at 7:33



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)