0
    <?        if(!$link)
               {
                   die('not connected');
               }
                    $mlink=  mysqli_query($link, "select * from products");
                    $row=  mysqli_fetch_array($mlink);  ?>

 <input list="pcode" required="required" class="form-control col-md-7 col-xs-12">     
                  <datalist id="pcode">
                       <?php
                         while($row= mysqli_fetch_array($mlink))
                           {
                              ?>
                <option value="<?php echo $row ['productcode']; ?>">  <?php } ?>
                            </datalist>

the above query doesnt fetch all the data, it misses the very first data and fetch the rest, i dont know y?? i was retriving all the fetched data into a datalist, it shows all the data except the first one,THE FULL CODE was pasted here, https://pastebin.com/LLDN0Y9M

  • Please start with [mcve] and edit your question accordingly. No one will follow your link and read whatever is there. – u_mulder May 31 '17 at 20:58
  • I have no idea what you are saying, but you only ever fetch 1 row `$row= mysqli_fetch_array($mlink);` – AbraCadaver May 31 '17 at 20:59
  • Your code is vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. You should use [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php) prepared statements with bound parameters as described in [**this post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – Alex Howansky May 31 '17 at 21:00
  • `$row= mysqli_fetch_array($mlink);` will give only one row data. also why `id>0` why not `mysqli_query($link, "select * from products");`?do you have `id=0` also? if yes then incorrect – Alive to die - Anant May 31 '17 at 21:01
  • sorry, edited my question, i dont have 0 id, – MuraleeDharan Sugumar May 31 '17 at 21:06
  • 1
    the problem is the first `$row= mysqli_fetch_array($mlink);`: there you don't use $row, but set the pointer to the next record. Delete this line. – Jeff May 31 '17 at 21:19
  • @Jeff , u r right it worked , thank u so much.... – MuraleeDharan Sugumar May 31 '17 at 21:23
  • you're welcome. give @ryo7689 a credit, he got the same answer. – Jeff May 31 '17 at 21:24

1 Answers1

0

Remove the $row= mysqli_fetch_array($mlink); on the 6th line, the 1st row is fetched here and not get echoed. let me know if you still have problem.

Also, there are some suggestions, generally for the best practice, it is not a good idea to use SELECT * for queries, and it is also a good idea to test for error for example use if (!$mysqli->query($sql)) and $mysqli->error to do error checking.

PHP Manual - mysqli_query

ryo7689
  • 136
  • 4