Page 1 of 1

Code to select certain records in a table and display

Posted: Sun Apr 22, 2007 4:29 pm
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]

Posted: Sun Apr 22, 2007 5:21 pm
by Oren
After the '}' which closes the while's block, you have ';'. Get rid of it.

Posted: Sun Apr 22, 2007 5:22 pm
by jlgray48
Still a blank page.

Posted: Mon Apr 23, 2007 8:39 am
by feyd
check your error logs.

Posted: Mon Apr 23, 2007 8:51 am
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.