Hi there ;)
Im building a MySQL table for a menssaging system, its a table that has 3
fields de UserID, MTime and Mess.
My problem is that i cant find a way that using only a mysql query i get the
time and the message, and that for each row.
Basicly the code would look like this, to give an idea...
<?php
$News=mysql_query("SELECT MTime,Mess FROM Star_Mess WHERE UserID = '$UID'
ORDER BY MTime DESC");
while ($line = mysql_fetch_array($News, MYSQL_ASSOC)) {
foreach ($line AS $Date) {
print "\t\t<p><b>$Date</b></p><p>$Mess</p>\n";
}
}
?>
Any ideas how to do it ?
The main look of the thing is to have the Time in bold followed by the
message, and that for each row.
Thx
Marco 4 1870
Marco wrote: Im building a MySQL table for a menssaging system, its a table that has 3 fields de UserID, MTime and Mess. My problem is that i cant find a way that using only a mysql query i get the time and the message, and that for each row.
Basicly the code would look like this, to give an idea...
(slightly edited)
<?php
$News=mysql_query("SELECT MTime,Mess FROM Star_Mess WHERE UserID = '$UID'
ORDER BY MTime DESC");
while ($line = mysql_fetch_array($News, MYSQL_ASSOC)) {
# foreach ($line AS $Date) {
print "\t\t<p><b>{$line['MTime']}</b></p><p>{$line['Mess']}</p>\n";
# }
}
?>
Any ideas how to do it ?
mysql_fetch_array() [as the name suggests] returns an array; so your
$line variable will be something like
$line['MTime'] = '2004-02-03';
$line['Mess'] = 'Message text';
When you do the foreach() to this array, it will loop twice. The first
time $Date will have '2004-02-03' and the second time it will have
'Message text'. Doing it with the foreach gives you no control over each
of the isolated elements; use them directly from the $line array.
Hope this helps.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Marco wrote: Hi there ;)
Im building a MySQL table for a menssaging system, its a table that has 3 fields de UserID, MTime and Mess. My problem is that i cant find a way that using only a mysql query i get the time and the message, and that for each row.
Basicly the code would look like this, to give an idea...
<?php $News=mysql_query("SELECT MTime,Mess FROM Star_Mess WHERE UserID = '$UID' ORDER BY MTime DESC"); while ($line = mysql_fetch_array($News, MYSQL_ASSOC)) { foreach ($line AS $Date) { print "\t\t<p><b>$Date</b></p><p>$Mess</p>\n"; } } ?>
I think this should work:
while ($line = mysql_fetch_array($News, MYSQL_ASSOC)) {
print "\t\t<p><b>".$line['MTime']."</b></p><p>".$line['Mess']."</p>\n";
}
You might want to use htmlentities(), at least on the Mess.
Shawn
--
Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com
"Pedro Graca" <he****@hotpop.com> wrote in message
news:bv************@ID-203069.news.uni-berlin.de... Marco wrote: Im building a MySQL table for a menssaging system, its a table that has
3 fields de UserID, MTime and Mess. My problem is that i cant find a way that using only a mysql query i get
the time and the message, and that for each row.
Basicly the code would look like this, to give an idea...
(slightly edited)
<?php $News=mysql_query("SELECT MTime,Mess FROM Star_Mess WHERE UserID = '$UID' ORDER BY MTime DESC"); while ($line = mysql_fetch_array($News, MYSQL_ASSOC)) { # foreach ($line AS $Date) { print "\t\t<p><b>{$line['MTime']}</b></p><p>{$line['Mess']}</p>\n"; # } } ?>
Any ideas how to do it ?
mysql_fetch_array() [as the name suggests] returns an array; so your $line variable will be something like
$line['MTime'] = '2004-02-03'; $line['Mess'] = 'Message text';
When you do the foreach() to this array, it will loop twice. The first time $Date will have '2004-02-03' and the second time it will have 'Message text'. Doing it with the foreach gives you no control over each of the isolated elements; use them directly from the $line array.
Hope this helps. -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =--
Indeed i noticed it did 2 times the loop ,when i tryed to use it the first
time.
Thanks for your insights.
"Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:40***************@glassgiant.com... Marco wrote: Hi there ;)
Im building a MySQL table for a menssaging system, its a table that has
3 fields de UserID, MTime and Mess. My problem is that i cant find a way that using only a mysql query i get
the time and the message, and that for each row.
Basicly the code would look like this, to give an idea...
<?php $News=mysql_query("SELECT MTime,Mess FROM Star_Mess WHERE UserID =
'$UID' ORDER BY MTime DESC"); while ($line = mysql_fetch_array($News, MYSQL_ASSOC)) { foreach ($line AS $Date) { print "\t\t<p><b>$Date</b></p><p>$Mess</p>\n"; } } ?>
I think this should work:
while ($line = mysql_fetch_array($News, MYSQL_ASSOC)) { print "\t\t<p><b>".$line['MTime']."</b></p><p>".$line['Mess']."</p>\n"; }
You might want to use htmlentities(), at least on the Mess.
Shawn -- Shawn Wilson sh***@glassgiant.com http://www.glassgiant.com
It works great even with out using the htmlentities(), im going to see what
htmlentities do in the manual, just in case i need it or if its better to
use it.
Thanks
Marco This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christian Decker |
last post by:
I wanted to know if is a good idea to create classes that mirror
exactly the structure of a database. This might sound a bit fuzzy but
I'l explain myself with an example:
CREATE TABLE...
|
by: Benny |
last post by:
I just wanted to throw the discussion out there on what the best
practice people feel is for using large objects in a foreach loop. For
example if you are reusing an Image object in a loop like...
|
by: inpuarg |
last post by:
Is it possible to get all controls and all of their children on a
Windows form without using recursive methods ?
|
by: Akira |
last post by:
I noticed that using foreach is much slower than using for-loop, so I
want to change our current code from foreach to for-loop.
But I can't figure out how.
Could someone help me please?
Current...
|
by: Doug |
last post by:
Hi,
I have a collection of objects and I need to compare each item in the
collection to see if it's a match on any or all of the others. I have
stored my collection in an item like so: ...
|
by: Nathan Sokalski |
last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action
that I want to perform on each of the Array values is:
Private Function AddQuotes(ByVal value As String) As String
Return...
|
by: SM |
last post by:
Hello,
I have an array that holds images path of cd covers. The array looks
like this:
$cd = array(
589=>'sylver.jpg',
782=>'bigone.jpg',
158=>'dime.jpg'
);
|
by: Tony |
last post by:
Hello!
Below I have a complete working program.with some simple classes one of
these is a generic class.
Now If I want to implement functionallity so I can compare animal with each
other or...
|
by: =?Utf-8?B?U2llZ2ZyaWVkIEhlaW50emU=?= |
last post by:
Can someone help me convert this to the latest C# syntax using
predicate/delegate? You can see my attempt in the comments.
Also: how would I set a new font for q_ul? q_ul is a WPF TextBlock and I...
|
by: natarajmtech |
last post by:
Hi all,
I have defined some array variables a
*****************************************
@L=('CTT','CTC','CTA','CTG','TTA','TTG');
@S=('TCT','TCC','TCA','TCG','AGT','AGC');
...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |