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
brassfid
Forum Newbie
Posts: 18 Joined: Thu Jan 13, 2011 11:09 pm
Post
by brassfid » Sat Jan 22, 2011 10:58 am
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)
?>
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Sat Jan 22, 2011 11:15 am
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
phazorRise
Forum Contributor
Posts: 134 Joined: Mon Dec 27, 2010 7:58 am
Post
by phazorRise » Sat Jan 22, 2011 11:52 am
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
Post
by brassfid » Sat Jan 22, 2011 11:54 am
Thankyou very much!