JohnDotOwl
JohnDotOwl

Reputation: 3755

mysql returning only 2 results

mysql_connect('localhost:3036', 'root', 'xxxx');

mysql_select_db('extractor');

$query = mysql_query("SELECT trackingno FROM xx where orderid='".$item->increment_id."'");

$compiledresults = mysql_fetch_array($query); 

foreach($compiledresults as $items){ 

echo $items."</br>";
} 

It's always returning two values at maximum only. Any idea why?

Upvotes: 2

Views: 99

Answers (1)

sybear
sybear

Reputation: 7784

Just fix your code to:

$query = mysql_query("SELECT trackingno FROM xx where orderid='".$item->increment_id."'");
if ($query){
  while ($data = mysql_fetch_assoc($query)){
    echo $data['trackingno'] ;
  } 
}

The reason you get 2 items is that you used mysql_fetch_array once. That gives you just one row from the database. First element in array is number-indexed, another is string-indexed.

So you had: $compiledresults[0] and $compiledresults['trackingno'] in fact.

Upvotes: 1

Related Questions