my first real php script.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

my first real php script.

Post by gaogier »

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?

Code: Select all

<?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?
mehran
Forum Newbie
Posts: 17
Joined: Fri Jan 21, 2011 1:31 am

Re: my first real php script.

Post by mehran »

i thing,
if you add one more column to the db table in which you save the address to which you want the link,
then get the data in the same waye as you get the remaining,
the link would be dynamic like
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td> <a href=". $row['targetpage'] .">".. $row['name'] ."</a></td>";
echo "</tr>";
}
this will dynamicall link all the pages
Post Reply