goma smile Posted March 7, 2009 Report Share Posted March 7, 2009 Vai kāds lūdzu nepatiektu, ka izdarīt lai pārbauda vai tāds id eksistē....... Piemēram http://xxx.lv/jaunumi/1 <- existē un parāda vajadzīgo lapu Piemēram http://xxx.lv/jaunumi/19 <- neexistē līdz ar to parāda ka tāds id neeksistē Quote Link to comment Share on other sites More sharing options...
marcis Posted March 7, 2009 Report Share Posted March 7, 2009 if(ieraksts eksistē){ viss ok }else{ nav ok } Quote Link to comment Share on other sites More sharing options...
bubu Posted March 7, 2009 Report Share Posted March 7, 2009 Tad, kad dabū to skaitli kādā mainīgajā $id, tad arī pārbaudi attiecīgi kā tev tie dati glabājas. Piemēram, ja tas ir kādas tabulas atslēga, tad: SELECT COUNT(*) FROM tabula WHERE id = $id Ja atgriež 0, tad tāda id nav. Quote Link to comment Share on other sites More sharing options...
goma smile Posted March 7, 2009 Author Report Share Posted March 7, 2009 provēju bet nesanāk kautko drošvien nedaru kā vaig $poll_check = mysql_query("SELECT COUNT(*) FROM polls WHERE poll_id='$poll_id'"); IF ($_GET['id'] == $poll_check) { echo "ir"; } else { echo "nav"; } Quote Link to comment Share on other sites More sharing options...
bubu Posted March 7, 2009 Report Share Posted March 7, 2009 mysql_query atgriež kverija objektu, nevis rezultātu datus. Lai izvilktu datus no kverija rezultāta jālieto kāda no mysql_fetch_... funkcijām. Pats tikko tak taisīji topikus ar tādu funkciju savā kodā, piemēram: http://php.lv/f/index.php?showtopic=12948 Quote Link to comment Share on other sites More sharing options...
goma smile Posted March 7, 2009 Author Report Share Posted March 7, 2009 (edited) $poll_check = mysql_query("SELECT poll_id FROM polls "); while ($pid = mysql_fetch_assoc($poll_check)) { $kautkas = $pid['poll_id']; } IF ($_GET['id'] == $kautkas) { echo "ir"; }else { echo "nav"; } Ar šito parāda ka eksistē tikai pēdējā, a pārējos rāda ka nav Edited March 7, 2009 by goma smile Quote Link to comment Share on other sites More sharing options...
bubu Posted March 7, 2009 Report Share Posted March 7, 2009 Paklau, tev kļūdu rādīšana php ir atslēgta vai kā? Ieliec visu skriptu sākumā šo: error_reporting(E_ALL); ini_set("display_errors", 1); Citādi jau programmēt takš nevar, ja nerāda kļūdas. Tu kverijā selektē COUNT(*), taču no $pid velc ārā "poll_id" - tur tak nav tāda nosaukuma lauka. Lieto fetch_row un velc pirmo elementu ārā - būs vienkāršāk. Un while ciklu tev arī nevajag. Tev vajag tikai vienu fetch'u uztaisīt un viss. Quote Link to comment Share on other sites More sharing options...
p4F Posted March 8, 2009 Report Share Posted March 8, 2009 mysql_result Quote Link to comment Share on other sites More sharing options...
goma smile Posted March 8, 2009 Author Report Share Posted March 8, 2009 (edited) $poll_check = mysql_query("SELECT poll_id FROM polls"); $pid = mysql_fetch_row($poll_check); IF ($_GET['id'] == $pid) { echo "ir"; }else { echo "nav"; } 6itā ? ja tā tad nav :( Edited March 8, 2009 by goma smile Quote Link to comment Share on other sites More sharing options...
bubu Posted March 8, 2009 Report Share Posted March 8, 2009 Nē, ne tā. Apskaties dokumentācijā vai ar print_r, kas ir $pid, tb ko atgriež mysql_fetch_row. Quote Link to comment Share on other sites More sharing options...
goma smile Posted March 8, 2009 Author Report Share Posted March 8, 2009 (edited) $poll_check = mysql_query("SELECT poll_id FROM polls"); $pid = mysql_fetch_row($poll_check); print_r($pid); Array ( [0] => 2 ) PIe jebkura $_GET['id'] Edited March 8, 2009 by goma smile Quote Link to comment Share on other sites More sharing options...
rausis Posted March 8, 2009 Report Share Posted March 8, 2009 (edited) $poll_check = mysql_query("SELECT id FROM polls WHERE poll_id = ".intval($_GET['id'])); $pid = mysql_fetch_row($poll_check); print_r($pid); Edited March 8, 2009 by rausis Quote Link to comment Share on other sites More sharing options...
bubu Posted March 8, 2009 Report Share Posted March 8, 2009 goma smile: nu un tagad ir skaidrs, kāpēc if's neizpildās? Jo tu salīdzini stringu ($_GET[...]) ar masīvu no viena elementa ($pid). Kuri dabiski ka nebūs vienādi. Quote Link to comment Share on other sites More sharing options...
goma smile Posted March 8, 2009 Author Report Share Posted March 8, 2009 Ā kā tad SELECTO id ja tāda id nav tad parāda erorru Quote Link to comment Share on other sites More sharing options...
bubu Posted March 8, 2009 Report Share Posted March 8, 2009 Eh... ka tu nelasi, ko tev saka. $poll_id = (int)$_GET['id']; $poll_check = mysql_query("SELECT COUNT(*) FROM polls WHERE poll_id=$poll_id") or die(mysql_error()); list($count) = mysql_fetch_row($poll_check); if ($count == 0) { echo "nav"; } else { echo "ir"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.