Jump to content

Using SESSION data to form a new SELECT query


N30Cr0n

Recommended Posts

Hi, i have been building a football prediction website, found here [url=http://premscore.smokingunz.co.uk]http://premscore.smokingunz.co.uk[/url], and i have run into a problem with part of the design.

what i would like to happen, is that when a user logs in, the username is stored somehow, and then i can reference that username in a generic select statement, so i can create one page, but it will show different data depending on the username.

i know this is done with sessions, and i am using php-nuke, which has a table called [b]nuke_sessions[/b], and this stores the username of all currently logged in users. so thats that session part covered, i can use that, but what i want is this,

on a page called, say predicta.php, i want to start by pulling the session data for username from nuke_sessions, and then form a new query based on this, e.g.

[code]<?php

....start of page code

$sql = "SELECT uname FROM ".$prefix."_session WHERE uname='$username'"; //query to SELECT username data from session table
$result = $db->sql_query($sql);
$row2 = $db->sql_fetchrow($result);
$entrant = $row2[uname];

$aug01 = $db->sql_query("SELECT id, team_a, team_b, date, time, score_a, score_b FROM predictions_".$entrant." WHERE date = '2006-08-19' ORDER BY date ASC"); //query to SELECT data from specific table based on session data selected above

....rest of page code below

?>[/code]

so from that i would expect that it pick the username data from nuke_session, and store it for use in the select query to pick the data up from predictions_(username from session table) e.g. predictions_johnsmith, because johnsmith is the username logged in the session table.

what i get, is the framework of the page, but no data, and when i [color=blue][b]echo[/b][/color] the sql queries, the output to the page is an empty line, so i am missing something, as the request is not being processed. can anybody spot it and help out/ solve it?

thanks a million
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.