zechdc Posted November 12, 2007 Share Posted November 12, 2007 I am trying to connect to my database and select the infromation from one column then displaying it in the web browser. I have done this before but there is something wrong in my code and I cant figure out what it is. When I run the code it just displays "Connected to MySQL" Please take a look and let me know what is wrong. Thanks. <?php $username = "Test_user"; $password = "Test_pas"; $hostname = "localhost"; $table = "test_tbl"; $column1 = "EventDate"; $connectdb = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); print "Connected to MySQL<br>"; $result = mysql_query("SELECT $column1 FROM $table"); print $result; ?> Quote Link to comment Share on other sites More sharing options...
drakal30 Posted November 13, 2007 Share Posted November 13, 2007 Your missing a PHP mySql statement. The result is an object you have to manipulate the object next to display usable data. Like this example. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { display line data } Quote Link to comment Share on other sites More sharing options...
zechdc Posted November 13, 2007 Author Share Posted November 13, 2007 I put that in the code and I get an error that says Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/p/o/g/pogotic/html/test.php on line 45 <?php $username = "PogoticTest"; $password = "Tiffaney1"; $hostname = "p41mysql81.secureserver.net"; $table = "info"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); print "Connected to MySQL<br>"; $result = mysql_query("SELECT * FROM $table"); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) //Line 45 print $line ?> Quote Link to comment Share on other sites More sharing options...
drakal30 Posted November 13, 2007 Share Posted November 13, 2007 The $line is an array you must now print out the elements of the array. I do not know your field names so I will make up generic ones. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {//Loop to display all turnover for given parameters echo $line["FIELD_NAME"]; so on and so on } 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.