SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    First ID not listed...

    I was able to pull the records from two tables together with select and inner join command, but for some reasons it won't show the first id records. Since I'm new to mysql and Joins concept, I'm sure I missed something or set up in wrong way. Could use a help here:

    Code:
    SELECT * FROM project INNER JOIN project_depth USING (projectDEPTH_id)

    Tables setup:
    CREATE TABLE project (
    project_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(30),
    type VARCHAR(30),
    rolloverIMG VARCHAR(50),
    rolloutIMG VARCHAR(50),
    imageALT VARCHAR(50),
    targetPAGE VARCHAR(20),
    comment VARCHAR(255),
    projectDEPTH_id INT(11)
    );

    CREATE TABLE project_depth (
    projectDEPTH_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    application VARCHAR(30),
    img01 VARCHAR(50),
    img02 VARCHAR(50),
    img03 VARCHAR(50),
    img04 VARCHAR(50),
    nimg01 VARCHAR(50),
    nimg02 VARCHAR(50),
    nimg03 VARCHAR(50),
    nimg04 VARCHAR(50),
    name01 VARCHAR(50),
    name02 VARCHAR(50),
    name03 VARCHAR(50),
    name04 VARCHAR(50),
    launchURL VARCHAR(60),
    launchW INT(11),
    launchH INT(11)
    );

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    looks okay to me

    can you show a few sample rows of data, especially the ones that you say it wouldn't show?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just gave Terminal a try a few minutes ago and was able to pull all records. So the problem lies in the webpage w/php commands. The page won't list the first id while it pulls another records.

    Connect to tables in database:
    PHP Code:
    $query_projects "SELECT * FROM project INNER JOIN project_depth USING (projectDEPTH_id)";
    $projects mysql_query($query_projects);
    $row_projects mysql_fetch_array($projects);
    ?> 

    Get records from tables:
    PHP Code:
    <?php 
    while ($row_projects mysql_fetch_array($projects)) 

    ?>
    <?php 
    echo $row_projects['project_id']; ?> <?php echo $row_projects['title']; ?> 

    <?php echo $row_projects['application']; ?> <?php echo $row_projects['img01']; ?> <?php echo $row_projects['img02']; ?>
    <?php 
    ?> 

    <?php
    mysql_free_result
    ($projects);
    ?>

  4. #4
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Gent, Belgium, Europe, World, Univers
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You fetch it ..

    $row_projects = mysql_fetch_array($projects); <-- Fetches record 1

    then loop while fetchin it ..

    while ($row_projects = mysql_fetch_array($projects)) <-- Fetches record 2
    {
    Shows records ... but not 1 since 2 has been fetched.
    }

    Just remove the first fetch ... :-)

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah! Got it. Didn't realize the first fetch would interfere the fetch function...

    Thanks for this tip!

    Jace


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •