Code to select certain records in a table and display

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
jlgray48
Forum Newbie
Posts: 5
Joined: Sun Apr 22, 2007 11:38 am

Code to select certain records in a table and display

Post by jlgray48 »

Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This code is suppose to select all the names in a table named yahoo that have an id of 44 and display them on the screen. 

Any help would be greatly appreciated.

Code: Select all

<?php 

$conn=mysql_connect("127.0.0.1", "odbc", "") ; 
mysql_select_db("uah",$conn); 
$sql = "Select name from yahoo where  id=44";
mysql_query($sql,$conn) ; 
$result = mysql_query($sql,$conn);
while ($array = mysql_fetch_array($result)) {
  print "$array['name']";
};

?>

Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

After the '}' which closes the while's block, you have ';'. Get rid of it.
jlgray48
Forum Newbie
Posts: 5
Joined: Sun Apr 22, 2007 11:38 am

Post by jlgray48 »

Still a blank page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

check your error logs.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

$array['name'] doesn't exist. You are using mysql_fetch_array($result), when you want to use mysql_fetch_assoc($result) or (if your PHP is old) mysql_fetch_array($result, MYSQL_ASSOC).

BTW, you're querying twice. It won't affect your results, but it will affect your bandwidth.
Post Reply