Jewel Posted September 1, 2006 Share Posted September 1, 2006 I have a short and simple script which is supposed to query my database for film titles and display them. At the moment it will only display the first title. I have checked and double checked but I can't see anything wrong with the code, can anyone tell me what I'm doing wrong please?The database only has the one field (title) and contains 11 titles at the moment. The code is as follows:<?//set up table and database names$db_name = "dynamic";$table_name = "Kubrick";//connect to server and select database$connection = @mysql_connect("localhost","jimmy","12345") or die(mysql_error());$db = @mysql_select_db($db_name,$connection) or die(mysql_error());//build and issue query$sql ="SELECT * FROM $table_name ORDER by title";//store the result of the query$result = @mysql_query($sql,$connection)or die(mysql_error());//get results for displaywhile ($row = mysql_fetch_array($result)) { $title = $row['title'];}?>Kubrick [<? echo "($title) {< KubrickMovie \"$title\" >}";?>] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 1, 2006 Share Posted September 1, 2006 Put you echo statement inside the while loop. SO chnage this:[code]//get results for displaywhile ($row = mysql_fetch_array($result)) { $title = $row['title'];}?>Kubrick [<? echo "($title) {< KubrickMovie \"$title\" >}";?>][/code]To this:[code]//get results for displaywhile ($row = mysql_fetch_array($result)) { $title = $row['title']; echo 'Kubrick [ ' . $title . "]<br />\n";}[/code] Quote Link to comment Share on other sites More sharing options...
pgsjoe Posted September 2, 2006 Share Posted September 2, 2006 damn! finally something I'd be able to answer and someone else beats me to it. Quote Link to comment Share on other sites More sharing options...
Jewel Posted September 2, 2006 Author Share Posted September 2, 2006 Thank you for that, It works fine now! I thought that I'd tried that earlier, but obviously I did something not quite right. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.