Welcome our webmaster and SEO forum
Please enjoy the forum, contribute what you can, and wind up the Moderators!
Closed Thread
Results 1 to 3 of 3

Thread: problem with Sessions

  1. #1
    StevieB is offline Junior Member StevieB is on a distinguished road
    Join Date
    Aug 2007
    Posts
    5

    Default problem with Sessions

    I'm trying to output sessions "row 0" "row 1" etc and all I get is either a blank output or "Array"

    This was working before I put the loop in.
    I think there's a problem with ['row '.$i]
    I've tried
    $row = "row ";
    $row = $row.$i - but that doesn't work either.

    Can anyone see where i'm going wrong?


    The php is -

    $query = " SELECT * FROM table ORDER BY RAND() LIMIT 1 ";
    for($i = 0; $i <= 2; $i++)
    {
    if($result = mysql_query($query))
    {
    while( $output = mysql_fetch_row($result) )
    {
    // create name and output to session
    $_SESSION ['row '.$i] = $output;
    }
    mysql_free_result($result);
    }
    }


    the output page is

    echo $_SESSION['row 0'];
    echo ' <br>';
    echo $_SESSION['row 1'];
    echo ' <br>';
    echo $_SESSION['row 2'];
    echo ' <br>';

    I can't think of any other way of creating row 0, row 1 in the loop.

    Thanks in advance.
    Steve.

  2. #2
    clau is offline Boss Cart Support clau is on a distinguished road
    Join Date
    Apr 2007
    Posts
    9

    Default

    Hi Steve,

    You get an array at the output page because the $output variable is an array of the columns you have in the table.
    If you want to use a certain column you need to use either $output[column-name] or better, in the output page put
    $row0 = $_SESSION['row 0'];
    echo $row0[column-name1].' '.$row0[column-name2].....

    Claudiu

  3. #3
    StevieB is offline Junior Member StevieB is on a distinguished road
    Join Date
    Aug 2007
    Posts
    5

    Default

    Ah yes, of course, I mised that.
    Cheers mate, spent ages trying to suss it out.

    have changed the processing page to ~

    for($i = 0; $i <= 2; $i++)
    {
    if($result = mysql_query($query))
    {
    while( $row = mysql_fetch_row($result) )
    {
    $output = $row[$i];
    $_SESSION ['row '.$i] = $output;
    }
    // free results
    mysql_free_result($result);
    }
    }




    Works now.

    Thanks again.

    Steve

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. If you ever had this problem...
    By OldDarkstarAccount in forum General Webmaster Talk
    Replies: 8
    Last Post: 11-06-2007, 07:43 AM
  2. problem with Sessions
    By StevieB in forum General Webmaster Talk
    Replies: 0
    Last Post: 09-21-2007, 12:57 PM
  3. little problem
    By Bisje in forum Feedback (Don't holdback :)
    Replies: 6
    Last Post: 09-20-2007, 10:40 AM
  4. Problem!
    By smartu in forum iG Shop
    Replies: 0
    Last Post: 01-14-2004, 04:41 AM
  5. Problem
    By Funnydummy in forum iG Shop
    Replies: 0
    Last Post: 11-04-2003, 11:10 AM

Bookmarks

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

Search Engine Friendly URLs by vBSEO 3.6.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124