Hi , I have a script that , when you execute it , it select data in mysql , and allow you to download the .txt file after (it isn't database table or other.)
I have two tables :
Mail , that contains : id , author , subject , content and date.
Mail_link contains : id , player_id , message_id and read.
When I execute , I need to select every message_id in Mail_link that is owned by player_id, and then store in an array.
After , I have another query that will scan the table Mail
to find every message (id) called by message_id.
The code is like this :
header("Content-Type: text/x-delimtext; name=Sauvegarde de courrier.txt");
header("Content-disposition: attachment; filename=Sauvegarde de courrier.txt");
echo "#\n";
echo "# Sauvegarde du courrier\n";
echo "# echo "#\n# DATE : " . gmdate("d-m-Y H:i:s", time()) . " GMT\n";
echo "#\n";
mysql_connect($serveur,$nom,$passe) or die('MySQL error!');
mysql_select_db($base) or die('MySQL error!');
$select[0] = "SELECT message_id FROM mail_link WHERE player_id='$pid'";
$request[0] = mysql_query($select[0]);
$res = mysql_fetch_array($request[0]);
$num_results = mysql_num_rows($request[0]);
foreach( $res as $key){
$select[1] = "SELECT author, subject, date, content FROM mail WHERE id =$key";
$request[1] = mysql_query($select[1]);
$i=0;
while($results = mysql_fetch_array($request[1])) {
$i++;
echo "Auteur : ".$results['author']."\n";
echo "Sujet : ".$results['subject']."\n";
echo "Date : ".$results['date']."\n";
echo "Message : ".$results['content']."\n\n\n\n";
}
}
But it only shows 2 times the same query , even if there's only one or only 3.
Thanks for your help.
I have two tables :
Mail , that contains : id , author , subject , content and date.
Mail_link contains : id , player_id , message_id and read.
When I execute , I need to select every message_id in Mail_link that is owned by player_id, and then store in an array.
After , I have another query that will scan the table Mail
to find every message (id) called by message_id.
The code is like this :
header("Content-Type: text/x-delimtext; name=Sauvegarde de courrier.txt");
header("Content-disposition: attachment; filename=Sauvegarde de courrier.txt");
echo "#\n";
echo "# Sauvegarde du courrier\n";
echo "# echo "#\n# DATE : " . gmdate("d-m-Y H:i:s", time()) . " GMT\n";
echo "#\n";
mysql_connect($serveur,$nom,$passe) or die('MySQL error!');
mysql_select_db($base) or die('MySQL error!');
$select[0] = "SELECT message_id FROM mail_link WHERE player_id='$pid'";
$request[0] = mysql_query($select[0]);
$res = mysql_fetch_array($request[0]);
$num_results = mysql_num_rows($request[0]);
foreach( $res as $key){
$select[1] = "SELECT author, subject, date, content FROM mail WHERE id =$key";
$request[1] = mysql_query($select[1]);
$i=0;
while($results = mysql_fetch_array($request[1])) {
$i++;
echo "Auteur : ".$results['author']."\n";
echo "Sujet : ".$results['subject']."\n";
echo "Date : ".$results['date']."\n";
echo "Message : ".$results['content']."\n\n\n\n";
}
}
But it only shows 2 times the same query , even if there's only one or only 3.
Thanks for your help.