Hi Glenn,
Would you not be better using a framework that is already set up rather starting to code from scratch? Oscommerce is a good one and there is a huge support community. You need to however understand the basics of php/mysql to get by.
Another good one if your coding experience is limited (don’t take that the wrong way) is wordpress with woocommerce installed.
Writing it all from scratch is extremely time consuming especially if you are not familiar with php/mysql - (I am speaking from my own personal experience!!!).
If you insist on going down the route of coding yourself I use the following code to list values of my MySQL database (some of the PHP senior members will better my code);-
Create a database connection (called “db-connect.php”)
[php]<?php
// edit the below four lines with your database details
define(‘DB_SERVER’, ‘YOUR SERVER NAME’);
define(‘DB_USERNAME’, ‘YOUR DATABASE USERNAME’);
define(‘DB_PASSWORD’, ‘PASSWORD’);
define(‘DB_DATABASE’, ‘DATABASE NAME’);
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>[/php]
then a page called “index.php”;-
[php]
id |
product name |
price |
stock |
</tr>
</thead>
<tbody>
<?php
include('db-connect.php');
if (mysqli_connect_errno($db)) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
// you need to alter the database table below
$query = "SELECT * FROM `**YOUR DATABASE TABLE NAME**`";
$result = mysqli_query($db, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($db), E_USER_ERROR);
if($result) {
while($row = mysqli_fetch_assoc($result)) {
echo '
';
echo ''.$row['id'] . ' | ';
echo ''.$row['product name'] . ' | ';
echo ''.$row['price'] . ' | ';
echo ''.$row['stock'] . ' | ';
}
}
mysqli_close($db);
?>
</tbody>
</table>
[/php]
This assumes your MySQL table has columns called id, product name, price, stock. You would need to replace these values with yours along with the database details.
I hope this helps…