value of select in array

Asked

Viewed 148 times

2

Good,

Looking at this query:

$sql = mysql_query("select A, B, C, D from table");
$row_sql = mysql_fetch_assoc($sql);

I want to take the A column and put all the values in an array:

$var = array('value1','value2','value3','value4');

What’s the best way to do it?

Thank you.

1 answer

2


With while.

$sql = mysql_query("select A, B, C, D from table");

while($res = mysql_fetch_assoc($sql)){
    $arrData[] = $res['A'];
}

echo '<pre>';
print_r($arrData);
echo '</pre>'
  • Thank you for the reply, and it worked, but the first value does not appear. Assuming the result would be: value1, value2, Valor3, etc...

  • You are repeating the mysql_fetch_assoc($sql) is not ?

  • No, it is unique in code. <? php $sql = mysql_query("select A from Tablea Where B IN($Var)"); while($res = mysql_fetch_assoc($sql)){ $arrData[] = $res['A']; } #echo '<pre>'; print_r(implode(',',$arrData)); #echo '</pre>' ;?>

  • Update your post with the current code and with the return of the code.

  • I redid the code and everything worked fine. There must have been something I couldn’t find to impact the result. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.