Jump to content

[SOLVED] variables not showing


chocopi

Recommended Posts

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 :P 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

Link to comment
Share on other sites

$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'";

Link to comment
Share on other sites

oh rite, sorry  :D

 

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

Link to comment
Share on other sites

$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());

Link to comment
Share on other sites

Here you go  ;D

 

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

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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);

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.