uswege Posted February 12, 2010 Share Posted February 12, 2010 I have just created a database for site created by someone else. The address to the database is http://www.tib.co.tz/db Use the following login details to get in Username: test Password: test The Challenge is, i am trying to output data from the database (mysql databe) into a webpage using php script, but the script is just not working, where am getting it wrong? below is the output script i am using <?php include 'connect.php'; $query="SELECT * FROM main WHERE Category='Home' ORDER BY 'id' DESC Limit 1"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $content=mysql_result($result,$i,"content"); echo "$content"; $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/191844-helpoutputting-data-from-mysql-database-using-php/ Share on other sites More sharing options...
premiso Posted February 12, 2010 Share Posted February 12, 2010 You close the mysql connection before you pull the results. Generally you should not close the mysql connection as when the scripts stops executing php will do this automatically for you. Quote Link to comment https://forums.phpfreaks.com/topic/191844-helpoutputting-data-from-mysql-database-using-php/#findComment-1011170 Share on other sites More sharing options...
sader Posted February 12, 2010 Share Posted February 12, 2010 mysql_numrows => mysql_num_rows and as long as I know u can close mysql connection after u queryed and u still will be able to fecth and manipulate data cuz u allredy have it in resource object Quote Link to comment https://forums.phpfreaks.com/topic/191844-helpoutputting-data-from-mysql-database-using-php/#findComment-1011171 Share on other sites More sharing options...
uswege Posted February 12, 2010 Author Share Posted February 12, 2010 Thanks guys. . i think i am one step ahead. I have removed mysql_close(); and changed mysql_numrows => mysql_num_rows before doing changes, the page could't open (the browser was just hanging and bringing an error msg), now the page opens but not data, the connection is Successful only the data is not displayed. The current script is <?php include 'connect.php'; $query="SELECT * FROM main WHERE category='Home' ORDER BY 'id' DESC Limit 1"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $content=mysql_result($result,$i,"content"); echo "$content"; $i++; } ?> Also the DB address and login info is http://www.tib.co.tz/db Username: test Password: test Quote Link to comment https://forums.phpfreaks.com/topic/191844-helpoutputting-data-from-mysql-database-using-php/#findComment-1011203 Share on other sites More sharing options...
uswege Posted February 13, 2010 Author Share Posted February 13, 2010 May be it is something that has to do with the structure of my db. i have two tables 1. main with fields id,category,content,updatetime,updateby 2.category with fields id,CategoryName The category field in the main table is linked to the category table (because i want the category field in the main table to be dynamic) i want to display the content field of a selected category field. can any one help? Quote Link to comment https://forums.phpfreaks.com/topic/191844-helpoutputting-data-from-mysql-database-using-php/#findComment-1011658 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.