Jump to content
php.lv forumi

ka lai uzraksta vienkarshak


marlboro

Recommended Posts

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!";
}
?>

Link to comment
Share on other sites

  • Replies 42
  • Created
  • Last Reply

Top Posters In This Topic

<?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!';
}
?>

Link to comment
Share on other sites

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'];
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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];

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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]; ?>

Link to comment
Share on other sites


×
×
  • Create New...