*Solved \\PHP Sessions question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
atsa1
Forum Newbie
Posts: 20
Joined: Wed Dec 09, 2009 9:11 am

*Solved \\PHP Sessions question.

Post by atsa1 »

Lately iv'e been asking a lot of questions and some of them figured out by myself. But now i face the problem.

Iv'e created database. table looks like this: id, date, kood, nimetus, number, kes, comment, staatus, all. from index i inclused file loe.php.
In loe.php i have this:

Code: Select all

 
<?php 
session_start(); 
$miss=$_SESSION['mis'];
$stats=$_SESSION['filter'];
?>
 
?php
mysql_connect ("localhost", "root", "defender") or die ('Error: ' . mysql_error());
mysql_select_db ("foral");
if(!isset($cmd)); 
{
//query
$query = mysql_query("SELECT * FROM tellimus WHERE $miss='$stats'");
 
Index.php looks like this:

Code: Select all

 
<?php 
session_start();
if ($_SESSION['filter']=''){
}else {
$mis='staatus';
($filter=$_POST['staatus']);
}
// adds it to our session 
$_SESSION['mis']=$mis;
$_SESSION['filter']=$filter;
?>
 
<form action="index.php" method="post" name="staatus" id="staatus" target="_self">
Kuva ainult ridasid mille staatus on:
<select name="staatus">
<option value="id">----------</option>
<option value="tellitud" value="staatus">Tellitud</option>
<option value="helistatud">Helistatud</option>
<option value="käes">käes</option>
</select>
<input type="submit" name="Submit" value="Submit" />
</form>
 
Main thing is: Session is controling the values in loe.php to read out certain line WHERE socalled status=status_from_dropdownmenu.
It works fine, but if i select the value -------- from dropdown. I have no status in mysql with that name "id" under status. Question is: How can i change session value $mis='staatus'; to $mis='id'; using the same dropdown box.

So in plain stubid way:

Code: Select all

 
if ($_POST['staatus'] = "tellitud") {
$mis="staatus";
($filter=$_POST['staatus']);
}else if ($_POST['staatus'] = "id") {
$mis="id";
($filter=$_POST['staatus']);
}
 

I could use $_POST status as $mis value but in mysql i need to get the value from either status or id.

Not that my current script aint working but it has a flaw in it. It only shows the column status value if status is selected. But i want to add users a chance to see all lines too not only the lines with selected. AKA i'm making a filter. At the beginning there should be visible all lines from mysql. But when user selects Filter from Dropdown menu, it will show only rows with selected status.
Ok. Confusing. At least for me. So any help? I have been figuring around this for couple of days now. This IS my first project where i use MySQL.
(when i started i user txt files LOL)
Thank's for your responses.
Last edited by atsa1 on Sat Jan 23, 2010 7:38 am, edited 1 time in total.
atsa1
Forum Newbie
Posts: 20
Joined: Wed Dec 09, 2009 9:11 am

Re: PHP Sessions question.

Post by atsa1 »

Ok. I managed to get my way in different way. Hope you can follow me!

Code: Select all

<table width="250" border="0">
  <tr>
    <th width="58" scope="col"><form action="loe.php?cmd=kõik" method="post"><input type="hidden" value="kõik"><input type="submit" name="kõik" id="1" value="kõik" style="background:none;border:0;color:#0000cc;text-decoration: underline" /></th></form>
    <th width="58" scope="col"><form action="loe.php?cmd=tellitud" method="post"><input type="hidden" value="tellitud"><input type="submit" name="tellitud" id="2" value="tellitud" style="background:none;border:0;color:#0000cc;text-decoration: underline" /></th></form>
    <th width="58" scope="col"><form action="loe.php?cmd=helistatud" method="post"><input type="hidden" value="helistatud"><input type="submit" name="helistatud" id="3" value="helistatud" style="background:none;border:0;color:#0000cc;text-decoration: underline" /></th></form>
    <th width="58" scope="col"><form action="loe.php?cmd=käes" method="post"><input type="hidden" value="käes"><input type="submit" name="käes" id="4" value="käes" style="background:none;border:0;color:#0000cc;text-decoration: underline" /></th></form>
  </tr>
</table>
<?
if ($_GET['cmd']=='kõik')
{
    $vali= "order by id" or die ('Error: ' . mysql_error());
}else if ($_GET['cmd']=='tellitud')
{
    $vali = "WHERE staatus='tellitud'" or die ('Error: ' . mysql_error());
}else if ($_GET['cmd']=='helistatud')
{
    $vali = "WHERE staatus='helistatud'" or die ('Error: ' . mysql_error());
}else if ($_GET['cmd']=='käes')
{
    $vali = "WHERE staatus='käes'" or die ('Error: ' . mysql_error());
}else {}
?>
<?php
mysql_connect ("localhost", "myuser", "mypass") or die ('Error: ' . mysql_error());
mysql_select_db ("foral");
 
//query
$query = mysql_query("SELECT id, date, kood, kogus, nimetus, number, kes, komm, staatus FROM tellimus $vali");
//display row
while ($row = mysql_fetch_array($query)) {
$id=$row['id'];//take out the id
$kood=$row['kood'];
$nimetus=$row['nimetus'];
$kogus=$row['kogus'];
$number=$row['number'];
$kes=$row['kes'];
$staatus=$row['staatus'];
 
  echo 
    '<form action="muuda.php?cmd=change" method="post">'.'<td border="1" size="1"><input name="id" type="text" size="1" value="'.$row['id'].'">'.'<td border="1" size="3"><input name="kood" type="text" size="6" value="'.$row['date'].'">'.'<td border="1" size="3"><input name="kood" type="text" size="23" value="'.$row['kood'].'">'.'<td border="1" size="3"><input name="nimetus" type="text" size="23" value="'.$row['nimetus'].'">'.'<td border="1" size="3"><input name="kogus" type="text" size="3" value="'.$row['kogus'].'">'.'<td border="1" size="3"><input name="number" type="text" size="23" value="'.$row['number'].'">'.'<td border="1" size="3"><input name="kes" type="text" size="8" value="'.$row['kes'].'">'.'<td border="1" size="3"><input name="komm" type="text" size="35" value="'.$row['komm'].'">';
    echo '<select name="staatus"><option selected>'.$row['staatus'].'</option><option value="" disabled>----------</option><option value="tellitud">Tellitud</option><option value="helistatud">Helistatud</option><option value="käes">käes</option></select>'.'&nbsp<td border="1" size="3"><A HREF="javascript&#058;decision(\'Kas kustutame rea '.$id.'?\', \'loe.php?cmd=delete&id='.$id.'\')">kustuta</a>'.'<td border="1" size="3"><input type="submit" value="Muuda" style="background:none;border:0;color:#0000cc;text-decoration: underline"/>'.'<br /></form>';}
  
 
?>
All i wanted was that:

Code: Select all

29.$query = mysql_query("SELECT id, date, kood, kogus, nimetus, number, kes, komm, staatus FROM tellimus $vali");
i could choose the value of $vali

Now i did it with simple buttons and if 10.if ($_GET['cmd']==
clever aint i?
Well it is my first project using mySQL. But i think i did great.
Post Reply