-
php&mysql
Daca va rog, se poate putin ajutor? Sunt incepator in php....
Mentionez ca i-mi adauga cu succes la username si friendname, dar update dintr-un tabel intr'altul (update friends, from registered_members) nu-mi mai face..cu ce am gresit?
-----------------------------------------------------------
$add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[username]' , '$_SESSION[username]') "); // add to your friends list
$add2 = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_SESSION[username]' , '$_GET[username]') "); // fix friend bug
$add3 = mysql_query( "UPDATE friends f SET f.imagelocation = ( SELECT rm.imagelocation FROM registered_members rm WHERE f.imagelocation = rm.imagelocation )");
-----------------------------------------------------------
Deci vreau sa-mi copie $imagelocation din tabelul 'friends' in tabelul 'registered_members'. Orice raspuns este bine venit. Multumesc!
-
as zice ca la sintaxa ...
incearca : UPDATE friends f SET f.imagelocation = ( SELECT rm.imagelocation FROM registered_members rm, friends f WHERE f.imagelocation = rm.imagelocation )
-
selectu: SELECT rm.imagelocation FROM registered_members rm WHERE f.imagelocation = rm.imagelocation foloseste f.imagelocation care f nu e specificat si trebuie. Eu pana la urma nu inteleg ce vrea sa faca a 3-a functie ... un export cu cele 2 tabele ar fi util ...
-
Acum citesc mai bine ce spui : vrei sa scrii din tabelul 'friends' in tabelul 'registered_members'.
Atunci trebuie sa faci update pe registered_members, nu pe friends ...
Explica mai bine legatura dintre cele 2 tabele + niste exemple fictive de date!
-
ce vreau eu sa fac....vreau sa fac cumva ca anumite randuri care poarta acelasi nume in ambele tabele sa le copii dintr-un tabel in altul..daca se poate..caci mi-am facut un profil..merge sa adaug prieteni, request, cand dau click pe imagine ma redirecteaza catre prieten dar imaginea care ar fi trebuit sa fie la prieten, de fapt este imaginea profilului meu
Acesta este request.php si merge..
-------
//query test
$sql = "SELECT * FROM friend_requests WHERE username = '$puser' LIMIT 8";
$result= mysql_query($sql) or trigger_error(E_USER_ERROR);
$array = array(); // Array ce va contine 'categorie' => nr_repetari
if (mysql_num_rows($result) == 0) { echo (" You have no new friend requests "); }
else {
while ($array = mysql_fetch_assoc($result)) {
$puser = $array['username'];
$puser2 = $array['by'];
echo ( "<a href='testmysql.php?friends=accept&username=$array[by]'>Accepta cererea</a>
|
<a href='prieteni.php?friends=delete&username=$array[by]'>Ignora cererea</a>
|
<a href='profil.php?username=$array[by]' target='blank'>Vizualizeaza profilu</a> <br>$array[by] vrea sa devina prietenul cu tine!</br><br></br> " ); //displays requests and shows accept delete links
}}
break;
case 'accept': //accept page
if ($_GET[username]) { //get username
{
$add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[username]' , '$_SESSION[username]') "); // add to your friends list
$add2 = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_SESSION[username]' , '$_GET[username]') "); // fix friend bug
$add3 = mysql_query( "UPDATE friends f SET f.imagelocation = ( SELECT rm.imagelocation FROM registered_members rm WHERE f.imagelocation = rm.imagelocation )");
$delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by` = '$_GET[username]'"); // deletes friend requestrequest
echo ( "$_GET[username] has been added as a friend and the request has been deleted" ); // echos the completion
}}
break; //ends delete page
-----
si acesta este view_friends.php
-----
$query = mysql_query("SELECT * FROM friends f INNER JOIN registered_members rm ON f.username = rm.username WHERE rm.username='$username' ORDER BY rm.username DESC LIMIT 8");
if (mysql_num_rows($query) == 0)
die("User not found!");
else
{
while ($row = mysql_fetch_array($query)){
$image = $row['image'];
$friendname = $row['friendname'];
echo "<a href='/website/view_friends.php?username=$friendname'><img src='$image' width='100' height='100' ></a>";
-----
Aici la view_friends.php nu-mi afiseaza imaginea prietenului, ci a mea. Multumesc anticipat.