Jump to content


Photo

Item catalogue


  • Please log in to reply
4 replies to this topic

#1 ThEMakeR

ThEMakeR
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 August 2006 - 01:08 PM

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:

field                Type              Collation                  Null              Extra
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!

#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 15 August 2006 - 01:25 PM

Well, here is the basic concept:

<?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>

That should give you the idea. From there you can make your changes etc.

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 15 August 2006 - 01:36 PM

^lol beat me to it. Speedy..Speedy.lol. I guess I should retake a typing class.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 15 August 2006 - 01:39 PM

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

#5 ThEMakeR

ThEMakeR
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 August 2006 - 04:29 PM

Wow!

That was mega quick and muchly appreciated! I will work on it now. See now that i've looked at it in the code (so to speak) I see how it all works but im damned if i'll ever learn how to do it myself :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users