millers Posted August 1, 2008 Report Share Posted August 1, 2008 tatad ta man nepieciesams user level es kko sadu uzrakstiju bet man vajg vell dazus pievienot ka varetu ar elseif ? un ja ja tad kaa . <?php if($_GET["tips"] = 4); { echo "sveiks admin"; } ?> Link to comment Share on other sites More sharing options...
Aleksejs Posted August 1, 2008 Report Share Posted August 1, 2008 Pirmkārt: nevis $_GET['tips']=4 bet gan $_GET['tips']==4 ;) Taisi ar switch: switch($_GET['tips']){ case 1: $msg='Tu pirmā tipa lietotājs'; break; case 2: $msg='Tu esi otrais tips'; break; case 3: $msg='Tu esi trešais... tēva dēls'; break; case 4: $msg='Tu esi ceturtais tips...'; break; default: $msg='Tu esi, kaut kas netipisks. Man bail!'; } echo $msg; Link to comment Share on other sites More sharing options...
millers Posted August 1, 2008 Author Report Share Posted August 1, 2008 hmm Notice: Undefined index: tips in C:\wamp\www\admin.php on line 59 Link to comment Share on other sites More sharing options...
Artenis Posted August 1, 2008 Report Share Posted August 1, 2008 (edited) switch($_GET['tips']){ default: case 0: $msg='Tu esi, kaut kas netipisks. Man bail!'; break; case 1: $msg='Tu pirmā tipa lietotājs'; break; case 2: $msg='Tu esi otrais tips'; break; case 3: $msg='Tu esi trešais... tēva dēls'; break; case 4: $msg='Tu esi ceturtais tips...'; break; } echo $msg; moška šitā? Edited August 1, 2008 by Artenis Link to comment Share on other sites More sharing options...
Klez Posted August 1, 2008 Report Share Posted August 1, 2008 (edited) $_GET['tips'] = (int)$_GET['tips'] switch($_GET['tips']){ case 1: $msg='Tu pirmā tipa lietotājs'; break; case 2: $msg='Tu esi otrais tips'; break; case 3: $msg='Tu esi trešais... tēva dēls'; break; case 4: $msg='Tu esi ceturtais tips...'; break; case 0: $msg='Tu esi, kaut kas netipisks. Man bail!'; break; } echo $msg; Edited August 1, 2008 by Klez Link to comment Share on other sites More sharing options...
Aleksejs Posted August 1, 2008 Report Share Posted August 1, 2008 Notice it tad un tikai tad, ja neesi padevis caur adresi tips=blabla default: varēja neaiztikt - ne tur tā vaina :) Link to comment Share on other sites More sharing options...
Klez Posted August 1, 2008 Report Share Posted August 1, 2008 nu jaa, tapeec jau liku $_GET['tips'] = (int)$_GET['tips'] lai nav notiice :) un shajaa gadiijumaa nevar mainiigajaa visu kaut ko baazt iekshaa ... bet tas jau ir cits staast .. :) Link to comment Share on other sites More sharing options...
andrisp Posted August 1, 2008 Report Share Posted August 1, 2008 Klez, tak ar to kodu tāpat būs notice. :) Link to comment Share on other sites More sharing options...
Klez Posted August 1, 2008 Report Share Posted August 1, 2008 if (!$_GET['tips']) $_GET['tips'] = (int)$_GET['tips']; else $_GET['tips'] = (int)$_GET['tips']; :) Link to comment Share on other sites More sharing options...
andrisp Posted August 1, 2008 Report Share Posted August 1, 2008 (edited) Nu tāpat būs notice. :) Un vispār tā rindiņa ir muļīga un ne ar ko neatšķiras no vienkārši $_GET['tips'] = (int)$_GET['tips'] Edited August 1, 2008 by andrisp Link to comment Share on other sites More sharing options...
Klez Posted August 1, 2008 Report Share Posted August 1, 2008 nu jaa :) vienkaarshaak ir atsleegt notiices :) Link to comment Share on other sites More sharing options...
andrisp Posted August 1, 2008 Report Share Posted August 1, 2008 (edited) Nē, labāk uztaisīt normāli pārbaudi: $page = 1; if (!empty($_GET['page']) && is_numeric($_GET['page'])) { $page = (int) $_GET['page']; } Edited August 1, 2008 by andrisp Link to comment Share on other sites More sharing options...
Aleksejs Posted August 1, 2008 Report Share Posted August 1, 2008 (edited) Lai nebūtu notice ir jāizmanto- isset(); tobiš: $msg=''; //Better safe than sorry - tāpēc nodefinēsim mainīgo tukšu if(isset($_GET['tips'])){ switch($_GET['tips']){ case 1: $msg='Tu pirmā tipa lietotājs'; break; case 2: $msg='Tu esi otrais tips'; break; case 3: $msg='Tu esi trešais... tēva dēls'; break; case 4: $msg='Tu esi ceturtais tips...'; break; default: $msg='Tu esi, kaut kas netipisks. Man bail!'; } } else { $msg = 'Tu esi pilnīgi netipisks! Gribi par to parunāt?'; } echo $msg; EDIT: Andri, negribu derēt, bet man šķiet, ka empty arī ģenerēs Notice :) Edited August 1, 2008 by Aleksejs Link to comment Share on other sites More sharing options...
andrisp Posted August 1, 2008 Report Share Posted August 1, 2008 (edited) Neģenerēs. Točna zinu. empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. Edited August 1, 2008 by andrisp Link to comment Share on other sites More sharing options...
Aleksejs Posted August 1, 2008 Report Share Posted August 1, 2008 Jā, tik tiešām! Redz, cik es tālredzīgs, ka nederēju :D empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. P.S. Pārbaudīts arī eksperimentāli. Link to comment Share on other sites More sharing options...
Recommended Posts