December 4, 201312 yr Hey all, I've created a back end where customers can edit their content. The page content (just text) is currently in a table, which includes the meta tags and page name. I have been using the following code to get the specific content on each page using WHERE id = 1,2,3 etc mysql_select_db($database_template, $template); $query_pages = "SELECT * FROM pages WHERE id = 1"; $pages = mysql_query($query_pages, $template) or die(mysql_error()); $row_pages = mysql_fetch_assoc($pages); $totalRows_pages = mysql_num_rows($pages); I now want to pull the page name from individual records so I can insert it into the navigation buttons. This way, if they change the page name from the back end, it will be reflected in the navigation buttons on every page. I don't want to use a while loop in the nav as some of the buttons are unique, like the active one has different properties and an arrow. What is the best way to pull individual bits of information from a table, so <?php echo $row_pages['pagename']; ?> where ID = 2. <?php echo $row_pages['pagename']; ?> where ID = 3 etc. I could duplicate the above 10 times on each page purely to get the page name but I guess there's a better way? Thanks in advance
December 4, 201312 yr You shouldn't be using mysql_* functions. They're deprecated. You should be using PDO. You're also writing procedural PHP, which generally isn't good practice for a web application that you're describing. For a CMS, you'd be better off working with a PHP framework. It looks like you need to take a step back and learn a little more about the basics before attempting to build something of this scale. You'll get into bad habits otherwise. With regards to your navigation question, I'm not sure I quite follow what you're trying to do. Manually echoing a finite set is rarely the solution to outputting information from arrays. Also, your query is already specifying "WHERE id = 1", so it should only return one result (assuming id is the primary key).
December 4, 201312 yr Author Thanks for the advice. Yeah I can already feel myself picking up some bad habits and trying to find workarounds like the example above. The back end is very basic, just allowing customers to change website text so I've just been echoing and updating records so far. Can you recommend a simple framework? Thanks buddy
December 4, 201312 yr CodeIgniter is a popular and simple PHP framework. I've used it a few times for personal projects and found it very easy to pick up. It would work well for this mini-CMS you're creating. It may be simple, what you're building, but that doesn't stop you building it using best practices. Hopefully you'll find that using a framework will open your eyes to the object-oriented approach.
December 4, 201312 yr Author Thanks, I'll take a look. I've been keen to start using some sort of framework so appreciate the advice.
Create an account or sign in to comment