Jump to content

Loading messages


SirChick

Recommended Posts

 

 

was wondering... say i have 3 messages for a user to read... now what i wanted to do was some how firslt get all the rows.. which i have done:

 

$GetLetters = mysql_query("SELECT * FROM messages WHERE reciever = '{$_SESSION['Current_User']}'");

 

Ok now at the moment there is 2 rows with reciever having ID as current user.

 

What i need to do then some how is to load up the following fields:

 

Sender

Subject

Time Sent

Message

 

Into variables.. now this is simple using 1 message but if you got 2 how would i get 2 separate rows using the same variables to echo them?

 

What i have is a max of 3, so the layout of message display is fixed rather than just adding more to the inbox page which means i can echo the letters in "exact" places using short tags...

 

So what should i do... any thoughts

Link to comment
Share on other sites

Just use a while loop.

 

<?php

$GetLetters = mysql_query("SELECT * FROM messages WHERE reciever = '{$_SESSION['Current_User']}'");

while ($row = mysql_fetch_assoc($GetLetters)){
   echo $row['sender'].'<br>';
   echo $row['subject'].'<p>';
}

?>

 

That will loop through all the rows that match the query.

Link to comment
Share on other sites

right ok thats one option but can i just ask if this is possible:

 

ok say theres 3 rows.

 

Now we have:

 

<Div etc etc >

then

echo $row['sender'].'<br>';

  echo $row['subject'].'<p>';

 

but "only" echo row 1 ^

 

then:

 

<Div etc etc >

then

echo $row['sender'].'<br>';

  echo $row['subject'].'<p>';

 

but "only" echo row 2 ^

 

 

And follow pattern. Reason i ask is because each message are in "specific" places on the page.. but i dont know how to retrieve an "exact" row..

Link to comment
Share on other sites

right ok thats one option but can i just ask if this is possible:

 

ok say theres 3 rows.

 

Now we have:

 

<Div etc etc >

then

echo $row['sender'].'<br>';

   echo $row['subject'].'<p>';

 

but "only" echo row 1 ^

 

then:

 

<Div etc etc >

then

echo $row['sender'].'<br>';

   echo $row['subject'].'<p>';

 

but "only" echo row 2 ^

 

 

And follow pattern. Reason i ask is because each message are in "specific" places on the page.. but i dont know how to retrieve an "exact" row..

 

Every time you call mysql_fetch_*, it fetches the next row in the result. For instance, you could do this:

 

$rowone = mysql_fetch_assoc($GetLetters);
$rowtwo = mysql_fetch_assoc($GetLetters);
$rowthree = mysql_fetch_assoc($GetLetters);

Link to comment
Share on other sites

I tried this:

 

$rowone = mysql_fetch_assoc($GetLetters);
$Subject = $rowone["Subject"];
$From = $rowone["Sender"];
$SentOn = $rowone["Senttime"];
$MessageOne = $rowone["MessageText"];

$rowtwo = mysql_fetch_assoc($GetLetters);
$Subjecttwo = $rowtwo["Subject"];
$Fromtwo = $rowtwo["Sender"];
$SentOntwo = $rowtwo["Senttime"];
$MessageTwo = $rowtwo["MessageText"];

 

But no echo's are working. I put a validation check to "redirect" me if there was no row's found and i tested that by removing all rows from the table and that worked.. so that suggests my query has found the row but it wont do the fetch assoc...

Link to comment
Share on other sites

<?
include("homeloginvariables.php");
$GetLetters = mysql_query("SELECT * FROM messages WHERE Reciever = '{$_SESSION['Current_User']}'");
// Fetch the row from the database

if (!($row = mysql_fetch_assoc($GetLetters))) {
    $bounce = 1;
}

If ($bounce == 1){

header("Location: letterbox.php");
}
else
{
include("energybarinclude.php");
$rowone = mysql_fetch_assoc($GetLetters);
$Subject = $rowone['Subject'];
$From = $rowone['Sender'];
$SentOn = $rowone['Senttime'];
$MessageOne = $rowone['MessageText'];

$rowtwo = mysql_fetch_assoc($GetLetters);
$Subjecttwo = $rowtwo['Subject'];
$Fromtwo = $rowtwo['Sender'];
$SentOntwo = $rowtwo['Senttime'];
$MessageTwo = $rowtwo['MessageText'];

$rowthree = mysql_fetch_assoc($GetLetters);
$Subjectthree = $rowthree['Subject'];
$FromThree = $rowthree['Sender'];
$SentOnThree = $rowthree['Senttime'];
$MessageThree = $rowthree['MessageText'];
}

?>

 

 

Then i have this further down the page:

<font style="font-size:13px" color="#FFFFFF" face="Arial"><b>Subject: <?= $Subject ?><br>
<br><br>

 

<font style="font-size:13px" color="#FFFFFF" face="Arial"><b>Subject:<?= $Subjecttwo ?><br>
<br><br>

 

 

short tags are on by the way.

 

 

Link to comment
Share on other sites

try this... and stop complaining

<?php
$GetLetters = mysql_query("SELECT * FROM messages WHERE reciever = '".$_SESSION['Current_User']."'");
while($result = mysql_fetch_array($GetLetters))
{
echo("<div id=\"id\">Sender: ".$result['sender']."<br>");
echo("Subject: ".$result['subject']."<br>");
echo("Time: ".$result['time']."<br>");
echo("Message: ".$result['message']."<br>");
}
?>

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.