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 Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/ 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. Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340071 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.. Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340074 Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 bump Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340148 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!! Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340178 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); Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340191 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! Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340421 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... Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340425 Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 bump Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340467 Share on other sites More sharing options...
trq Posted September 3, 2007 Share Posted September 3, 2007 Can we see more code? Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340471 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. Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340480 Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 bump Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340548 Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 any one? Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340650 Share on other sites More sharing options...
SirChick Posted September 3, 2007 Author Share Posted September 3, 2007 bump Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-340869 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 Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-342045 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>"); } ?> Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-342052 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 Link to comment https://forums.phpfreaks.com/topic/67695-loading-messages/#findComment-342067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.