Ciao ragazzi!
come da titolo, un niubbo vi chiede un parere, come posso ottimizzare questo script? A parte il fatto che mancherebbe la parte di validazione dell'array $array che pensavo di ottenere con un if ($array[]=0) echo "nessun valore" else {prosegui con lo script} (ditemi se ho pensato bene).
come da titolo, un niubbo vi chiede un parere, come posso ottimizzare questo script? A parte il fatto che mancherebbe la parte di validazione dell'array $array che pensavo di ottenere con un if ($array[]=0) echo "nessun valore" else {prosegui con lo script} (ditemi se ho pensato bene).
PHP:
<?php
//recupero codice
$id = $_POST['codcliente'];
$id2= $_POST['prodotto'];
$id3= $_POST['industry'];
if(!empty($id)){
$query= "SELECT * FROM ch WHERE id LIKE ".$id;
}
else{
$query= "SELECT * FROM ch WHERE prodotto LIKE '$id2%' ";
}
if(empty($id) && empty($id2)){
$query= "SELECT * FROM ch WHERE Industry LIKE '%$id3%' ";
}
if (empty($id) && empty ($id2) && empty($id3)){
die("Selezionare un criterio di ricerca") ;
}
//connessione al DB
$dbc = mysql_connect('localhost', 'root','root','CH_db')
or die('Errore di connessione al db');
$db = mysql_select_db('CH_db');
//query al db
$result=mysql_query($query);
if(!empty($result)){
$array= mysql_fetch_row ($result);
$numfield=mysql_num_fields($result);
echo "<table border=1><tr>";
echo "<th><b>Azienda</b></th>";
echo "<th><b>codice cliente</b></th>";
echo "<th><b>prodotto</b></th>";
echo "<th><b>scad contratto</b></th>";
echo "<th><b>referente</b></th>";
echo "<th><b>num referente</b></th>";
echo "<th><b>commerciale</b></th>";
echo "<th><b>limitazioni lib</b></th>";
echo "<th><b>note limitazionib></th>";
echo "<th><b>scad. liberatoria</b></th>";
echo "<th><b>area</b></th>";
echo "<th><b>provincia</b></th>";
echo "<th><b>industry</b></th>";
echo "</tr>";
foreach ($array as $campo) {
echo "<td>$campo</td>";
}
echo "</tr></table>";
}else{
echo "Issues trying to fetch results. Check the error-->" . mysql_error();
}
?>