smoreno Posted July 19, 2006 Share Posted July 19, 2006 I am currently using yahoo as a host, and they supply a mysql server, and they support php.I am very new to php and I am having trouble figuring out how to get data from the database and being able to edit it.Basically, on my page, I want an announcements section. I want this data to be editable though, but only by certain people. I have made a page that is password protected, I only need the codeing that would allow them to edit it.So, 2 pages, one that pulls the data from the database and displays it, and a page that allows that data to be edited.Could anyone help me with this or lead me to a website that would show me how?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/15034-useing-php-to-edit-and-pull-data-from-a-database/ Share on other sites More sharing options...
designationlocutus Posted July 19, 2006 Share Posted July 19, 2006 Check out some of the database connection tutorials on this site. Quote Link to comment https://forums.phpfreaks.com/topic/15034-useing-php-to-edit-and-pull-data-from-a-database/#findComment-60445 Share on other sites More sharing options...
Ninjakreborn Posted July 19, 2006 Share Posted July 19, 2006 $select = "SELECT * FROM tablename";$query = mysql_query($select);//2 functions mysql_num_rows and mysql_fetch_array$num_rows = mysql_num_rows($query);while ($rows = mysql_fetch_array($query)) { //format the data for viewing, with tables or lists or whatever.//for instance listsecho "<ul type=/"disc/">";echo "<li>" . $rows['variable'] . "</li>";echo "<li>" . $rows['variable2'] . "</li>";echo "<li>" . $rows['variable3'] . "</li>";echo "</ul>";// this displays the data as a list, then if you wanted it as tables, something like thisecho "<table>";echo "<tr><td>" . $rows['variable'] . "</td></tr>";echo "<tr><td>" . $rows['variable2'] . "</td></tr>";echo "<tr><td>" . $rows['variable3'] . "</td></tr>";echo "</table>";}// I didn't have a lot of time so these are a little off, for example , it's going to create a new list for every row, then a new table for every row so instead if you use the list have the echo "<ul>"; or whatever before the while statementand the end tag after it, the same with table start and finishalso while and foreach are roughly the same thing, after asking hundreds of developers none of them notice a difference so you can safely use either.As for updating, you can set up a straight update, where you have fields, and they update the stuff automatically, without testing, or test for hte existence of first, then update if it doesn't exist.to update it's just the exact same query above just with alteror insert if you are just adding data, you could also use update, which is what I always use.$select = "UPDATE columnname FROM tablename WHERE whatever.You get the point as soon as that query hits mysql query it's run automatically so be carefuly if you do$select = "UPDATE mycolumn SET whateverit allows you to set it but as soon as you usemysql_query($select)then the data is updated. Quote Link to comment https://forums.phpfreaks.com/topic/15034-useing-php-to-edit-and-pull-data-from-a-database/#findComment-60457 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.