1

I am having problem extracting values from a mysql table: I need to get all values of picname column from a table where uid condition is satisfied. Now i have two rows where this condition is satisfied but i am getting output only for 1st case. I am not able to get the second row's value. 1st rows value repeats again for second time.

$i = 0;
for($i;$i<2;$i++)
{
    $s = "SELECT picname FROM uploaded_data WHERE uid='$uid'";
    $que = mysql_query($s,$db);
    while($num = mysql_fetch_array($que))
    {

    echo $name ['picname'];

    }

}

Thank You

gapc311
  • 463
  • 2
  • 6
  • 15
  • after while loop set free `$que` like this : `mysql_free_result($que);` – Awlad Liton Feb 21 '14 at 14:43
  • 1
    `$name ['picname']` should be `$num['picname']`. Is that just a typo here? – jeroen Feb 21 '14 at 14:45
  • 1
    Where do you change the value of `$uid`? It runs the same query in every loop. BTW you should write a query like this: `select picname FROM uploaded_data WHERE uid in ($uids)` and iterate over the query results. – HarryFink Feb 21 '14 at 14:45
  • Yaa..sorry...it is $num instead of $name...but still it is not working – gapc311 Feb 21 '14 at 14:50
  • 1
    Please, don't use `mysql_*` functions to write new code. See the [red box](http://uk.php.net/manual/en/function.mysql-connect.php)? Instead you should learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) and use either [PDO](http://www.php.net/pdo) or [MySQLi](http://www.php.net/mysqli). If you can't decide which, [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you. Also see http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Marijke Luttekes Feb 21 '14 at 14:55

1 Answers1

1

it should not give you any result you do not have

$name

should be:

$i = 0;
for($i;$i<2;$i++)
{
    $s = "SELECT picname FROM uploaded_data WHERE uid='$uid'";
    $que = mysql_query($s,$db);
    while($num = mysql_fetch_array($que))
    {

    echo $num['picname'];

    }
   mysql_free_result($que);

}
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53