Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [sql] Zle wybiera rekordy
Bojakki
post
Post #1





Grupa: Zarejestrowani
Postów: 379
Pomógł: 0
Dołączył: 18.08.2004

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


Mam najprostsze z mozliwych zapytan:

$query = mysql_query("SELECT * FROM image WHERE genre = $g") or die(mysql_error());

kolumna 'genre' moze miec tylko 2 wartosci: 1 lub 0. Gdy zmienna $g wynosi 1 to wybiera dobre rekordy z bazy tzn. te, ktore w kolumnie 'genre' mam 1. Ale gdy zmienna $g ma wartosc 0 to wybiera wszytskie rekordy, tzn i te co maja wartosc 0 i te co maja wartosc 1. Jak dla mnie jest to sytuacja paranormalna. Wie moze ktos czym to mzoe byc spowodowane?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Bojakki
post
Post #2





Grupa: Zarejestrowani
Postów: 379
Pomógł: 0
Dołączył: 18.08.2004

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


Wyzej z istotniejszych rzeczy jest:

  1. <?php
  2. $idc = intval($_REQUEST['id']);
  3. if($_REQUEST['idr']!='') $idr = intval($_REQUEST['idr']); else $idr = $_REQUEST['idr'];
  4. if($_REQUEST['idg']!='') $idg = intval($_REQUEST['idg']); else $idg = $_REQUEST['idg'];
  5. if($_REQUEST['ids']!='') $ids = intval($_REQUEST['ids']); else $ids = $_REQUEST['ids'];
  6.  
  7. $query = mysql_query("SELECT bb_city.name, bb_city.status, bb_city.governor, bb_city.space, bb_ci
    ty.population, bb_city.density, bb_city.unemployment, bb_city.board, bb_district.
    id, bb_district.name, bb_province.id, bb_province.name
  8. FROM bb_city, bb_district, bb_province WHERE bb_city.id = $idc AND bb_city.distr
    ict = bb_district.id AND bb_district.province = bb_province.id"
    ) or die(mysql_error());
  9. $bb_cit=mysql_fetch_row($query);
  10.  
  11. $cityid = $idc;
  12. $city = htmlspecialchars(stripslashes($bb_cit[0]));
  13. $districtid = $bb_cit[8];
  14. $district = htmlspecialchars(stripslashes($bb_cit[9]));
  15. $provinceid = $bb_cit[10];
  16. $province = htmlspecialchars(stripslashes($bb_cit[11]));
  17.  
  18. $status = $bb_cit[1];
  19. $governor = htmlspecialchars(stripslashes($bb_cit[2]));
  20. $space = number_format($bb_cit[3], 0, '', ' ');
  21. $population = number_format($bb_cit[4], 0, '', ' ');
  22. $density = number_format($bb_cit[5], 0, '', ' ');
  23. $uneployment = $bb_cit[6];
  24. $board = htmlspecialchars(stripslashes($bb_cit[7]));
  25.  
  26. echo '<b><p style="margin-left: 8; margin-bottom: 2"><a class="blue" href="province.php?id='.$provinceid.'">woj. ';
  27. echo $province;
  28. echo '</a>';
  29.  
  30. echo ' <img border="0" src="layout/arrow.gif" width="13" height="15" align="absbottom"> ';
  31. echo '<a class="blue" href="district.php?id='.$districtid.'">';
  32. echo 'pow. '.$district;
  33. echo '</a>';
  34.  
  35. echo ' <img border="0" src="layout/arrow.gif" width="13" height="15" align="absbottom"> ';
  36. echo '<a class="blue" href="city.php?id='.$cityid.'">'.$city.'</a></b>';
  37.  
  38.  
  39. if($idc > '0' AND ($idr =='' AND $idg =='' AND $ids =='')){
  40. $query = mysql_query("SELECT * FROM image WHERE idc = $idc ORDER BY year DESC, month DESC, day DE
    SC, id DESC"
    ) or die(mysql_error());
  41. }
  42.  
  43. if($idr != ''){
  44. $query = mysql_query("SELECT * FROM image WHERE region = $idr AND idc = $idc ORDER BY year DESC, 
    month DESC, day DESC, id DESC"
    ) or die(mysql_error());
  45. }
  46.  
  47. if($idg != ''){
  48. $query = mysql_query("SELECT * FROM image WHERE genre like '".$idg."' AND idc = $idc ORDER BY year DESC, month DESC, day DESC, id DESC") or die(mysql_error());
  49. }
  50.  
  51. if($ids != ''){
  52. $query = mysql_query("SELECT * FROM image WHERE skyline = $ids AND idc = $idc ORDER BY year DESC,
     month DESC, day DESC, id DESC"
    ) or die(mysql_error());
  53. }
  54. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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: 26.12.2025 - 07:22