Ricky Ricky - 3 months ago 5
PHP Question

How to display my selected index in my php

$result = mysql_query("SELECT * FROM customer where index = '" . $index . "'");
$row = mysql_fetch_array($result);


while($row = mysql_fetch_array($result)){
results
echo $row['index'] . " | " . $row['name'] . " | " . $row['contact'] . " | " . $row['email'] ;

}


Why I cannot display the selected $index? My result is empty.

**In my database the index is int and AUTO_INCREMENT, is it because the index is int, it cannot be found?

image

Answer

When you since it is auto-incremented it you are likely to get only one row as result so when you call $row = mysql_fetch_array($result); for the first time youe values are being set in it and then when you call it again in your while loop it is getting blank.

Try this:

$result = mysql_query("SELECT * FROM customer where `index` = '" . $index . "'");
$row = mysql_fetch_array($result);
echo  $row['index'] . " | " . $row['name'] . " | " . $row['contact'] . " | " . $row['email'] ;
Comments