SirChick Posted September 2, 2007 Share Posted September 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted September 2, 2007 Share Posted September 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 2, 2007 Author Share Posted September 2, 2007 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.. Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 bump Quote Link to comment Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 can you give sample out output and brief description of the prob again plzz!! Quote Link to comment Share on other sites More sharing options...
Hypnos Posted September 3, 2007 Share Posted September 3, 2007 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); Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 Thankyou Hypnos i think that is what im needing, ill give it a go and see what happens! Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 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... Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 bump Quote Link to comment Share on other sites More sharing options...
trq Posted September 3, 2007 Share Posted September 3, 2007 Can we see more code? Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 <? 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. Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 bump Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 any one? Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 bump Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 5, 2007 Author Share Posted September 5, 2007 guess ill bump this.. been 2 days now Quote Link to comment Share on other sites More sharing options...
xyn Posted September 5, 2007 Share Posted September 5, 2007 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>"); } ?> Quote Link to comment Share on other sites More sharing options...
SirChick Posted September 5, 2007 Author Share Posted September 5, 2007 where was i complaining :S i was asking for help 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.