how to mysql/php page navigate?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
buzzby
Forum Newbie
Posts: 9
Joined: Sun Oct 12, 2003 2:13 pm

how to mysql/php page navigate?

Post by buzzby »

hi there. i am so stuck. i want to use a php/mysql navigation type setup. i have written the mysql code which is this:

CREATE TABLE profile (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
picture CHAR(30) NOT NULL,
PRIMARY KEY (id)
)

load data infile "c:/apache/htdocs/lojsite/database/profiletable1.txt" into table profile
fields terminated by ','

the profiletable1.txt contains lines like this:

6, /pics/pics6.jpg, text 6 text 6 text 6 text 6 text 6 text 6
(it is comma delimited)

i want to show each row as a page so in effect you get this view.php?id=23 where the 23 record that i insert into mysql is what will be shown.

i would love it if you could help me out in this.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You have a id and a picture field in the table, but looking at:
6, /pics/pics6.jpg, text 6 text 6 text 6 text 6 text 6 text 6
I'm wondering where the
, text 6 text 6 text 6 text 6 text 6 text 6
part ends up...

Neverless, this is just a small example, untested but the ideas are there for you to lookup in the manual:

Code: Select all

<?php
    // apage.php
    // db connection here
    $result = mysql_query("select id, picture from profile");
    while ($row = mysql_fetch_array($result)) {
        echo '<a href="image.php?id='.$row['id'].'">'.basename($row['picture']).'</a><br />';
    }
?>

Code: Select all

<?php
    // image.php
    // db connection here
    if (!empty(instval($_GET['id']))) {
        $result = mysql_query("select * from profile where id = $_GET['id']");
        while ($row = mysql_fetch_array($result)) {
            echo 'ID: '.$row['id'].'<img src="'.$row['picture'].'">';
        }
    }
buzzby
Forum Newbie
Posts: 9
Joined: Sun Oct 12, 2003 2:13 pm

Post by buzzby »

does this use includes? i dont wat to go down the avenue of includes
Post Reply