[PHP]problema visualizzazione immagini
-
le immagini vengono visualizzate in blocchi da 50 per ogni utente in base all'ultimo id_user user registrato.
cosi' l'utente 1 avra' il blocco 1, il 2 il blocco 2 , il 10 il blocco 0, il 13 il 3 e cosi' via.
Il problema è che se piu' utenti accedono contemporaneamente, registrando solo alla fine il proprio id_user che è autoincrement nel db, faranno tutti riferimento all'id_user precedente.
esempio:
l'ultimo id_user =2 nel db
4 utenti accedono contemporaneamente,
tutti gli utenti visualizzaranno il blocco 2,
alla fine pero' ci saranno registrati gli utenti 3,4,5,6 che hanno visualizzato il blocco 2.
vorrei invece che ogni utente visualizzasse il blocco relativo al suo reale numero id_user finale, anche se lo avra' solo alla fine della sessione. -
mi rendo conto che il problema è un po ' complesso da spiegare, questo è in geerale il sito giorgiodp.netsons.org
dunque, ho in parte risolto il problema.
Ora dovrei solo registrare nel db l' "echo" di $id_cartella; mettiamo 6, in modo da ricordarmi quale è il blocco di immagini che ha visualizzato.<?php
$connessione=
$selezione_db=
$query = mysql_query("SELECT id_user, date FROM messaggi ORDER BY date DESC limit 1");
while($riga = mysql_fetch_assoc($query))
{
$id_user = $riga['id_user'];
}
$id_cartella = substr($id_user, -1, 1);
$cartella = "fotos/".$id_cartella ;
$image_src ="fotos/" . $id_cartella . "fotos/"."1" . ".jpg";
echo "<img src="$image_src">";
?> -
-
la normalizzazione l'ho totalmente ignorata,lo so..
-- phpMyAdmin SQL Dump
-- version 2.6.1-- Host: localhost
-- Generato il: 31 Mag, 2008 at 06:04 PM
-- Versione MySQL: 4.1.9
-- Versione PHP: 4.3.10-- Database:
guest_book
--
-- Struttura della tabellamessaggiCREATE TABLE
messaggi(
id_userint(10) NOT NULL auto_increment,
id_cartellatinyint(1) default NULL,
usernamevarchar(65) NOT NULL default '',
passwordvarchar(65) NOT NULL default '',
uservarchar(20) NOT NULL default '',
gendervarchar(10) NOT NULL default '',
date_of_birthdate NOT NULL default '0000-00-00',
countryvarchar(30) NOT NULL default '',
test_arousal_photo1tinyint(3) default NULL,
test_valence_photo1tinyint(3) default NULL,
test_arousal_photo2tinyint(3) default NULL,
test_valence_photo2tinyint(3) default NULL,
test_arousal_photo3tinyint(3) default NULL,
test_valence_photo3tinyint(3) default NULL,
test_arousal_photo4tinyint(3) default NULL,
test_valence_photo4tinyint(3) default NULL,
test_arousal_photo5tinyint(3) default NULL,
test_valence_photo5tinyint(3) default NULL,
test_arousal_photo6tinyint(3) default NULL,
test_valence_photo6tinyint(3) default NULL,
test_arousal_photo7tinyint(3) default NULL,
test_valence_photo7tinyint(3) default NULL,
test_arousal_photo8tinyint(3) default NULL,
test_valence_photo8tinyint(3) default NULL,
test_arousal_photo9tinyint(3) default NULL,
test_valence_photo9tinyint(3) default NULL,
test_arousal_photo10tinyint(3) default NULL,
test_valence_photo10tinyint(3) default NULL,
test_arousal_photo11tinyint(3) default NULL,
test_valence_photo11tinyint(3) default NULL,
test_arousal_photo12tinyint(3) default NULL,
test_valence_photo12tinyint(3) default NULL,
test_arousal_photo13tinyint(3) default NULL,
test_valence_photo13tinyint(3) default NULL,
test_arousal_photo14tinyint(3) default NULL,
test_valence_photo14tinyint(3) default NULL,
test_arousal_photo15tinyint(3) default NULL,
test_valence_photo15tinyint(3) default NULL,
test_arousal_photo16tinyint(3) default NULL,
test_valence_photo16tinyint(3) default NULL,
test_arousal_photo17tinyint(3) default NULL,
test_valence_photo17tinyint(3) default NULL,
test_arousal_photo18tinyint(3) default NULL,
test_valence_photo18tinyint(3) default NULL,
test_arousal_photo19tinyint(3) default NULL,
test_valence_photo19tinyint(3) default NULL,
test_arousal_photo20tinyint(3) default NULL,
test_valence_photo20tinyint(3) default NULL,
test_arousal_photo21tinyint(3) default NULL,
test_valence_photo21tinyint(3) default NULL,
test_arousal_photo22tinyint(3) default NULL,
test_valence_photo22tinyint(3) default NULL,
test_arousal_photo23tinyint(3) default NULL,
test_valence_photo23tinyint(3) default NULL,
test_arousal_photo24tinyint(3) default NULL,
test_valence_photo24tinyint(3) default NULL,
test_arousal_photo25tinyint(3) default NULL,
test_valence_photo25tinyint(3) default NULL,
test_arousal_photo26tinyint(3) default NULL,
test_valence_photo26tinyint(3) default NULL,
test_arousal_photo27tinyint(3) default NULL,
test_valence_photo27tinyint(3) default NULL,
test_arousal_photo28tinyint(3) default NULL,
test_valence_photo28tinyint(3) default NULL,
test_arousal_photo29tinyint(3) default NULL,
test_valence_photo29tinyint(3) default NULL,
test_arousal_photo30tinyint(3) default NULL,
test_valence_photo30tinyint(3) default NULL,
test_arousal_photo31tinyint(3) default NULL,
test_valence_photo31tinyint(3) default NULL,
test_arousal_ foto32tinyint(3) default NULL,
test_valence_photo32tinyint(3) default NULL,
test_arousal_ foto33tinyint(3) default NULL,
test_valence_photo33tinyint(3) default NULL,
test_arousal_ foto34tinyint(3) default NULL,
test_valence_photo34tinyint(3) default NULL,
test_arousal_ foto35tinyint(3) default NULL,
test_valence_photo35tinyint(3) default NULL,
test_arousal_ foto36tinyint(3) default NULL,
test_valence_photo36tinyint(3) default NULL,
test_arousal_ foto37tinyint(3) default NULL,
test_valence_photo37tinyint(3) default NULL,
test_arousal_ foto38tinyint(3) default NULL,
test_valence_photo38tinyint(3) default NULL,
test_arousal_ foto39tinyint(3) default NULL,
test_valence_photo39tinyint(3) default NULL,
test_arousal_ foto40tinyint(3) default NULL,
test_valence_photo40tinyint(3) default NULL,
test_arousal_ foto41tinyint(3) default NULL,
test_valence_photo41tinyint(3) default NULL,
test_arousal_ foto42tinyint(3) default NULL,
test_valence_photo42tinyint(3) default NULL,
test_arousal_ foto43tinyint(3) default NULL,
test_valence_photo43tinyint(3) default NULL,
test_arousal_ foto44tinyint(3) default NULL,
test_valence_photo44tinyint(3) default NULL,
test_arousal_ foto45tinyint(3) default NULL,
test_valence_photo45tinyint(3) default NULL,
test_arousal_ foto46tinyint(3) default NULL,
test_valence_photo46tinyint(3) default NULL,
test_arousal_ foto47tinyint(3) default NULL,
test_valence_photo47tinyint(3) default NULL,
test_arousal_ foto48tinyint(3) default NULL,
test_valence_photo48tinyint(3) default NULL,
test_arousal_ foto49tinyint(3) default NULL,
test_valence_photo49tinyint(3) default NULL,
test_arousal_ foto50tinyint(3) default NULL,
test_valence_photo50tinyint(3) default NULL,
datedatetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id_user)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PACK_KEYS=0 AUTO_INCREMENT=878 ;-- Dump dei dati per la tabella
messaggiINSERT INTO
messaggiVALUES (1, 0, 'g', 'b2f5ff47436671b6e533d8dc3614845d', '0', '0', '0000-00-00', 'selected', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2008-05-31 04:51:10');
INSERT INTOmessaggiVALUES (872, 0, 'u', '7b774effe4a349c6dd82ad4f4f21d34c', 'researcher', 'female', '1952-09-24', 'LA', 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 2, -2, 0, -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2008-05-31 05:05:25'); -
-
grazie:
in questo passaggio
<?php
$connessione=mysql_connect("localhost", "
$selezione_db=mysql_select_db("guest_book", $connessione);
$query = mysql_query("SELECT id_user, date FROM messaggi ORDER BY date DESC limit 1");
while($riga = mysql_fetch_assoc($query))
{
$id_user = $riga['id_user'];
}
$id_cartella = substr($id_user, -1, 1);
$cartella = "fotos/".$id_cartella ;
$image_src ="fotos/" . $id_cartella . "fotos/"."1" . ".jpg";
echo "<img src="$image_src">";
?>vorrei inserire il valore
$id_cartella = substr($id_user, -1, 1);
$id_cartella = che sara' da 0 a 9
inserirlo nel campoid_cartella del tabase -
-
-
-
-
-
Allora eccoti il codice:
<?php // Dati di connessione al database $dbhost = "localhost"; // Host del database $dbuser = ""; // Username database (specificalo) $dbpass = ""; // Password database, se non c'è lascia vuoto $dbname = ""; // Nome del database (specificalo) $db = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname, $db); $query = mysql_query("SELECT id_user, date FROM messaggi ORDER BY date DESC limit 1", $db); while($riga = mysql_fetch_assoc($query)) { $id_user = $riga['id_user']; } $id_cartella = substr($id_user, -1, 1); $cartella = "fotos/".$id_cartella; $image_src ="fotos/" . $id_cartella . "fotos/"."1" . ".jpg"; echo "<img src=\"$image_src\">"; // Quello che vuoi inserire nel campo id_cartella $ins = ""; // Specificalo // Qui inserisce i dati nel database mysql_query("INSERT INTO messaggi (id_cartella) VALUES(\"".$ins."\")", $db); // Disconnessione dal database mysql_close($db); ?>Fammi sapere...


-
$id_cartella = substr($id_user, -1, 1);
$cartella = "fotos/".$id_cartella ;
$image_src ="fotos/" . $id_cartella . "fotos/"."50" . ".jpg";
echo "<img src="$image_src">";
$ins = "$id_cartella";
?>lo porto con la sessione alla pagina successiva:
<?php
session_start();
$_SESSION['id_cartella'] = $_INS ['id_cartella'];
?>alla terza inserisco:
<?php
session_start();
?><?php
$connessione=mysql_connect("localhost", "");
$selezione_db=mysql_select_db("guest_book", $connessione);
$id_cartella = $_SESSION['id_cartella'];
$user = $_SESSION['user'];
$gender = $_SESSION['gender'];
$year=$_SESSION['year'];
$month=$_SESSION['month'];
$day=$_SESSION['day']$query="INSERT INTO messaggi (id_user,id_cartella,user,gender,date_of_birth,country,test_arousal_photo1,test_valence_
pero' qui come la scrivo$id_cartella?
$query.=" VALUES ('$id_user','$user','$gender','$year-$month-$day','$country
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi
