Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
MySQL DB Control Center - array.php

array.php

Caricato da: Piero Tofy
Scarica il programma completo

  1. <?php
  2. //Titolo
  3. echo "<div align='center'><font size=4>Gestione Array</font><p>Tabella selezionata: $table<p>";
  4.  
  5. include("mysql_data.txt");
  6. include("extras.txt");
  7.  
  8. echo "$input_style";
  9.  
  10. echo "<head><title>Gestione Array del Database $database</title></head>";
  11. $link=mysql_connect($db_host,$db_login,$db_pass)
  12.   or die("Non riesco a connettermi al server <b>$db_host");
  13.  
  14. mysql_select_db($database,$link);
  15.  
  16.  
  17. if (isset($table)){
  18. //Carica l'Help
  19. echo "
  20. <script language='javascript'>
  21. function help(testo){
  22. alert (testo);
  23. }
  24. </script>";
  25.  
  26. //Visualizzare i Record
  27. $all="SELECT * FROM $table";
  28. $query=mysql_query($all,$link)
  29. or die("Non riesco ad eseguire la richiesta $all");
  30.  
  31. $righe=mysql_num_rows($query);
  32. $colonne=mysql_num_fields($query);
  33. echo "<div align='center'>Numero Record: $righe<div align='center'>Numero Campi: $colonne<p>";
  34.  
  35. //Visualizza i nomi dei campi...
  36. $values=mysql_fetch_array($query);
  37. $count_fields=0;
  38. echo "<div align='center'><table border=1><tr>";
  39. while($count_fields<$colonne){
  40. echo "<td><b>".mysql_field_name($query,$count_fields)."</b></td>";
  41. $count_fields++;
  42. }
  43. echo "</tr></table><p>";
  44.  
  45. //Inserisce il form per l'array...
  46. //Importa
  47. $align="center";
  48. echo "<form>";
  49. echo "<input type='hidden' name='table' value='$table'>";
  50. echo "<input type='hidden' name='import' value='OK'>";
  51. echo "<div align='$align'>Prendi Array dal file esterno: <input type='text' name='filename' value='array_file.txt'><input type='button' value='?' onclick=\"help('Inserisci il nome del file da cui prelevare l Array.')\">";
  52. echo "<div align='$align'>Campo ID: <select name='campoid'><option>Si<option>No</select><input type='button' value='?' onclick=\"help('Si consiglia attivare questa funzione se nella tabella è presente un campo ID oppure un campo per identificare i record. Nella maggior parte delle tabelle è presente un campo ID.')\"><p>";
  53. echo "<input type='submit' name='cmdinsert' value='Inserisci Array'><p>";
  54. echo "</form>";
  55. //Esporta
  56. echo "<form>
  57. <input type='hidden' name='table' value='$table'>
  58. <input type='hidden' name='export' value='OK'>
  59. <input type='submit' value='Ricevi Array'>
  60. <div align='$align'>Campo ID: <select name='campoid'><option>Si<option>No</select><input type='button' value='?' onclick=\"help('Si consiglia attivare questa funzione se nella tabella è presente un campo ID oppure un campo per identificare i record. Nella maggior parte delle tabelle è presente un campo ID.')\">";
  61. //Ricerca i campi e li inserisce in un option button...
  62. echo "<div align='$align'>Order By: <select name='order_value'>";
  63. $count_fields=0;
  64. while($count_fields<$colonne){
  65.  echo "<option>".mysql_field_name($query,$count_fields);
  66.  $count_fields++;
  67. }
  68. echo "</select><p>";
  69. echo "</form>";
  70. if (!isset($export)) echo "<p><textarea name='datax_array' rows='8' cols='80'></textarea><p>";
  71.  
  72. }
  73.  
  74. //Sistema per importare un array...
  75. if (isset($import)){
  76. echo "<b>Inserimento dati in corso...</b><div align='center'>";
  77. include("$filename");
  78.  
  79. if ($campoid=="Si"){
  80. $colonne--;
  81. }
  82. $array_count=(count($datax)/$colonne);
  83.  
  84. //Ripete il ciclo per un numero di volte che è uguale al numero di record da inserire
  85. for ($count=0;$count<$array_count;$count++){
  86. $sql_string="";
  87.  
  88. if ($campoid=="Si"){
  89.  $sql_string=$sql_string."'',";
  90. }
  91.  for ($countx=0;$countx<$colonne;$countx++){
  92.   $x=$countx+($colonne*$count);
  93.   if ($countx<$colonne-1){
  94.    $sql_string=$sql_string."'$datax[$x]',";
  95.   }else{
  96.    $sql_string=$sql_string."'$datax[$x]'";
  97.   }
  98.  }
  99. //Inserisce i dati nella tabella
  100. $dati="INSERT INTO $table VALUES($sql_string);";
  101. mysql_query($dati,$link)
  102. or die ("Non riesco ad inserire correttamente i dati con il comando $dati. Il comando è al $count ciclo.<p><div align='center'><input type='button' name='cmdexit' value='Go to $main' onclick=\"location.href='$main'\">");
  103. $record=$count+1;
  104. echo "Ho inserito $record record.</font><div align='center'>";
  105. }
  106. echo "<b>Inserimento dell'array completato con successo!</b><p>";
  107.  
  108. }
  109.  
  110.  
  111.  
  112. //Sistema per esportare i dati in un array
  113. if (isset($export)){
  114. //Legge i dati
  115. $all="SELECT * FROM $table ORDER BY $order_value";
  116. $query=mysql_query($all,$link)
  117. or die("Non riesco ad eseguire la richiesta $all");
  118.  
  119. $rows=mysql_num_rows($query);
  120. $fields=mysql_num_fields($query);
  121.  
  122. $string="";
  123. $string="\$datax=array(";
  124. if ($rows==0) $string="Non ci sono record da Ricevere...(   ";
  125.  
  126. while($values=mysql_fetch_array($query)){
  127. $count_fields=0;
  128.  while($count_fields<$fields){
  129.  //Controlla il Campo ID...
  130.   if ($count_fields==0){
  131.    if ($campoid=="No"){
  132.     $string=$string.'"'.$values[$count_fields].'",';
  133.    }
  134.   }else{
  135.    $string=$string.'"'.$values[$count_fields].'",';
  136.   }
  137.   $count_fields++;
  138.  }
  139. //Inserisce la tabulazione...
  140. $string=$string."
  141.         ";
  142. }
  143. //Toglie gli ultimi caratteri (tab+enter+virgola...)
  144. $x_string=$string;
  145. $string="";
  146. for ($x=0;$x<(strlen($x_string)-3);$x++) $string=$string.$x_string[$x];
  147.  
  148. //Chiude l'array....
  149. $string=$string.');';
  150.  
  151. //Stampa il risultato sullo schermo...
  152. echo "<p><textarea name='datax_array' rows='8' cols='80'>$string</textarea><p>";
  153.  
  154. }
  155.  
  156. //Chiude il programma!
  157.  
  158.  
  159. echo "<div align='center'><input type='button' name='cmdexit' value='Go to $main' onclick=\"location.href='$main'\"><hr>";
  160.  
  161.  
  162. //Ricerca le tabelle e le manda sullo schermo
  163. $result=mysql_list_tables($database,$link);
  164. $i=0;
  165. $table_count=mysql_num_rows($result);
  166. echo "<form><div align='center'>";
  167. echo "<select name='table'>";
  168. while($i<mysql_num_rows($result)){
  169.   $tb_names[$i]=mysql_tablename($result,$i);
  170.   echo "<option>$tb_names[$i]";
  171.   $i++;
  172. }
  173. echo "</select><p>";
  174. echo "<input type='submit' value='Seleziona la Tabella'>";
  175. echo "</form><p>";
  176.  
  177.  
  178. mysql_close($link);
  179. ?>
  180.  
  181. <html>
  182. <body>
  183. </body>
  184. </html>