SQL query only returning first result - twice...

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

Like the title says, I am only getting the first result, and getting it twice.

example:

<?php
$con
= mysql_connect("localhost","USER","PASS");
if (!
$con)
  {
  die(
'Could not connect: ' . mysql_error());
  }
mysql_select_db("DB_NAME", $con);
$sql = 'SELECT ptext FROM  provisions WHERE pnumber =
"119441a" OR pnumber = "119441b"'
;
$data = mysql_query( $sql, $con );
$info = mysql_fetch_array( $data );
$arr = array_values($info);

print_r($arr);
?>

I only get the (a) value - twice:

Array ( [0] => (a) Product support documentation provided to end-users shall be made available in alternate formats upon request, at no additional charge. [1] => (a) Product support documentation provided to end-users shall be made available in alternate formats upon request, at no additional charge. )

The first result twice.

Same result for SELECT DISTINCT

I have a shadow of the db on localhost, SQL on localhost works fine.

On localhost running the query in phpmyadmin I get the two text fields, (a) and (b)..

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

Doh! DOH!

mysql_fetch_array($data)

only returns one row from the db at a time...

so you need a "while" loop to loop through all the rows in the db..

<?php

$con
= mysql_connect("localhost","communit_508dev","commUNIT");
if (!
$con)
  {
  die(
'Could not connect: ' . mysql_error());
  }
mysql_select_db("communit_508prov", $con);


$sql = 'SELECT ptext FROM  provisions';

$data = mysql_query( $sql, $con );

while(
$row = mysql_fetch_array($data))
  {
 
$arr .= $row['ptext'] . "<br />";
  }

print_r($arr);

mysql_close($con);
?>

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.