waverider303 Posted December 9, 2009 Share Posted December 9, 2009 I have this site and the information on the page is coming from a database. I want to create a class so on each page I can just call the class to put the correct information on that page. IE: Instead of writing this on all the pages <?php include('connect.php'); $sql = "SELECT * FROM db_name WHERE db_row = '$variable'"; $res = mysql_query($sql); while($row = mysql_fetch_assoc($res)) { $page_content = $row['page_content']; } ?> I could intune write just a require_once(''); statement and it will do it all. Link to comment https://forums.phpfreaks.com/topic/184577-retrieve-mysql-db-information-from-a-class/ Share on other sites More sharing options...
mrMarcus Posted December 9, 2009 Share Posted December 9, 2009 couldn't you just put this: <?php $sql = "SELECT * FROM db_name WHERE db_row = '$variable'"; $res = mysql_query($sql); while($row = mysql_fetch_assoc($res)) { $page_content = $row['page_content']; } ?> into connect.php and include that on every page? instead of having to rewrite/convert, etc. anything/everything to accommodate a class when one is not really necessary at this time. and if you don't know how to write a class to begin with, you're not ready to take advantage of what OOP has to offer anyways, so it's best to just stick with regular includes, etc., and read up on classes and OOP, then implement it when you have a working knowledge of it. or am i missing the point entirely? Link to comment https://forums.phpfreaks.com/topic/184577-retrieve-mysql-db-information-from-a-class/#findComment-974413 Share on other sites More sharing options...
waverider303 Posted December 10, 2009 Author Share Posted December 10, 2009 Na your right. I guess that would do. I am trying to segway into classes. Any good tutorials on them? Link to comment https://forums.phpfreaks.com/topic/184577-retrieve-mysql-db-information-from-a-class/#findComment-974416 Share on other sites More sharing options...
waverider303 Posted December 10, 2009 Author Share Posted December 10, 2009 Actually one question I have is if i place this: <?php $sql = "SELECT * FROM db_name WHERE db_row = '$variable'"; $res = mysql_query($sql); while($row = mysql_fetch_assoc($res)) { $page_content = $row['page_content']; } ?> inside the connect.php files and include it on my pages. How would I change $variable depending on the page? Link to comment https://forums.phpfreaks.com/topic/184577-retrieve-mysql-db-information-from-a-class/#findComment-974428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.