Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Zmiana php 5 na php 7
szczalpi
post
Post #1





Grupa: Zarejestrowani
Postów: 336
Pomógł: 0
Dołączył: 25.10.2006

Ostrzeżenie: (10%)
X----


Witam
Zmieniłem php z 5 na 7. Niestety komendy przestały działać.
Nie wiem jak to ruszyć.
Proszę Was o pomoc




  1. $result = mysqli_query("SELECT FLOOR(RAND() * COUNT(*)) AS offset FROM k_copy where id");
  2. $offset_row = mysqli_fetch_object( $result );
  3. $offset = $offset_row->offset;
  4. $result = mysqli_query("SELECT * FROM k_copy where id LIMIT $offset, 5 " );
  5. $row = mysqli_fetch_array($result);
Go to the top of the page
+Quote Post
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Komendy przestały działać? Niby które?
Może to raczej wina składni zapytań - raczej nie chodziło Ci o warunek "WHERE id".
Go to the top of the page
+Quote Post
szczalpi
post
Post #3





Grupa: Zarejestrowani
Postów: 336
Pomógł: 0
Dołączył: 25.10.2006

Ostrzeżenie: (10%)
X----


Zadam inaczej pytanie.
Jak zmienić zapytanie, aby działało w php 7 ?
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Zapytanie jest niezależne od wersji PHP, bo dotyczy MySQL.
Jeśli w identycznej postaci działało w PHP5, to będzie działać w PHP7.
Go to the top of the page
+Quote Post
ohm
post
Post #5





Grupa: Zarejestrowani
Postów: 623
Pomógł: 144
Dołączył: 22.12.2010

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


A masz w ogóle mysqli w php7?
Go to the top of the page
+Quote Post
szczalpi
post
Post #6





Grupa: Zarejestrowani
Postów: 336
Pomógł: 0
Dołączył: 25.10.2006

Ostrzeżenie: (10%)
X----


Poniżej kod. W 5 działało bez problemu. 7 nie chce zaskoczyć.

  1. <?php
  2. $servername = "";
  3. $username = "";
  4. $password = "";
  5.  
  6. // Create connection
  7. $conn = mysqli_connect($servername, $username, $password);
  8.  
  9. // Check connection
  10. if (!$conn) {
  11. die("Connection failed: " . mysqli_connect_error());
  12. }
  13. echo "działa";
  14.  
  15. $result = mysqli_query("SELECT FLOOR(RAND() * COUNT(*)) AS offset FROM k_copy WHERE id");
  16. $offset_row = mysqli_fetch_object( $result );
  17. $offset = $offset_row->offset;
  18. $result = mysqli_query("SELECT * FROM k_copy WHERE id LIMIT $offset, 5 " );
  19. $row = mysqli_fetch_array($result);
  20. ?>
  21.  
  22. <h2 class="tytul">Pogoda <? echo $row['miasta']; ?></h2>
  23. <?php
  24. while ($row = mysqli_fetch_array($result))
  25. {
  26. ?>
  27. <div class="szukaj-tytul">
  28. <div class="szukaj-tytul-address">
  29. <h2 class="szukaj-tytul-name">
  30. <?php $str=''.$row['miasta'].'';?>
  31. <a href="<? echo $row['id'];?>-<? echo tytul_ogl($str);?>,pogoda.html" title="Pogoda <? echo $row['miasta']; ?>">
  32. Pogoda <? echo $row['miasta']; ?></a><br/>
  33. </h2>
  34. <div style="float:left;color:#797979" >
  35. ul. <? echo $row['ul']; ?></div><br/>
  36. <div style="float:left;color:#797979" >
  37. Gmina: <? echo $row['gmina']; ?></div><br/>
  38. <div style="float:left;color:#797979" >
  39. Powiat: <? echo $row['powiat']; ?><br/></div><br/>
  40. <div style="float:left;color:#797979" >
  41. Województwo: <? echo $row['wojewodztwo']; ?><br/></div><br/>
  42. <div style="float:left;color:#797979" >
  43. <div class="linki2" style="margin-top:5px;">
  44. | <a href="kod-pocztowy,<? echo $row[miasta];?>.html" title="Kod pocztowy <? echo ucfirst($row[miasta]);?>">kod pocztowy <?php echo ucfirst($row[miasta]);?></a>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. <?php
  50. }
  51. ?>
Go to the top of the page
+Quote Post
ohm
post
Post #7





