Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL]Pobieranie wszytskich pustych rekordów
diamondking
post 16.01.2015, 14:03:45
Post #1





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Witam - jestem bardzo początkujący wink.gif

Mam w bazie danych tabelę users obecnie składa się z pól:

Jak mam pobrać wszystkie puste pola z tej tabeli i je zliczyć?



Go to the top of the page
+Quote Post
Pyton_000
post 16.01.2015, 14:06:38
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


.... jakich pól ... i co oznacza puste: czy '' czy NULL

WHERE pole IS NULL OR pole = ''
Go to the top of the page
+Quote Post
diamondking
post 16.01.2015, 14:12:55
Post #3





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Mam tabelę users w niej pola:

1. id
2. user_name
3. user_email
4. website
5. wiek
6. plec (z czasem będzie więcej)

Przy rejestracji uzupełnione zostanie tylko id, unser_name, user_email.

Teraz bym chciał pobrać wszystkie pola, które nie są uzupełnione i je zliczyć.

świeżo po rejestracji bedą trzy (webiste, wiek, plec)

ale później może je uzupełnić wiec będą np 2.



  1. SELECT COUNT(*) FROM users WHERE id='$userid';


Tak może być ?
Jak dodać warunek by pobrało tylko puste pola?
Go to the top of the page
+Quote Post
Pyton_000
post 16.01.2015, 14:15:08
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


To jeszcze powiedz do czego Ci taki manewr?
Go to the top of the page
+Quote Post
diamondking
post 16.01.2015, 14:16:32
Post #5





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Chciałbym na podstawie tego później wyświetlić ile procent profilu jest uzupełnione
Go to the top of the page
+Quote Post
Pyton_000
post 16.01.2015, 14:21:35
Post #6





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Ehh...

Na szybko:
  1. <?php
  2.  
  3. $sql= "SELECT * FROM users WHERE id = 2";
  4. // Pobieranie danych
  5. // $results = ....
  6.  
  7. $allFields = count($result)-1;
  8. $filledFields = count(array_filter($results))-1;
  9.  
  10. $filledPercent = $filledFields / $allFields *100;
  11.  


Ten post edytował Pyton_000 16.01.2015, 14:22:05
Go to the top of the page
+Quote Post
diamondking
post 16.01.2015, 14:30:19
Post #7





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Dzięki wielkie ale co mam wstawic w miejsce

  1. // Pobieranie danych
  2. // $results = ....


czy to juz gotowe jest ;D ?
Go to the top of the page
+Quote Post
daniel1302
post 16.01.2015, 15:21:41
Post #8





Grupa: Zarejestrowani
Postów: 602
Pomógł: 30
Dołączył: 1.08.2007
Skąd: Nowy Sącz

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


Zależy czego używasz do komunikacji z bazą bo jeśli jest to PDO to musisz wstawić coś typu
  1. $q = $pdo -> prepare($sql); $q -> execute(); $result = $q -> fetch();


albo jeśli czyste mysql, w co wątpię to:
  1. $q = mysql_query($sql); $result = mysql_fetch_assoc($q);

A jeśli coś innego, to zobacz do dokumentacji biblioteki.
Go to the top of the page
+Quote Post
diamondking
post 16.01.2015, 15:22:51
Post #9





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


  1. //procent profilu
  2. function procent_profil(){
  3.  
  4. $zapytanie = "SELECT * FROM `users` WHERE `user_id` = 1";
  5. $result = mysql_query($zapytanie);
  6.  
  7. $allFields = count($result)-1;
  8. $filledFields = count(array_filter($results))-1;
  9.  
  10. $filledPercent = $filledFields / $allFields *100;
  11.  
  12. echo $filledPercent;
  13.  
  14. }


BŁĄD:

  1. Warning: array_filter() expects parameter 1 to be array, null given in /home/u416505061/public_html/config.php on line 92 Warning: Division by zero in /home/u416505061/public_html/config.php on line 94 0
Go to the top of the page
+Quote Post
Pyton_000
post 16.01.2015, 15:55:44
Post #10





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


to teraz popatrz jak Ty pobierasz rekordy a jak kolega wyżej...
Go to the top of the page
+Quote Post
diamondking
post 16.01.2015, 16:57:16
Post #11





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Czy musicie mi to tak utrudniać smile.gif
UCZE SIĘ smile.gif
Czy ktoś mógłby napisać działający kod nerdsmiley.png ?
Ja próbuję i nie umiem :/

  1. //procent profilu2
  2. function procent_profil2(){
  3.  
  4. $sql= "SELECT * FROM users WHERE user_id = 1";
  5. $q = mysql_query($sql);
  6. $result = mysql_fetch_assoc($q);
  7.  
  8. $allFields = count($result)-1;
  9. $filledFields = count(array_filter($results))-1;
  10.  
  11. $filledPercent = $filledFields / $allFields *100;
  12.  
  13. echo $filledPercent;
  14.  
  15. }


nadal błąd:

Warning: array_filter() expects parameter 1 to be array, null given in /home/u416505061/public_html/config.php on line 127 -11.111111111111
Go to the top of the page
+Quote Post
SpiritCode
post 16.01.2015, 17:03:30
Post #12





Grupa: Zarejestrowani
Postów: 167
Pomógł: 35
Dołączył: 29.12.2014
Skąd: Otwock

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


Linia 9.
Napisałeś zmienną $results a w linii 6. deklarujesz $result
Go to the top of the page
+Quote Post
diamondking
post 16.01.2015, 17:11:39
Post #13





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Dzięki wielkie wszystkim !
Tylko jedna literka a tyle zamieszania !

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 Wersja Lo-Fi Aktualny czas: 26.04.2024 - 15:29