se potessi/sapessi usare bene php e mysql userei le sessioni ma l'idea mi spaventa....senza nessuno che mi dia una mano la vedo dura e js mi sembrava una scorciatoia...![]()
[nella pagina del carrello, dove sostanzialmente lo script legge il cookie e stampa la tabella avrei voluto recuperare anche altri dati dei prodotti (collegandomi al db) ma non so come integrare php e document.write.
così facendo potrei inserire nel cookie $id, $prezzo, $quantità e recuperare i dati dal db tramite una query.
ma come posso intercalare una query in:
carrello.htm
ti prego dammi una mano..codice:<script language="javascript"> function cancella() { document.cookie = "Lampade=0"; location.href="carrello.htm"; } function deleteart(nomearticolo) { var deletearticle=0; var sostflag=0; var subpuntatore=0; var string=document.cookie; var puntatore=string.lastIndexOf("Lampade=#"); var lung=string.indexOf("##"); var newstring="Lampade=#"; while (puntatore<=lung) { deletearticle=0; if (string.charAt(puntatore) == "@") { puntatore++; subpuntatore=puntatore; while (string.charAt(puntatore) != "@") puntatore++; if (string.substring(subpuntatore, puntatore) == nomearticolo) deletearticle=1; if (deletearticle==0) newstring+="@"+string.substring(subpuntatore, puntatore); puntatore++; subpuntatore=puntatore; while (string.charAt(puntatore) != "@") puntatore++; if (deletearticle==0) newstring+="@"+string.substring(subpuntatore, puntatore); puntatore++; subpuntatore=puntatore; while ((string.charAt(puntatore) != "@") && (string.charAt(puntatore) != "#"))puntatore++; if (deletearticle==0) newstring+="@"+string.substring(subpuntatore, puntatore); puntatore--; } puntatore++; } newstring+="##"; puntatore=newstring.lastIndexOf("@"); if (puntatore != -1) document.cookie=newstring; else document.cookie = "Lampade=0"; location.href="carrello.htm"; } function chiudi() { close(); } function punteggiatura(num) { retval =""+num; if (retval < 100) { retval="0,"+retval; while (retval.length < 10){ retval =" "+retval } } if ((retval <= 99999) && (retval >= 100)) { temp1 = retval.substring(0,retval.length-2); temp2 = retval.substring(retval.length-2,retval.length+1); retval =temp1+","+temp2; while (retval.length < 10){ retval =" "+retval } } if(retval >= 100000) { temp1 = retval.substring(0,retval.length-5); temp2 = retval.substring(retval.length-5,retval.length-2); temp3 = retval.substring(retval.length-2,retval.length+1); retval=temp1+"."+temp2+","+temp3; while (retval.length < 10){ retval =" "+retval } } return retval; } document.write('<div align="center"> <center>'); document.write(" "); var quant=0; var prezzo=0; var totale=0; var string=document.cookie; var puntatore=string.lastIndexOf("Lampade=#"); var lung=string.indexOf("##"); if (puntatore == -1) document.write(' Il carrello è vuoto'); else { document.write('<table width="600" border="0" cellpadding="5" cellspacing="0">'); document.write('<tr bgcolor="#eeeeee"><td><font class="subtitlib">Titolo</font></td>'); document.write('<td align="right"><font class="subtitlib">Prezzo</font></td>'); document.write('<td align="right"><font class="subtitlib">Quantità</font></td>'); document.write('<td align="right"><font class="subtitlib">Totale</font></td>'); document.write('<td align="right"></td></tr><tr></tr>'); while (puntatore<=lung) { if (string.charAt(puntatore) == "@") { document.write('<tr bgcolor="#CEE7FF">'); puntatore++; subpuntatore=puntatore; while (string.charAt(puntatore) != "@") puntatore++; nomearticolo=string.substring(subpuntatore, puntatore); document.write('<td align="left"><font class="txtaut"> '+string.substring(subpuntatore, puntatore)+'</font></td>'); puntatore++; subpuntatore=puntatore; while (string.charAt(puntatore) != "@") puntatore++; prezzo=parseFloat(string.substring(subpuntatore, puntatore)); document.write('<td align="right"><font class="txtaut">€'+punteggiatura(parseInt(prezzo*100))+'</font></td>'); puntatore++; subpuntatore=puntatore; while ((string.charAt(puntatore) != "@") && (string.charAt(puntatore) != "#")) puntatore++; quant=parseInt(string.substring(subpuntatore, puntatore)); document.write('<td align="right"><font class="txtaut">'+quant+'</font></td>'); totale+=parseInt(prezzo*quant*100); document.write('<td align="right"><font class="txtaut">€'+punteggiatura(parseInt(prezzo*quant*100))+'</font></td>'); document.write('<td align="right"><font class="txtaut">[img]del.gif[/img]</font></td>'); puntatore--; document.write('</tr>'); } puntatore++; } document.write('<tr></tr><tr bgcolor="#CEE7FF">'); document.write('<td colspan="3" align="right"></td>'); document.write('<td align="right"><font class="subtitlib">Totale: €'+punteggiatura(totale)+'</font></td><td></td>'); document.write('</tr> </table> </center> </div>'); document.write('<div align="center"> [img]ordina.gif[/img][img]svuota.gif[/img]</div>'); } </script>

Rispondi quotando