Jump to content

my first real php script


gaogier

Recommended Posts

Okay, so this is my first real php script from scratch.

 

This is the theory of the script I am writing.

 

 

Mysql database connect script already done.

 

So, first things I need to do is connect, right?

 

<?php
//connect to db
require_once ('includes/connect.php');

//connect to table
$result = mysql_query ("select * FROM shop1");

//display data in table
echo "<table border='1'><tr><td>Shop</td><td>city</td><td>members</td></tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['members'] . "</td>";
echo "</tr>";
}
echo "</tr></table>";

?>

 

Displays this, http://67.23.249.45/~gaogier/shop1.php

 

What do you think so far?

 

 

 

Whats still to come.

 

How do I link 2 tables together?

  I mean, I plan to have many shops displayed, then, inside the shop, have the items, which will be linked to each shop.

 

I plan to link each shop to a different page, which will be displayed like, url/shop/shopname 

 

 

If you are confused, i need to have a working shop database that works like this, http://www.tip.it/runescape/?rs2shops

 

I don't care about styling at the moment, I just want the script to work.

 

What do I do now?

Link to comment
Share on other sites

Give the shops a unique id, if your not already.

 

Then create a table called items, give items one field called id, that is a unique number, and a second field called owner, that is the id of the shop they belong too.

 

Make a page called items.php, that prints out all the items. Then make it so, if you pass a shop, it only shows the items for that shop. So, items.php?shop=1 would show all the items in 'Two Feet' Charley's Fish Shop.

 

Then, on your shop page, link to items.php?id=X , where X is the id of the shop.

 

I'd worry about the url/shop/shopname thing later, it's a little advanced and you can always add it at the end anyway.

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.