Easy Question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rdionne1187
Forum Newbie
Posts: 17
Joined: Tue Feb 01, 2005 9:30 am
Location: CT

Easy Question

Post by rdionne1187 »

Code: Select all

$connect=mysql_connect('localhost', 'clanhost_frgn1', 'dumbo5');
  if(!$connect){
        die('unable to connect to mysql server');
  }
  echo "connected..."."<br>";
  mysql_select_db("clanhost_frgn1", $connect);
  $query="SELECT Part_Name FROM `orders`";
  $result=mysql_query($query) or die("unable to retrieve pn: ".mysql_error()."<br>");
  $row = mysql_fetch_array($result);
  foreach($row as $value)&#123;
    print($value."<br>");
  &#125;
  
mysql_close($connect);
basically, I'm trying to get the contents of this table, and print them, but it just prints

Code: Select all

connected...
Chain
Chain
where the first item in the table of Part_number is chain, and the second one doesn't get printed? it just prints the first one twice.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_fetch_array() returns both numeric and named fields, this explains the two of the same. The other part is, mysql_fetch_array() only returns 1 record found at a time. You need a loop.
rdionne1187
Forum Newbie
Posts: 17
Joined: Tue Feb 01, 2005 9:30 am
Location: CT

Post by rdionne1187 »

I am extremely new to mysql, thank you
Post Reply