Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Wyświetlanie wyników w tabeli.
DDK15
post
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 1
Dołączył: 16.04.2011

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


Witam, mam problem gdyż stworzyłem prosty skrypt do pobierania danych z mysql i wyświetlania ich w tabeli. Wszystko działa pięknie, jeżeli coś w tej tabeli jest, ale jak nie ma to pojawiają się błędy. Proszę o pomoc smile.gif

Kod
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 6 in reward_history.php on line 12

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 7 in reward_history.php on line 13

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 8 in reward_history.php on line 14


  1. <?php
  2. $usernameb = $_SESSION['username'];
  3. $query1 = "SELECT username FROM history ORDER BY id";
  4. $result1 = mysql_query($query1) or die(mysql_error());
  5. $query2 = "SELECT reward FROM history WHERE username='$usernameb' ORDER BY id";
  6. $result2 = mysql_query($query2) or die(mysql_error());
  7. $query3 = "SELECT date FROM history WHERE username='$usernameb' ORDER BY date DESC";
  8. $result3 = mysql_query($query3) or die(mysql_error());
  9. $query4 = "SELECT status FROM history WHERE username='$usernameb' ORDER BY id";
  10. $result4 = mysql_query($query4) or die(mysql_error());
  11. $username = mysql_result($result1,$usernameb);
  12. $reward = mysql_result($result2,"reward");
  13. $date = mysql_result($result3,"date");
  14. $status = mysql_result($result4,"status");
  15. $num=mysql_num_rows($result3);
  16. ?>
  17.  
  18. <table border="1" cellpadding="10">
  19. <tr><td><strong>Username</strong></td><td><strong>Reward</strong></td><td><strong>Date</strong></td><td><strong>Status</strong></td></tr>
  20. <?php
  21. $i=0;
  22. if($num>0){
  23. while ($i < $num) {
  24. $reward=mysql_result($result2,$i,"reward");
  25. $date=mysql_result($result3,$i,"date");
  26. $status=mysql_result($result4,$i,"status");
  27. $i++;
  28.  
  29. echo"<tr><td>".$usernameb."</td><td>".$reward."</td><td>".$date."</td><td>".$status."</td></tr>";
  30. }
  31. }
  32. else { echo "No elements to display"; }
  33. ?>
  34. </table>


Ten post edytował DDK15 18.06.2012, 09:56:02
Go to the top of the page
+Quote Post

Posty w temacie
- DDK15   [MySQL][PHP] Wyświetlanie wyników w tabeli.   18.06.2012, 09:53:34
- - emkej   Czemu aż 4 zapytania do jednej tablicy? [PHP] pob...   18.06.2012, 13:42:12
- - DDK15   Dzięki   18.06.2012, 14:41:26


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 - 05:02