Jump to content


Photo

useing php to edit and pull data from a database


  • Please log in to reply
2 replies to this topic

#1 smoreno

smoreno
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 July 2006 - 01:23 PM

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!


#2 designationlocutus

designationlocutus
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 19 July 2006 - 01:25 PM

Check out some of the database connection tutorials on this site.

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 July 2006 - 01:50 PM

$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 lists
echo "<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 this
echo "<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 statement
and the end tag after it, the same with table start and finish
also 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 alter
or 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 whatever
it allows you to set it but as soon as you use
mysql_query($select)
then the data is updated.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users