Thread: Coding Confusion
Results 1 to 6 of 6
Related
-
My Space Coding Forum: Myspace Forum
Replies: 3 -
do you need Myspace coding help? Forum: Myspace Forum
Replies: 2 -
My Space CSS coding... help! Forum: Myspace Forum
Replies: 0 -
cgi confusion Forum: CGI Perl Forum
Replies: 27
-
07-07-2008, 09:03 AM #1
Coding Confusion
well the code is below before i start my little frustrated rant.
PHP Code:<?php
session_start();
require ('config.php');
include('title.php');
include('resources.php');
$messages = mysql_query("SELECT * FROM messages WHERE user_id='$user'");
$messages2 = mysql_fetch_array($messages);
?>
<table>
<tr><td>From</td><td>Timesent</td><td>Subject</td></tr>
<?php
if($messages2){
while($row = mysql_fetch_array($messages))
{
$sender_id = $row['sender_id'];
$sender1 = mysql_query("SELECT username FROM users WHERE id='$sender_id'");
$sender2 = mysql_fetch_array($sender1);
$sender = $sender2['username'];
$subject = $row['subject'];
$message = $row['message'];
$time = $row['time'];
$date = date('F j, Y, g:i a', $time);
echo "<tr><td>" . $sender . "</td><td>" . $date . "</td><td>" . $subject . "</td></tr>";
}
}
else{echo "<tr><td>You have no new Messages<td></tr>";}
?> </table>
<?php include ('suffix.php'); ?>
I have read on the php website the following, and it seems to apply:
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you must use the numeric index of the column or make an alias for the column. For aliased columns, you cannot access the contents with the original column name.
http://uk.php.net/manual/en/function...etch-array.php
The code does execute without error btw, its just it only displays the final message in the database !
Database includes the following records:
table messages
user_id, sender_id, subject, message, time
1,1,testing123,testing123,1234567890
1,2,tester123,tester123,1234567899
table users
Username=Replicada, id=1
Username=Demo, id=2
Any help would be appreciated thanksLast edited by Replicada; 07-07-2008 at 09:08 AM.
-
07-07-2008, 10:28 AM #2
Re: Coding Confusion
Can you post the error message thrown??
-
07-07-2008, 11:38 AM #3
Re: Coding Confusion
As i said its probably not a fault with my code, as it does execute without error. It's the fact that the Loop does not function as it should.
When the query searches for all messages with user id 1, it should return 2 rows(As there are two messages for user 1), not just 1. Therefore i used a while loop to hopefully produce two rows in my table, but it only retrieves 1 row still, bizarely the last one...
I was just wondering how you retrieve two rows in a query as the function mysql_fetch_array only retrieves a single row, and places it in an array for use in the script.
-
07-11-2008, 09:40 AM #4
Re: Coding Confusion
Try using this code
PHP Code:<?php
session_start();
require ('config.php');
include('title.php');
include('resources.php');
$messages = mysql_query("SELECT * FROM messages WHERE user_id='$user'");
?>
<table>
<tr><td>From</td><td>Timesent</td><td>Subject</td></tr>
<?php
while($row = mysql_fetch_array($messages))
{
...If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
07-11-2008, 02:41 PM #5
Re: Coding Confusion
Are my eyes playing tricks on me or did I just read a post made today by quietdean?
Welcome back stranger!
-
07-15-2008, 10:27 AM #6
Re: Coding Confusion
Hi Dave
If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
[Hostdens] – Cheap Linux Cloud VPS | Cheap Windows VPS...
10-23-2019, 05:25 AM in Web Hosting Forum