Page 1 of 1

Echo results not working

Posted: Sat Jan 22, 2011 10:58 am
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)

?>

Re: Echo results not working

Posted: Sat Jan 22, 2011 11:15 am
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'];
}
?>

Re: Echo results not working

Posted: Sat Jan 22, 2011 11:52 am
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 !

Re: Echo results not working

Posted: Sat Jan 22, 2011 11:54 am
by brassfid
Thankyou very much!