Jump to content

listing


jah_php

Recommended Posts

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";

}

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.