marlboro Posted December 2, 2008 Report Posted December 2, 2008 Sveiki man ir skripts kas peec id izdruka konkretu mainigo (mainigie DB tabulas) Taatad ta jautajums - Kaa lai vienkarshak sho visu uzraxtu ? - manuprat tas ir loti mulkigi katram id ar roku rakstit un definet savu mainigo - ka lai panak aatraakaa ,ertakaa veida ka php saprot ja id =1 tad izruka db tabulu 1 ja id=2 tad izdruka Db tabulu 2 un tt... <?php $saturs_x = (int)$_GET['lapa']; if($saturs_x == 1){ echo "$saturs"; } else if ($saturs_x == 2){ echo "$saturs_a2"; } else if ($saturs_x == 3){ echo "$saturs_a3"; } else if ($saturs_x == 4){ echo "$saturs_a4"; } else if ($saturs_x == 5){ echo "$saturs_a5"; }else{ echo "Izvзlies sadaпu!"; } ?>
waplet Posted December 2, 2008 Report Posted December 2, 2008 mysql select from table where table name = saturs_x
bubu Posted December 2, 2008 Report Posted December 2, 2008 Masīvus ir jālieto: <?php $arr = array( 1 => "teksts1", 2 => "teksts2", 3 => "teksts3", ...); $x = 2; echo $arr[$x]; ?>
Aleksejs Posted December 2, 2008 Report Posted December 2, 2008 <?php $saturs_x = (int)$_GET['lapa']; switch($saturs_x){ case 1: echo $saturs; break; case 2: echo $saturs_a2; break; case 3: echo $saturs_a3; break; case 4: echo $saturs_a4; break; case 5: echo $saturs_a5; break; default: echo "Izvзlies sadaпu!"; } ?> Ja nevajadzētu pirmo keisu, tad: $saturs_x = (int)$_GET['lapa']; if($saturs_x > 0 && $saturs_x < 6){ echo ${saturs_a$saturs_x}; } else { echo 'Izvзlies sadaпu!'; } ?>
marlboro Posted December 2, 2008 Author Report Posted December 2, 2008 Patreiz man sanak ta ja - $saturs_x = ar kkadau id nr tad izrukaju mainigo kas definets - mainigo satura ir informacija par to ka savienoties ar DB un izdrukat konkreto tabulu - ka lai to vissu uztasisu vienkarshaku un bez mazakas rasktishanas ..? $result = mysql_query("SELECT saturs from x_lv.lapas where id = '1' ") or die("Nevar savienoties ar tabulu 1!"); while ($row = mysql_fetch_assoc($result)){ $saturs = $row['saturs']; } $rezultats_a2 = mysql_query("SELECT saturs from x_lv.lapas where id = '2' ") or die("Nevar savienoties ar tabulu 2!"); while ($row_a2 = mysql_fetch_assoc($rezultats_a2)){ $saturs_a2 = $row_a2['saturs']; } $rezultats_a3 = mysql_query("SELECT saturs from x_lv.lapas where id = '3' ") or die("Nevar savienoties ar tabulu 3!"); while ($row_a3 = mysql_fetch_assoc($rezultats_a3)){ $saturs_a3 = $row_a3['saturs']; } $result_a4 = mysql_query("SELECT saturs from x_lv.lapas where id = '4' ") or die("Nevar savienoties ar tabulu 4!"); while ($row_a4 = mysql_fetch_assoc($result_a4 )){ $saturs_a4 = $row_a4 ['saturs']; } $result_a5 = mysql_query("SELECT saturs from x_lv.lapas where id = '5' ") or die("Nevar savienoties ar tabulu 5!"); while ($row_a5 = mysql_fetch_assoc($result_a5 )){ $saturs_a5 = $row_a5 ['saturs']; }
Aleksejs Posted December 2, 2008 Report Posted December 2, 2008 (edited) Es rakstītu vienu vaicājumu: SELECT id, saturs FROM x_lv.lapas WHERE id IN (1,2,3,4,5) P.S. Pieliku id rezultātam. Edited December 2, 2008 by Aleksejs
marlboro Posted December 2, 2008 Author Report Posted December 2, 2008 ok ar db nolasishanu itka esmu ticis skaidriba - a ka tagad izdrukat $result = mysql_query("SELECT id, saturs FROM xx_lv.lapas WHERE id IN (1,2,3,4,5)") or die("Nevar savienoties ar tabulu!"); while ($row = mysql_fetch_assoc($result)){ $saturs = $row['saturs']; } $select_opts = array(1,2,3,4,5); if ($_GET['lapa']) { $lapa = (int)$_GET['lapa']; echo $saturs; << patreiz sanaak ka man tiek izdrukaats kkadz rezultats nevis rezultats pec konkeeta id } else { $lapa = 0; } if (!in_array($lapa, $select_opts)) $lapa = 0
Aleksejs Posted December 2, 2008 Report Posted December 2, 2008 $result = mysql_query("SELECT id, saturs FROM xx_lv.lapas WHERE id IN (1,2,3,4,5)") or die("Nevar savienoties ar tabulu!"); $lapu_masivs = new Array(); while ($row = mysql_fetch_assoc($result)){ $lapu_masivs[$row['id']]=$row['saturs']; } $lapa = (int)$_GET['lapa']; echo $lapu_masivs[$lapa];
marlboro Posted December 3, 2008 Author Report Posted December 3, 2008 index>>>>> <form name="form1" method="post" action="updatePage.php"> <?php $result = mysql_query("SELECT id, saturs FROM xx_lv.lapas WHERE id") or die("Nevar savienoties ar tabulu!"); $lapu_masivs = Array(); while ($row = mysql_fetch_assoc($result)){ $lapu_masivs[$row['id']]=$row['saturs']; } $lapa = (int)$_GET['lapa']; ?> <textarea rows="10" cols="60" name="contents"> <?php echo $lapu_masivs[$lapa]; ?> </textarea> <input type="submit" name="Submit" value="Saglabвt"> </form> >>>>>>updatePage.php>>>>>> Kaa butu jaiskatas updatepage lai ta veiktu ierakstu vajdzigaja DB tabulai ? $contents=$_REQUEST['contents']; $result = @mysql_query("UPDATE xx_lv.lapas SET saturs='$contents' where id = '???'"); mysql_close(); ?>
Aleksejs Posted December 4, 2008 Report Posted December 4, 2008 Tev ir jāpieliek hidden lauks index lapā, kas satur $lapa: ... $lapa = (int)$_GET['lapa']; ?> <textarea rows="10" cols="60" name="contents"> <?php echo $lapu_masivs[$lapa]; ?> </textarea> <input type="hidden" name="lapas_id" value="<?php echo $lapa; ?>"> ... un tad attiecīgi updatePage.php izmantot šo padoto mainīgo: $contents=$_REQUEST['contents'];//A kāpēc REQUEST - vai tiešām Tev vajag, lai arī caur GET varētu padot?? $iidee = intval($_REQUEST['lapas_id']); $result = @mysql_query("UPDATE xx_lv.lapas SET saturs='$contents' where id = $iidee"); mysql_close(); ?>
marlboro Posted December 5, 2008 Author Report Posted December 5, 2008 Ok ar to tiku galaa viss tagad strada - bet man patreiz ir Undefined offset: 0 ka lai to defineju ?piem ja id nau tad ielade konkretu tabulu
Aleksejs Posted December 5, 2008 Report Posted December 5, 2008 Pārbaudi, vai atslēga eksistē ar array_key_exists(). Ja nav tādas atslēgas, tad izvadi defaulto.
marlboro Posted December 5, 2008 Author Report Posted December 5, 2008 kaa lai izvada defaulto? reku man tas viss... $result = mysql_query("SELECT id, saturs FROM xx_lv.lapas WHERE id") or die("Nevar savienoties ar tabulu!"); $lapu_masivs = Array(); while ($row = mysql_fetch_assoc($result)){ $lapu_masivs[$row['id']]=$row['saturs']; } $lapa = (int)$_GET['lapa']; ?> izrukaju ta - <?php echo $lapu_masivs[$lapa]; ?>
Aleksejs Posted December 5, 2008 Report Posted December 5, 2008 Pirms izdrukāšanas, pārbaudi. ja lapu masīvs satur indeksu lapa, tad drukāt lapumasīvs[indekss], citādi drukāt kaut ko ko nu tev vajag, ja padots neeksistējošs indekss.
marlboro Posted December 5, 2008 Author Report Posted December 5, 2008 isti nesapratu ka lai to pieraksta ? :(
Recommended Posts