KevHopwood Posted July 4, 2013 Share Posted July 4, 2013 (edited) Hi guys. I am creating a cms for my own and am rather new to php and databases. what i want is to simply display each item on my mysql database in a list and display each image with the title next to it. I currentiy have this code on my index page: <?php include_once('include/connection.php'); include_once('include/article.php'); $app = new article; $apps = $app->fetch_all(); ?> <html> <head> <title>App Donate</title> <link rel="stylesheet" href="style.css" /> </head> <body> <ol> <?php foreach ($apps as $app) { ?> <li><a href="article.php?id=<?php echo $apps['app_id']; ?>"> <img src="<?php echo $row_getdetails['app_img']; ?>" alt="Image from DB" /> <?php echo $apps['app_title']; ?> </a> <?php } ?> </li></ol> </div> </body> </html> include/article.php <?php class article { public function fetch_all(){ global $pdo; $query = $pdo->prepare("SELECT * FROM `apps`"); $query->execute(); return $query->fetchAll(); } public function fetch_data($app_id) { global $pdo; $query = $pdo->prepare("SELECT * FROM apps WHERE app_id = ?"); $query->bindValue(1, $app_id); $query->execute(); return $query->fetch(); } } ?> my index page can be found HERE as you can see it has seen that there is 2 posts in my databace but it just is not displaying the content. please can someone help? THANK YOU. Edited July 4, 2013 by KevHopwood Quote Link to comment https://forums.phpfreaks.com/topic/279856-display-database-content/ Share on other sites More sharing options...
Strider64 Posted July 4, 2013 Share Posted July 4, 2013 (edited) Just a recommendation, but if you are new to databases and php then why are you starting out using Object-Oriented Programming Style? I would find a current book that shows procedural style programming that uses mysqli or PDO or a video tutorial. Edited July 4, 2013 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/279856-display-database-content/#findComment-1439405 Share on other sites More sharing options...
boompa Posted July 4, 2013 Share Posted July 4, 2013 (edited) <?php foreach ($apps as $app) { ?> You're iterating over $apps creating an $app variable, so why are you using the array variable $apps instead of $app in your loop? <?php foreach ($apps as $app) { ?> <li><a href="article.php?id=<?php echo $apps['app_id']; ?>"> <img src="<?php echo $row_getdetails['app_img']; ?>" alt="Image from DB" /> <?php echo $apps['app_title']; ?> </a> <?php } ?> And $row_getdetails doesn't seem to be a valid variable either. You need to learn to turn on error reporting and check your error logs, because I'm sure these things are producing at last warnings. Edited July 4, 2013 by boompa Quote Link to comment https://forums.phpfreaks.com/topic/279856-display-database-content/#findComment-1439420 Share on other sites More sharing options...
Strider64 Posted July 4, 2013 Share Posted July 4, 2013 (edited) Plus $app is a new instance of a class it doesn't matter what you do it is going to create an error. I still say get the procedural style down pat so you can get a grasp of php and databases. Though turning on error reporting will help you out in the long run. P.S. -> I know you can fetch a class and the following is a snippet of my website // Check that rows were returned: if ($result && $result->rowCount() > 0) { // Set the fetch mode: $result->setFetchMode(PDO::FETCH_CLASS, 'Page'); // Records will be fetched in the view: include('views/index.html'); } else { // Problem! throw new Exception('No content is available to be viewed at this time'); } Edited July 4, 2013 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/279856-display-database-content/#findComment-1439428 Share on other sites More sharing options...
KevHopwood Posted July 4, 2013 Author Share Posted July 4, 2013 (edited) Hi all.. I did use a video tutorial. I used this one: http://www.youtube.com/watch?v=vM6_OCAoiFg i watched all 7 and it worked perfectly. What I then did is added a new table to my mysql called "apps" and I replaced all the column names which where column_??? to app_???. I just assumbed that as I have changed the little details then it must work the same. so can no one tell me where I am going wrong? Edited July 4, 2013 by KevHopwood Quote Link to comment https://forums.phpfreaks.com/topic/279856-display-database-content/#findComment-1439432 Share on other sites More sharing options...
KevHopwood Posted July 4, 2013 Author Share Posted July 4, 2013 (edited) ALSO I do check my error_log actually. but it does not bring back any errors. So how can I know what the errors are? I edit the file via cpannel. Edited July 4, 2013 by KevHopwood Quote Link to comment https://forums.phpfreaks.com/topic/279856-display-database-content/#findComment-1439433 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.