Page 1 of 1

my first real php script.

Posted: Tue Feb 08, 2011 11:47 pm
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?

Re: my first real php script.

Posted: Wed Feb 09, 2011 6:18 am
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