- Home
- Categorie
- Coding e Sistemistica
- PHP
- [PHP]problema visualizzazione immagini
-
[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">";
?>
-
Tu vuoi memorizzare la variabile $id_cartella nel database? Se sì, facci vedere la struttura della tabella del database dove vuoi che venga memorizzato $id_cartella
-
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 tabellamessaggi
CREATE TABLE
messaggi
(
id_user
int(10) NOT NULL auto_increment,
id_cartella
tinyint(1) default NULL,
username
varchar(65) NOT NULL default '',
password
varchar(65) NOT NULL default '',
user
varchar(20) NOT NULL default '',
gender
varchar(10) NOT NULL default '',
date_of_birth
date NOT NULL default '0000-00-00',
country
varchar(30) NOT NULL default '',
test_arousal_photo1
tinyint(3) default NULL,
test_valence_photo1
tinyint(3) default NULL,
test_arousal_photo2
tinyint(3) default NULL,
test_valence_photo2
tinyint(3) default NULL,
test_arousal_photo3
tinyint(3) default NULL,
test_valence_photo3
tinyint(3) default NULL,
test_arousal_photo4
tinyint(3) default NULL,
test_valence_photo4
tinyint(3) default NULL,
test_arousal_photo5
tinyint(3) default NULL,
test_valence_photo5
tinyint(3) default NULL,
test_arousal_photo6
tinyint(3) default NULL,
test_valence_photo6
tinyint(3) default NULL,
test_arousal_photo7
tinyint(3) default NULL,
test_valence_photo7
tinyint(3) default NULL,
test_arousal_photo8
tinyint(3) default NULL,
test_valence_photo8
tinyint(3) default NULL,
test_arousal_photo9
tinyint(3) default NULL,
test_valence_photo9
tinyint(3) default NULL,
test_arousal_photo10
tinyint(3) default NULL,
test_valence_photo10
tinyint(3) default NULL,
test_arousal_photo11
tinyint(3) default NULL,
test_valence_photo11
tinyint(3) default NULL,
test_arousal_photo12
tinyint(3) default NULL,
test_valence_photo12
tinyint(3) default NULL,
test_arousal_photo13
tinyint(3) default NULL,
test_valence_photo13
tinyint(3) default NULL,
test_arousal_photo14
tinyint(3) default NULL,
test_valence_photo14
tinyint(3) default NULL,
test_arousal_photo15
tinyint(3) default NULL,
test_valence_photo15
tinyint(3) default NULL,
test_arousal_photo16
tinyint(3) default NULL,
test_valence_photo16
tinyint(3) default NULL,
test_arousal_photo17
tinyint(3) default NULL,
test_valence_photo17
tinyint(3) default NULL,
test_arousal_photo18
tinyint(3) default NULL,
test_valence_photo18
tinyint(3) default NULL,
test_arousal_photo19
tinyint(3) default NULL,
test_valence_photo19
tinyint(3) default NULL,
test_arousal_photo20
tinyint(3) default NULL,
test_valence_photo20
tinyint(3) default NULL,
test_arousal_photo21
tinyint(3) default NULL,
test_valence_photo21
tinyint(3) default NULL,
test_arousal_photo22
tinyint(3) default NULL,
test_valence_photo22
tinyint(3) default NULL,
test_arousal_photo23
tinyint(3) default NULL,
test_valence_photo23
tinyint(3) default NULL,
test_arousal_photo24
tinyint(3) default NULL,
test_valence_photo24
tinyint(3) default NULL,
test_arousal_photo25
tinyint(3) default NULL,
test_valence_photo25
tinyint(3) default NULL,
test_arousal_photo26
tinyint(3) default NULL,
test_valence_photo26
tinyint(3) default NULL,
test_arousal_photo27
tinyint(3) default NULL,
test_valence_photo27
tinyint(3) default NULL,
test_arousal_photo28
tinyint(3) default NULL,
test_valence_photo28
tinyint(3) default NULL,
test_arousal_photo29
tinyint(3) default NULL,
test_valence_photo29
tinyint(3) default NULL,
test_arousal_photo30
tinyint(3) default NULL,
test_valence_photo30
tinyint(3) default NULL,
test_arousal_photo31
tinyint(3) default NULL,
test_valence_photo31
tinyint(3) default NULL,
test_arousal_ foto32
tinyint(3) default NULL,
test_valence_photo32
tinyint(3) default NULL,
test_arousal_ foto33
tinyint(3) default NULL,
test_valence_photo33
tinyint(3) default NULL,
test_arousal_ foto34
tinyint(3) default NULL,
test_valence_photo34
tinyint(3) default NULL,
test_arousal_ foto35
tinyint(3) default NULL,
test_valence_photo35
tinyint(3) default NULL,
test_arousal_ foto36
tinyint(3) default NULL,
test_valence_photo36
tinyint(3) default NULL,
test_arousal_ foto37
tinyint(3) default NULL,
test_valence_photo37
tinyint(3) default NULL,
test_arousal_ foto38
tinyint(3) default NULL,
test_valence_photo38
tinyint(3) default NULL,
test_arousal_ foto39
tinyint(3) default NULL,
test_valence_photo39
tinyint(3) default NULL,
test_arousal_ foto40
tinyint(3) default NULL,
test_valence_photo40
tinyint(3) default NULL,
test_arousal_ foto41
tinyint(3) default NULL,
test_valence_photo41
tinyint(3) default NULL,
test_arousal_ foto42
tinyint(3) default NULL,
test_valence_photo42
tinyint(3) default NULL,
test_arousal_ foto43
tinyint(3) default NULL,
test_valence_photo43
tinyint(3) default NULL,
test_arousal_ foto44
tinyint(3) default NULL,
test_valence_photo44
tinyint(3) default NULL,
test_arousal_ foto45
tinyint(3) default NULL,
test_valence_photo45
tinyint(3) default NULL,
test_arousal_ foto46
tinyint(3) default NULL,
test_valence_photo46
tinyint(3) default NULL,
test_arousal_ foto47
tinyint(3) default NULL,
test_valence_photo47
tinyint(3) default NULL,
test_arousal_ foto48
tinyint(3) default NULL,
test_valence_photo48
tinyint(3) default NULL,
test_arousal_ foto49
tinyint(3) default NULL,
test_valence_photo49
tinyint(3) default NULL,
test_arousal_ foto50
tinyint(3) default NULL,
test_valence_photo50
tinyint(3) default NULL,
date
datetime 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
messaggi
INSERT INTO
messaggi
VALUES (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 INTOmessaggi
VALUES (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');
-
Ok ora fammi sapere che cosa vuoi inserire insieme a $id_cartella e dove inserire (in che campi)
-
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
-
ho questa variabile:
$id_cartella = substr($id_user, -1, 1);
l'echo di $id_cartella = un numero,nel db ho creato un campo id_cartella
che comando gli do in php per farla passare nel db?
grazie
-
Sì questo l'ho capito, ma dato che la tabella messaggi c'hai quasi 100 campi, (test... ecc...) vuoi inserire una riga solo con $id_cartella o inserire nella stessa riga più cose?
-
ho già inserito una riga, la seconda, che si chiama id_cartelle
-
Sì, ma nella riga che inserisci che campi vai a riempire? Solo $id_cartella?
-
si un solo campo contenente il valore id_cartella
-
Allora eccoti il codice:
[php]<?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);
?>[/php]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