Grow your CSS skills. Land your dream job.

PHP spit table not working

  • # April 5, 2012 at 9:14 pm
    < ?php
    $id=$_SESSION;
    $fetch=mysql_query("SELECT * FROM music WHERE user=$id limit 10") or die(mysql_error());
    echo("
    Title
    Composer
    Type
    ");
    while($row = mysql_fetch_array($fetch))
    {
    echo("
    ");
    echo $row;
    echo("");
    echo("");
    echo $row;
    echo("");
    echo("");
    echo $row;
    echo("");
    echo("");
    }
    ?>

    As I go, it’s probably syntax, but I can’t figure it out. After a while, I figured out I was missing three semicolons, but it still doesn’t work. Developing locally. Trimmed it down to something here.

    You can see what I’m doing–selecting from mysql table and spitting out the first 10 results in a table. Yes, a table. My first use of tables.

    But the table doesn’t show up. That don’t help.

    # April 5, 2012 at 9:29 pm

    I think you need to change mysql_fetch_array to mysql_fetch_assoc

    Does it print the first line of the table that is outside the while loop?

    # April 6, 2012 at 4:32 am

    Where are the

    tags?

    # April 6, 2012 at 2:42 pm

    @karlpcrowley actually no. I’m starting to think it’s something with my include. I guess assos would be better…why didn’t I think of that. But it still doesn’t work.

    @TT_Mark they’re right around this PHP, I just didn’t copypaste them.

    # April 6, 2012 at 7:49 pm

    Just after the query put in

    print_r($fetch);

    It will show an array of data if it’s getting the right information

    # April 6, 2012 at 9:22 pm

    also, during development, you should always use error_reporting( -1 );. It really does help.

    # April 7, 2012 at 10:42 am

    Hem it’s still not working. either of those statements.

    I’m starting to think it’s my include.


    < ?php if(!isset($_SESSION)){
    include_once("login.php");
    } else {
    include_once("display.php") or die();
    }
    ?>

    I put die() there so that the rest of my page will load, but it’s not working.

    @traq what exactly does that do?

    # April 8, 2012 at 8:32 am

    Try require_once() instead of include_once(). That way your script will die if the file cannot be included.

    I’d also echo out mysql_num_rows( $fetch ) just to make sure you’re actually returning rows

    # April 8, 2012 at 9:54 am

    Hi peoples,

    Just like it always does, it works for some random reason now. Either include or require works. Thanks for all your help!

    Red

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".