Grupa: Zarejestrowani
Postów: 623
Pomógł: 144
Dołączył: 22.12.2010

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


Aha, no to trzeba cos zrobic zeby zaskoczylo.
Go to the top of the page
+Quote Post
szczalpi
post
Post #8





Grupa: Zarejestrowani
Postów: 336
Pomógł: 0
Dołączył: 25.10.2006

Ostrzeżenie: (10%)
X----


but how (IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
ohm
post
Post #9





Grupa: Zarejestrowani
Postów: 623
Pomógł: 144
Dołączył: 22.12.2010

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


Np analizując kod poprzez np włączenie jakiegoś error_reporting czy sprawdzenie logów na serwerze.
Go to the top of the page
+Quote Post
phpamator
post
Post #10





Grupa: Zarejestrowani
Postów: 328
Pomógł: 3
Dołączył: 10.07.2016
Skąd: UK-raine

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


To jest przykładowy kod czy działający ?
nie widzę tam żebyś się podłaczał do jakiejś konkretnej bazy .....

a skoro się nie podłączasz to skąd niby ma ci dane ciągnąć ?
..... AI ?
.... zgaduje gdzie leżą ?

tak tylko pytam ... (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
szczalpi
post
Post #11





Grupa: Zarejestrowani
Postów: 336
Pomógł: 0
Dołączył: 25.10.2006

Ostrzeżenie: (10%)
X----


Pomóżcie, nie wiem gdzie jest błąd. Tępy jestem (IMG:style_emoticons/default/sad.gif)
  1. <?php
  2.  
  3. $link = mysqli_connect("localhost", "szczypioerkr", "kuba","poszukaj");
  4. $result = mysqli_query($link,"SELECT FLOOR(RAND() * COUNT(*)) AS offset FROM k_copy WHERE id");
  5. $offset_row = mysqli_fetch_object( $result );
  6. $offset = $offset_row->offset;
  7. $result = mysqli_query("SELECT * FROM k_copy WHERE id LIMIT $offset, 5 " );
  8. $row = mysqli_fetch_array($result);
  9. ?>
  10.  
  11. <h2 class="tytul">Pouugodja <? echo $row['miasta']; ?></h2>


POMOCY (IMG:style_emoticons/default/exclamation.gif) !!

Ten post edytował szczalpi 30.12.2021, 13:01:42
Go to the top of the page
+Quote Post
Neutral
post
Post #12





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


WHERE `id` <tutaj dokończ>
Go to the top of the page
+Quote Post
szczalpi
post
Post #13





Grupa: Zarejestrowani
Postów: 336
Pomógł: 0
Dołączył: 25.10.2006

Ostrzeżenie: (10%)
X----


dodałem np: LIMIT 5 i dalej nie działa
Go to the top of the page
+Quote Post
Neutral
post
Post #14





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Cytat
where_condition is an expression that evaluates to true for each row to be selected. The statement selects all rows if there is no WHERE clause.


Gdzie jabłka nie są w wiklinowym koszyku.

WHERE apples NOT IN('box', 'container');
WHERE id=1;

MySQL

Ten post edytował Neutral 30.12.2021, 15:24:26
Go to the top of the page
+Quote Post
trueblue
post
Post #15





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Abstrahując od problemów Autora, samo "WHERE id" jest poprawnym warunkiem.
Go to the top of the page
+Quote Post
Neutral
post
Post #16





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Nie czytałem, ale może sprawdza to istnienie kolumny.
Go to the top of the page
+Quote Post
trueblue
post
Post #17





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Nie istnienie, ale czy wartość jest równa true/false.
Go to the top of the page
+Quote Post
Neutral
post
Post #18





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


OK dzięki, nie musiałem otwierać dokumentacji.(IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
trueblue
post
Post #19





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


No tak, była cytowana przez Ciebie wyżej.
Go to the top of the page
+Quote Post
ohm
post
Post #20





Grupa: Zarejestrowani
Postów: 623
Pomógł: 144
Dołączył: 22.12.2010

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


Cytat(szczalpi @ 30.12.2021, 13:25:42 ) *
Pomóżcie, nie wiem gdzie jest błąd. Tępy jestem (IMG:style_emoticons/default/sad.gif)


Bardziej bym rzekł że leniwy. Co zwraca zapytanie? Próbowałeś sprawdzić przez var_dump? Włączałeś error_reporting? Sprawdzałeś czy masz moduł mysqli w php7?
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 13:12