jah_php Posted August 10, 2010 Share Posted August 10, 2010 i need held on my coding, im a php beginner and cant figure this out. adding new record to the database works fine but populating the table doesnt work, thanks in advance my connection <conf.php> function dbConnect() { $db_host = '127.0.0.1'; $db_user = 'root'; $db_password = ''; $db_name = 'project_estate'; $db_port = 3306; $conn = new mysqli($db_host,$db_user,$db_password,$db_name,$db_port); if (mysqli_connect_errno()) { die("Error Connecting to mySQL!"); } return $conn; <functions.php> <?php include_once('conf.php'); function getSites() { $conn = dbConnect(); $query = "select * from sites"; $result = mysqli_query($conn,$query); if (!$result) { return false; } $numSites = mysqli_num_rows($result); if ($numSites == 0) { return false; } for ($i = 0; $i < $numSites; $i++) { $sites[] = mysqli_fetch_assoc($result); } return $sites; <site_listing.php> include_once('functions.php'); $sites = getSites(); $size = sizeof($sites); for ($i = 0; $i < $size; $i++) { if ($i % 2 == 0) { $color = "#FFFFFF"; } else { $color = "#ECECEC"; } echo "<tr bgcolor=\"$color\">\n"; $site = $sites[$i]; echo "<td>{$site['ID']}</td>\n"; echo "<td>{$site['title']}</td>\n"; echo "<td>{$site['price']}</td>\n"; echo "<td>{$site['description']}</td>\n"; echo "<td><a href=\"edit_site.php?id={$site['id']}\">Edit</a></td>\n"; echo "</tr>\n"; } Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 10, 2010 Share Posted August 10, 2010 I'm not sure what the PHP Applications, Frameworks and Libraries forum section has to do with your code, but - A) You didn't bother to tell us what result you are getting. What do you see in front of you when you try this, and B) You are not testing the value being returned by your functions and outputting any user error messages, so you will never know, and we cannot possibly tell you either, if your query worked or not or if it matched zero rows, yet you are blindly attempting to process the data, which might not even have been returned. For some quick debugging, what does using var_dump($sites); in your main code show? Quote Link to comment 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.