0
name|fileid|refferer|clicks|
good|same  |asda.com|20    |
good|same  |bsad.com|500   |
good|diffnt|csad.com|600   |
dddd|dasdds|asad.com|200   |

Output:

[asda.com,20],[bsda.com,500]

What I tried:

$result = mysql_query("SELECT * FROM `ios7_refclean`.`graph_refferer_table` WHERE Name = 'good'");
$rowz = mysql_fetch_assoc($result);
foreach ($rowz as $col => $value) {
  if (($col !== "fileid") && ($col !== "name")) {
  echo ",['" . $col . "'," . $value . "]";
}

However only one row of good is coming, the other rows are not coming. Also I am not able to link the $col of refferer with $value of clicks with square brackets.

1 Answer 1

6

First of all, switch to MySQLi Or PDO because mysql_* functions were Deprecated.

You need to use while loop for retrieving all rows:

 while($rowz = mysql_fetch_assoc($result)){
  //your code here
 }

Also, you are using bad logic for printing your data, you can simply use:

 while($rowz = mysql_fetch_assoc($result)){
  $data[] = '['.$rowz['refferer'].','.$rowz['clicks'].']';
 }
echo implode(",", $data);
Sign up to request clarification or add additional context in comments.

Comments

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.