View Full Version : MySQL/PHP listing script

8th October 2004, 04:45 AM
Hi All

Just wondering if someone could please give me a pointer?...

I need to develop a simple php webpage(s) where listings from a small mysql database containing books/videos/CDs get listed. I need the database to be searchable & browsable.

Is there a simple php script out there that i could use to start from? I know little php/mysql, but if i can get a pre-built script to start from i should be ok.



8th October 2004, 05:11 PM
Go to http://hotscripts.com/ you may find what you need

8th October 2004, 05:42 PM
try this in a file like list.php

// Database parameter
$host = "localhost";
$user = "jdbc"; // your mysql user
$pass = "test"; // your mysql password
$bdd = "appl"; // Database name

// connection
or die("Connection refused");
or die("Connection refuses");



// sélectionne toutes les fiches de la table $table
$query = "SELECT * FROM personne"; // choose a another table instead of personne :-)
$result = mysql_query($query);

while ($val = mysql_fetch_array($result)) { ?>
<? echo $val["nom"]; ?> -
<? echo $val["email"]; ?><br>
<? }


hope it helps,

21st October 2004, 01:19 PM

Thanks for the replies. I am well on the way now with mysql data displaying well within a web page.

Quick question: Is it possible to develop relationships between tables within MySQL? (i.e. primary key -> foreign key)



21st October 2004, 01:39 PM
mySQL versions before 4.1 don't technically support foreign keys, but instead you can just create a field with the same name as whichever you want to link from.

So, for a table of names, you may have the primary key field as p_ID. On another table you wish to link to the names table, let's say its phone_numbers the phone_numbers table would have a primary key called num_ID and then the next field would be p_ID

when adding info to the list of names you would then use INSERT INTO names (first_name) VALUES ('bob')
then in php use:

$person_ID = mysql_insert_id(); which gets back the primary key from the names table for the person you just entered.

Then to add a number to that person right after you inserted their name, you would then use:

INSERT INTO phone_numbers (p_ID, number) VALUES ('$person_ID', '01424534...')

hope that helped.

EDIT: oh yeah, so when you want to get 'bobs' info from both the tables you would use a statement like so:

SELECT names.p_ID, first_name, number
FROM names, phone_numbers
WHERE names.p_ID = phone_numbers.p_ID
AND first_name = 'bob'

21st October 2004, 01:43 PM
for fast database creation use phpMyAdmin - it is web frontend to MySQL. if you wan't to give users forms for imputing/browsing/searching data check out http://www.dadabik.org/ you can make nice forms very fast with this tool...