Sharkadder Posted August 22, 2008 Share Posted August 22, 2008 Hi, on my website i am using $_SESSION variable, now i am new to how this works but basically this is what i am trying to do.If a database has a value in then it displays the row from that database, if the database doesn't have a value in, i'd like to display the text "you don't have any subscriptions"I have been trying this the last hour and cannot get it working right, here is my current code:$dbHost = '********.net';// Database Connection Details - Host$dbUser = 'dream*****';// Database Connection Details - Username$dbPass = '********';// Database Connection Details - Password$dbname = '******';// Database Connection Details - Database Name$db = mysql_connect($dbHost,$dbUser,$dbPass); // Connection Codemysql_select_db($dbname,$db); // Connects to database$query = "SELECT Username, Boxtype, Sublength, Subleft, Startdate, Expirydate FROM satellitebox WHERE Username = '$username'";$result = mysql_query($query, $db);SESSION_START();$_SESSION['displaydata'] = 1;if(mysql_num_rows($result)){$row = mysql_fetch_assoc($result);$newline = "<br />";// If the login information is correct do the following;echo "Username : {$row[username]} ".$newline;echo "Box Type : {$row[boxtype]} ".$newline ;echo "Subscription Length : {$row[sublength]} ".$newline ;echo "Subsciption Length Remaining : {$row[subleft]} ".$newline ;echo "Start Date : {$row[startdate]} ".$newline ;echo "Expiry Date : {$row[Expirydate]} ".$newline ;}else{ $_SESSION['displaydata'] = 'you currently have no subscriptions'; echo $SESSION['displaydata'];}ok i have commented out the server details but in the live version i have they are included so that isn't the problem, why is it then when i do the database lookup and they isn't a record with the $username variable i cannot display the text "you currently have no subscriptions"?, but yet if the $username variable is in the database, it will display all the frields relating to that record.thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted August 22, 2008 Share Posted August 22, 2008 $_SESSION['displaydata'] =echo $SESSION['displaydata'];Why are you even using the session at all though? The session is for saving data across several pages, you don't need to use the session for data on a single page. Link to comment Share on other sites More sharing options...
Sharkadder Posted August 23, 2008 Author Share Posted August 23, 2008 if session is wrong, how do you think i should do it then? I tried just using a normal variable to store the info, but i couldn't get that working either. If i have done it the wrong way then a different solution will be apprechiated.thanks Link to comment Share on other sites More sharing options...
rattlsnak Posted August 23, 2008 Share Posted August 23, 2008 else (mysql_num_rows($results) == 0){echo "no search results found!";} Link to comment Share on other sites More sharing options...
Sharkadder Posted August 23, 2008 Author Share Posted August 23, 2008 ok thanks for that, just shows how daft i was forgetting to just put a basic else after the if statement. Your else didn't work with the =0 bit, so i just putelse {echo "you currently have no subscriptions";}Now it works fine, excerllent (y) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.