Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][MySQL] Jak pobrać imie użytkownika
Kacper10
post
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 13.01.2013

Ostrzeżenie: (0%)
-----


Dzień dobry, mam następujący problem. Otóż mam taką strukturę tabeli:
  1. CREATE TABLE IF NOT EXISTS `tablica` (
  2. `id` int(10) NOT NULL,
  3. `uid` int(10) NOT NULL,
  4. `status` varchar(255) NOT NULL,
  5. PRIMARY KEY (`id`)
  6. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  7.  
  8. CREATE TABLE IF NOT EXISTS `users` (
  9. `user_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  10. `user_name` varchar(255) NOT NULL,
  11. `user_password` varchar(250) NOT NULL,
  12. `user_email` varchar(255) NOT NULL,
  13. `user_fname` varchar(255) NOT NULL DEFAULT '',
  14. `user_lname` varchar(255) NOT NULL DEFAULT '',
  15. `user_admin` int(11) NOT NULL,
  16. `user_regdate` int(11) NOT NULL,
  17. `user_from` varchar(255) NOT NULL,
  18. `user_website` varchar(255) NOT NULL,
  19. `user_gg` int(11) NOT NULL,
  20. `user_jabber` varchar(255) NOT NULL,
  21. `user_birth` date NOT NULL,
  22. `user_plec` int(11) NOT NULL,
  23. PRIMARY KEY (`user_id`)
  24. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

Oto problem:
Gdy piszę wpis, to chcę, żeby z ID autora wpisu pobierać imię i nazwisko, które podał przy rejestracji. Piszę, ponieważ nic nie znalazłem w Google.
Pozdrawiam.
Go to the top of the page
+Quote Post
b4rt3kk
post
Post #2





Grupa: Zarejestrowani
Postów: 1 933
Pomógł: 460
Dołączył: 2.04.2010
Skąd: Lublin

Ostrzeżenie: (0%)
-----


  1. SELECT * FROM tablica INNER JOIN users ON tablica.uid = users.id


--------------------
Jeśli pomogłem, kliknij proszę 'pomógł'. Dzięki.
Go to the top of the page
+Quote Post
Kacper10
post
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 13.01.2013

Ostrzeżenie: (0%)
-----


Tylko mam mały problem - gdzie to wstawić?
  1. <div class="tab" id="tablica">
  2. <h2>Tablica</h2>
  3. <p><?php // tutaj
  4. $query = mysql_query('select * from wall order by id desc limit 0,5');
  5. $idq = mysql_query('SELECT * FROM wall INNER JOIN users ON wall.uid = users.id');
  6. while($rekord = mysql_fetch_array($query))
  7. {
  8. $naz .= '
  9. <tr>
  10. <td><a href="profile.php?id='.$rekord[1].'">Imię nazwisko</a> (Link: shout.php?id='.$rekord[0].') </td>
  11. </tr>
  12. <tr>
  13. <td>'.$rekord[2].'</td>
  14. </tr>
  15. <tr>
  16. <td>'.$rekord[3].' <button class="like">Vote!</button></td>
  17. </tr>
  18. ';
  19. }
  20. echo '<form method="post" action="add.php">
  21. <input type="text" name="text" size="70" value="'.$_POST['text'].'" /> <input type="submit" class="like" value="wyslij" />
  22. </form>
  23. <hr />';
  24. echo '<table>'.$naz.'</table>';?>
  25. </p>
  26. </div>

Pozdrawiam.
PS:No i zapomniałem nowa struktura to(kolejno): 0=id, 1=uid, 2=status, 3=data.

Ten post edytował Kacper10 14.01.2013, 20:15:57
Go to the top of the page
+Quote Post
b4rt3kk
post
Post #4





Grupa: Zarejestrowani
Postów: 1 933
Pomógł: 460
Dołączył: 2.04.2010
Skąd: Lublin

Ostrzeżenie: (0%)
-----


Tutaj:

  1. while($rekord = mysql_fetch_array($idq))


--------------------
Jeśli pomogłem, kliknij proszę 'pomógł'. Dzięki.
Go to the top of the page
+Quote Post
emillo91
post
Post #5





Grupa: Zarejestrowani
Postów: 129
Pomógł: 13
Dołączył: 29.03.2012

Ostrzeżenie: (0%)
-----


Jeżeli twój skrypt logowania opiera się na sesjach to możesz zapisać login w sesji i przypisać zmienną $_SESSION['login'] do zmiennej $login i później wywołać login w zapytaniu mysql czyli:


$_SESSION['login'] = $login;

SELECT imie, nazwisko FROM tabela where login="$login"

smile.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 03:09