Jump to content

Item catalogue


ThEMakeR

Recommended Posts

I really need some help from this community regarding a script/code (in php) for an item catalogue with the following fields:

id
name
description
image

I have made a database with those four fields in it:

[b]field[/b]                [b]Type[/b]              [b]Collation[/b]                  [b]Null[/b]              [b]Extra[/b]
id                    int(11)                                            NO                auto_increment      <id is primary key
item_name        Text                latin1_swedish_ci        NO
item_desc        Text                latin1_swedish_ci        NO
item_img          Blob                                              NO

^Hope thats clear enough peeps. Well I can make the database but I can't do the PHP code needed to display the contents of that database on a php page. Does anyone have any code or an example of a similar system I can use??

Any help is much appreciated!
Link to comment
Share on other sites

Well, here is the basic concept:

[code]
<?php
//connect to your database
$server = "localhost"; //most common
$user = "user"; //database user
$password = "password"; //database password
$database = "database"; //database

$connection = mysql_connect("$server","$user","$password"); 
$db = mysql_select_db("$database", $connection);   
?>
<table width="100%">
<tr>
<td>ID</td>
<td>Item Name</td>
<td>Item Description</td>
<td>Item Image</td>
</tr>
<?php
$query = "SELECT * FROM table"; //select the results, be sure to change "table" to whatever your table is
$result = mysql_query($query, $connection) or die(mysql_error()); //check the query and connection
while ($row = mysql_fetch_array($result)) { //loop through the results
$id = $row['id'];
$item_name = $row['item_name'];
$item_desc = $row['item_desc'];
$item_img = $row['item_img'];
//echo the results
?>

<tr>
<td><?php echo $id; ?></td>
<td><?php echo $item_name; ?></td>
<td><?php echo $item_desc; ?></td>
<td><?php echo $item_img; ?></td>
</tr>

<?php
}
?>
</table>
[/code]

That should give you the idea. From there you can make your changes etc.
Link to comment
Share on other sites

Lol, I've learned around here that if you want to be the first to answer, then you need to type fast. Which is one of the reasons I always find myself editing the code after posting it due to errors. Then I am thinking "Man, I hope the OP doesn't try this code before I fix the errors".
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.