chocopi Posted June 11, 2007 Share Posted June 11, 2007 So here is my code, but the variables are not showing up, it's probably an easy mistake but i'm tired and my eyes ache I'm sorry for the n00bish question but i really cant see it <?php // start session session_start(); require_once('page_header.php'); // set sessions to variables $id = $_SESSION['id']; $username = $_SESSION['username']; // set board id $board = '1'; // select message id's from db $query = "SELECT `id` FROM `zBoard_messages` WHERE board_id='$board'"; $row = mysql_query($query) or die(mysql_error()); // set db results to variables $id = $row['id']; $poster = $row['poster_id']; $subject = $row['subject']; $text = $row['message']; $date = $row['date']; // get username $query = "SELECT username FROM `zBoard_users` WHERE id='$poster'"; $row = mysql_query($query) or die(mysql_error()); $poster = $row['username']; // convert message into viewer message require_once('bbcode.php'); // get legible date list ($date,$time) = explode(' ',$date); list ($year,$month,$day) = explode('-',$date); $date = "$day/$month/$year"; //display contents echo "<center>"; echo ("At ".$date." ".$time.", ".$poster." wrote:"); echo "<br />"; echo "<br />"; echo "<b>".$subject."</b>"; echo "<br />"; echo "<br />"; echo $text; echo "<br />"; echo "<br />"; echo "THE END"; ?> Cheers, ~ Chocopi Quote Link to comment Share on other sites More sharing options...
Lumio Posted June 11, 2007 Share Posted June 11, 2007 which variables? Quote Link to comment Share on other sites More sharing options...
pikemsu28 Posted June 11, 2007 Share Posted June 11, 2007 $poster = $row['poster_id']; $subject = $row['subject']; $text = $row['message']; $date = $row['date']; to me, it looks like these variables will not show because your query is not populating them. $query = "SELECT `id` FROM `zBoard_messages` WHERE board_id='$board'"; needs to be changed to include the variables or to select all $query = "SELECT * FROM `zBoard_messages` WHERE board_id='$board'"; Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 11, 2007 Author Share Posted June 11, 2007 oh rite, sorry <?php //display contents echo "<center>"; echo ("At ".$date." ".$time.", ".$poster." wrote:"); echo "<br />"; echo "<br />"; echo "<b>".$subject."</b>"; echo "<br />"; echo "<br />"; echo $text; echo "<br />"; echo "<br />"; echo "THE END"; ?> None of them show anything except $date which shows // because it should say ??/??/?? ?? Thanks, ~ Chocopi Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 11, 2007 Author Share Posted June 11, 2007 no adding the * does nothing Quote Link to comment Share on other sites More sharing options...
chigley Posted June 11, 2007 Share Posted June 11, 2007 $query = mysql_query("SELECT `id` FROM `zBoard_messages` WHERE board_id='$board'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); // -------------------- $query = mysql_query("SELECT username FROM `zBoard_users` WHERE id='$poster'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 11, 2007 Author Share Posted June 11, 2007 cheers, but that completly stops the page from outputting anything which is exactly what happened when i used mysql_fetch_array Quote Link to comment Share on other sites More sharing options...
chigley Posted June 11, 2007 Share Posted June 11, 2007 Paste your code with the made changes please Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 11, 2007 Author Share Posted June 11, 2007 Here you go <?php // start session session_start(); require_once('page_header.php'); // set sessions to variables $id = $_SESSION['id']; $username = $_SESSION['username']; // set board id $board = '1'; // select message id's from db $query = mysql_query("SELECT `id` FROM `zBoard_messages` WHERE board_id='$board'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); // set db results to variables $id = $row['id']; $poster = $row['poster_id']; $subject = $row['subject']; $text = $row['message']; $date = $row['date']; // get username $query = mysql_query("SELECT username FROM `zBoard_users` WHERE id='$poster'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); $poster = $row['username']; // convert message into viewer message require_once('bbcode.php'); // get legible date list ($date,$time) = explode(' ',$date); list ($year,$month,$day) = explode('-',$date); $date = "$day/$month/$year"; //display contents echo "<center>"; echo ("At ".$date." ".$time.", ".$poster." wrote:"); echo "<br />"; echo "<br />"; echo "<b>".$subject."</b>"; echo "<br />"; echo "<br />"; echo $text; echo "<br />"; echo "<br />"; echo "THE END"; ?> Quote Link to comment Share on other sites More sharing options...
chigley Posted June 11, 2007 Share Posted June 11, 2007 Looks fine to me.... try get_defined_vars() or print_r($row) to see where there's a kink in the chain. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 11, 2007 Share Posted June 11, 2007 Your only selecting "id" from the table, how do you expect the code to know what $row['date'] is when you didn't tell it what it is? Change this: $query = mysql_query("SELECT `id` FROM `zBoard_messages` WHERE board_id='$board'") or die(mysql_error()); To: $query = mysql_query("SELECT `id`,`poster_id`, `subject`, `message`, `date` FROM `zBoard_messages` WHERE board_id='$board'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 11, 2007 Author Share Posted June 11, 2007 Well this returns: Array ( [id] => 1 ) $query = mysql_query("SELECT `id` FROM `zBoard_messages` WHERE board_id='$board'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); but this is retuning nothing, blank, null, zilch etc $query = mysql_query("SELECT username FROM `zBoard_users` WHERE id='$poster'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); print_r($row); Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 11, 2007 Author Share Posted June 11, 2007 Thanks pocobueno1388 thats sorted it and thanks chigley for your help however, i always use $blah = row['blah']; and it works so i dont get why it hasnt worked this time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.