0

I want to populate a string via MySQL, the string will be an Array.

$con = mysql_connect("localhost","username","#######");
mysql_select_db("mydatabase", $con);
$result = mysql_query("");

while($row = mysql_fetch_array($result)){
  $saleArrayList = array("");

}

I want my Array like

  // $saleArrayList = array("data1seperatecomma,data2seperateacomma,etc,etc");

This is my new code:

$salesArrayList = array();

while($row = mysql_fetch_array($result)){
  array_push($salesArrayList, $row[0]);
}
$string = implode(',', $salesArrayList);
echo $string;

Works well!!!

1 Answer 1

2

Do you just want to fill an array? Then use array_push() to add items to your array

$con = mysql_connect("localhost","username","#######");
mysql_select_db("mydatabase", $con);
$result = mysql_query("");

$salesArrayList = array();

while($row = mysql_fetch_array($result)){
  array_push($salesArrayList, $row[0]);
}

If you want a string with comma delimiter based on an array you can use implode():

$string = implode(',', $salesArrayList);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man. I updated my thread question at the top with the new code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.