Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: WHERE Statement

  1. #11
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Great... It works - except, it shows 8 entries for each row! So I have 16 boxes for 2 rows... ???

    Thanks for the base code Schmoopy!

    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  2. #12
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    What fields do you have in your database?

    You put that after the row, like:

    PHP Code:
    echo $row['email']; 
    Are you saying it's duplicating the same row?

    Can you show me some code / outputs?

  3. #13
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Here's a couple screenshots:

    http://x96webdesign.uuuq.com/xtra/repeating_rows/

    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  4. #14
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ok, and the code?

  5. #15
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Just added it to the page I linked to...

    // X \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  6. #16
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ah you've combined the two, you're getting it from the database, then going through that array in another loop...

    Change it to:

    PHP Code:
    $sql mysql_query("SELECT * FROM notes");
    while(
    $row mysql_fetch_array($sql)) {
    // Code here (echo '<div></div>' etc...)

    Just a quick side note, it's more efficient to not output HTML markup in an echo, so instead of:

    PHP Code:
    <?php
    if($var) {
    echo 
    "<div>more html in here</div>";
    }
    ?>
    You should put:


    PHP Code:
    <?php
    if($var) { 
    ?>
    <div>more html in here</div>
    <?php
    }
    ?>
    so you go in and out of PHP. This should make your page load faster.

    Anyways, hope that fixes it.

    Edit: Better explanation for why it repeats 4 times:

    You're querying the database for the fields and then putting that into the $row array. You have 4 fields so $row contains 4 items.

    So it's going through $row[0], output all the code in that record, then going to $row[1] -> $row[2] -> $row[3]

    Etc...

    Hope you understand that.

  7. #17
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Okay... Thanks Schmoopy! It works perfectly. And I edited the code to be in and out of PHP.

    Cheers,
    X96
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  8. #18
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Here's another question - deleting table rows...

    I want to delete a table row by using GET and the ID equals the ID for the row to be deleted...

    I'm using this, but It won't work:
    Code:
    if($_GET['delete'] == $unique) {
    	mysql_query("DELETE FROM `notes` WHERE `owner` = '$sessionuser' AND `id` = '$delete'");
    }
    	$delete = $_GET['delete'];
    	$sessionuser = $_SESSION['username']
    	$unique = $row[3];
    Wow - this thread has changed topics about 5 times!

    Thanks,
    X96
    Last edited by X96 Web Design; 05-09-2009 at 11:31 PM. Reason: Spelling...
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  9. #19
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Don't use ticks (`) for the table name, you've got it right for the column names but the table name doesn't need ticks:

    PHP Code:
    "DELETE FROM notes WHERE `owner` = '$sessionuser' AND `id` = '$delete'" 
    See if that works.

  10. #20
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Nope... Nothing is deleted...

    Is there something wrong with all the variables? Even I get confused with all the variables calling variables... and I wrote it!

    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

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
  •