Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Help: display data from the database to the page

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30973
    Hadley17
    Member

    Hello,

    this is the chunk of code i have so far,

    //call the session variable from the registration page
    $userNameLog = $_SESSION;
    $query = "SELECT game_name, game_genre, company, system, bge, comments
    FROM mylist
    WHERE username = '" . $userNameLog. "'";

    echo $query;
    //submit query
    $rs = mysqli_query($oConn, $query);
    //create a variable to hold the array of data in your database
    $myarray = mysqli_fetch_array($rs);
    //create variables to hold the data in each field
    $oldGameName = $myarray;
    $oldGenre = $myarray;
    $oldCompany = $myarray;
    $oldSystem = $myarray;
    $oldBGE = $myarray;
    $oldComments = $myarray;
    //add the session variable into a variable to be able to echo it out.
    echo $myarray;

    Basically, the user that logged in, creates a random list(fills out my form) now i want them to see what is in the database, but for some reason this order isn’t working.. This basic format worked for displaying their profile but for the list it doesn’t work.

    I’m sure it has something to do with the query and I dont know how to connect the logged in user and the mylist table in sql and then display the info..

    Help or guidance would be sweet!

    #70013
    TT_Mark
    Member

    Hi Hadley,

    You cannot ‘echo’ an array if that way. To write an array to the page you need to use

    print_r($myarray)

    However, what you need to do is write out the other variables that you have assigned your results to e.g.

    echo $oldComments
    #69942
    Hadley17
    Member

    i was just echoing the myarray to see if anything was actually present in it.. and second well, when i echo the variables that hold the certain parts of the DB, it doesn’t echo anything out…

    #69966
    Rob MacKay
    Participant

    What he means is you actually just can’t echo an array – as in it’s impossible it will show nothing. You have to echo specific values or dump the whole thing with print_r(). print_r(); will show you the keys and values of all your entries. If you wrap it in pre tags you will get a nicely formatted display too…



    echo "
    ";
    print_r($myarray);
    echo "

    ";

    #69979
    Hadley17
    Member

    ok well, i still can get them to display and time is running short to get this done :(.. i dont even understand php.

    im getting the values from my form inserted into my table, which is good.

    next, they dont wanna display.. and how can we set this up so when I keep filling out this form, it keeps adding them to the page.. my while loop isnt working too too well :S

    #69896
    Rob MacKay
    Participant

    Well you need to be using mysqli properly. Off the top of my head



    $rs = new mysqli($HostName, $UserName, $Password, $DBName);

    $query = "SELECT game_name, game_genre, company, system, bge, comments
    FROM mylist
    WHERE username = $userNameLog";

    $result = $rs->query($query);

    $myarray = $result->fetch_array(MYSQLI_ASSOC);

    echo "
    ";
    print_r($myarray);
    echo "

    ";

    If that dosen’t work or something around that, check the manual on the functions you are trying to use…

    http://php.net/manual/en/mysqli-result.fetch-array.php

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.