Echo results not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brassfid
Forum Newbie
Posts: 18
Joined: Thu Jan 13, 2011 11:09 pm

Echo results not working

Post by brassfid »

Alright, the only thing I am getting back from this code is: Resource id #2. I am trying to pull all records and have them ordered alphabetically. Please help, thanks!

Code: Select all

<?php

$con = mysql_connect("localhost","ID","Psswrd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db", $con);

$result = mysql_query("SELECT * FROM Table ORDER BY column");

echo $result;
 
mysql_close($con)

?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Echo results not working

Post by social_experiment »

You have to pass the value from $result to something like mysql_fetch_array()

Code: Select all

<?php
$result = mysql_query("SELECT * FROM Table ORDER BY column");
while ($array = mysql_fetch_array($result)) {
 echo $array['yourField1'];
 echo $array['yourField2'];
}
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: Echo results not working

Post by phazorRise »

social_experiment wrote:You have to pass the value from $result to something like mysql_fetch_array()

Code: Select all

<?php
$result = mysql_query("SELECT * FROM Table ORDER BY column");
while ($array = mysql_fetch_array($result)) {
 echo $array['yourField1'];
 echo $array['yourField2'];
}
?>
Absolutely correct !
brassfid
Forum Newbie
Posts: 18
Joined: Thu Jan 13, 2011 11:09 pm

Re: Echo results not working

Post by brassfid »

Thankyou very much!
Post Reply