Forum Moderators: coopster

Message Too Old, No Replies

Problem simulating a multiple php-mysql query

         

stefanolanci

11:04 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



Goodmorning everybody.

I'm a newby in LAMP.

I got 2 mysql tables in database "X"

1rst table Users has 2 fields i'm interested with:
"ID": is a varchar(8) containing ID of registered users
"Image": is a blob containing uploaded thumbnails of registered users.

2nd table Online has two fields i'm interested with:
"Connected" and "Room".
Both fields are int(11)

Both 2nd table fields are autoupdated by a a chat "engine" depending on wich users are logged-in inside the chat.

The 2nd table field "Connected" can contain only values available also in the 1rst table->field ID.
In fact users logged in the chat can be only registered ID users.

My goal is to create a php script able to check who's "Connected" in the chat then display the right "Image" in a autoupdating html page showing in a 3 columns table the right values: "Image"; "Connected" or "ID" and "Room" of the chat logged-in users.

Who can give me an help?
GD libraries allowed.
Thanks.

stefanolanci

8:02 pm on Apr 22, 2009 (gmt 0)

10+ Year Member



I changed structure and actualy i write in the "Image" field only path to the pic.
Eveything works, only the script below used to output the querys in the HTML page doesn't... one only row of the generated html table is displayed showing 1st userName data found in using first query.

why doesn't work? While cycle break because of second query?

<?php
$query = "SELECT userName, channel FROM $tabella_online";
$result = mysql_query($query);
if(!$result) messaggio_errore(errore_sql());

while($query_data = mysql_fetch_array($result)) {
$nome = $query_data["userName"];
$stanza = $query_data["channel"];
$query = "SELECT immagine FROM $tabella_utenti WHERE id='$nome'";
$result = mysql_query($query);
if(!$result) messaggio_errore(errore_sql());
$query_data = mysql_fetch_array($result);
$path = "./".$query_data["immagine"];
echo "<TR>";
echo "<TD WIDTH=\"33%\" ALIGN=\"CENTER\"><img src=\"$path\" width=100%></TD>\n";
echo "<TD WIDTH=\"33%\" ALIGN=\"CENTER\">$nome</TD>\n";
echo "<TD WIDTH=\"33%\" ALIGN=\"CENTER\">$stanza</TD>\n";
echo "</TR>\n";
}
?>

stefanolanci

9:16 pm on Apr 22, 2009 (gmt 0)

10+ Year Member



sorry for disturbing
i got it
same variables names in second query

ha ha ha

coopster

12:25 pm on Apr 23, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, stefanolanci.

It seems like a JOIN might work here, too. Here is an example of a "who's online" solution that may be helpful to study:
[webmasterworld.com...]