Jump to content


Photo

Using SESSION data to form a new SELECT query


  • Please log in to reply
No replies to this topic

#1 N30Cr0n

N30Cr0n
  • Members
  • PipPip
  • Member
  • 21 posts
  • LocationUK

Posted 08 August 2006 - 10:59 AM

Hi, i have been building a football prediction website, found here http://premscore.smokingunz.co.uk, 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 nuke_sessions, 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.

<?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

?>

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 echo 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
..:: [SG]N30Cr0n ::..
-= Co-Founder =-

Smokin Gunz [SG] Evolution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users