Jump to content

[SOLVED] Please help


oceans

Recommended Posts

:'(Dear Friends,

 

This is a tricky one;

Situation:

I will have a database, Fields in the database: (1) Country Name, (2) State Name, (3) City Name, (4) Student ID.

 

At the first run of my page, I will have only Country Name Combo Box filled with Country Names and a button beside it.

 

Please follow my sequence (a,bc,)

 

a) When Country Name has been selected and the button pressed, SQL will be done to populate State Name Combo box , this combo box appears and a button appears beside this, at the same time the country combo box disappears to become a text value and the button disappears.

 

b) now the next selection, when state name has been selected and the button pressed, SQL will be done to populate City Name Combo box, this combo box appears and a button appears beside this, at the same time the state name combo box disappears to become a text value and the button disappears.

 

c) same thing for city, then I will be able to populate Student ID, bla, bla after which

 

I tried very hard, am very tired, but it is killing me, I did not sleep.

 

Fetching data is not problem, only the reaction on screen:

My current problem:

One the first load all three fields and all buttons appear

I could not figure out how to make the combo to become text value and kill the respective button.

 

 

Here is my test page

"

<?php

/*

 

 

 

*/

?>

<?php

ob_start();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title></title>

<link href="../../CSS/StyleSheet.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?PHP

if (isset($_POST['Submit']))

{

$StoreDepthLevel=$_POST["TxtDepthLevel"];

$CountryName=$_POST["CountryName"];

$StateName=$_POST["StateName"];

}

else

{

$StoreDepthLevel=1;

}

?>

<form id="form1" name="form1" method="post" action="0701Viewtest.php">

<table width="741" border="0" cellpadding="5" cellspacing="0">

<tr>

<td width="81" class="FieldName"><span class="FieldName">Country Name</span></td>

<td width="201" class="FieldValue"> </td>

<td width="429" class="FieldValue"><span class=" ">

<select name="CountryName" size="1" class="FieldValue" id="CountryName">

<option

value="AF">Afghanistan</option>

<option value="AL">Albania</option>

<option value="DZ">Algeria</option>

<option value="AS">American

Samoa</option>

<option value="AD">Andorra</option>

<option

value="AO">Angola</option>

<option value="GB">United Kingdom</option>

<option

value="US" selected="selected">United States</option>

</select>

<?PHP

if ($StoreDepthLevel==1)

{

echo "<input name=Submit1 type=submit class=FeildButton id=Submit1 value=Submit />";

}

?>

</span></td>

</tr>

<tr>

<td class="FieldName"><span class="FieldName">State Name</span></td>

<td class="FieldValue"> </td>

<td class="FieldValue">

<?PHP

if ($StoreDepthLevel==1)

{

/*Search For Country Entry & Fill State Entry*/

$con = mysql_connect($DataBaseHostName,$DataBaseUserName,$DataBaseUserPassword);

if (!$con)

{

echo "<br />Could NOT Connect to Server, Please Contact our Webmaster for Assistance!<br /><br />";

}

else

{

mysql_select_db($DataBaseName, $con);

$result = mysql_query("SELECT DISTINCT `StateName` FROM `st` WHERE `CountryName` = '".$_POST["CountryName"]."'");

}

if (mysql_num_rows($result))

{

echo "<select name=\"StateName\" id=\"StateName\">";

while($row = mysql_fetch_assoc($result))

{

echo " <option value=\"".$row['StateName']."\">".$row['StateName']."</option>";

}

echo "</select>";

$StoreDepthLevel=2;

}

else

{

echo "No Record!";

}

mysql_close($con);

}

?>

<span class=" ">

<?PHP

if ($StoreDepthLevel==2)

{

echo "<input name=Submit2 type=submit class=FeildButton id=Submit2 value=Submit />";

}

?>

</span></td>

</tr>

<tr>

<td class="FieldName"><span class="FieldName">City Name</span></td>

<td class="FieldValue"> </td>

<td class="FieldValue"><?PHP

if ($StoreDepthLevel==2)

{

/*Search For State Entry & Fill City Entry*/

$con = mysql_connect($DataBaseHostName,$DataBaseUserName,$DataBaseUserPassword);

if (!$con)

{

echo "<br />Could NOT Connect to Server, Please Contact our Webmaster for Assistance!<br /><br />";

}

else

{

mysql_select_db($DataBaseName, $con);

$result = mysql_query("SELECT DISTINCT `CityName` FROM `st` WHERE `CountryName` = '".$_POST["CountryName"]."' AND `StateName` = '".$_POST["StateName"]."'");

}

if (mysql_num_rows($result))

{

echo "<select name=\"CityName\" id=\"CityName\">";

while($row = mysql_fetch_assoc($result))

{

echo " <option value=\"".$row['CityName']."\">".$row['CityName']."</option>";

}

echo "</select>";

$StoreDepthLevel=3;

}

else

{

echo "No Record!";

}

mysql_close($con);

}

?>

<span class=" ">

<?PHP

if ($StoreDepthLevel==3)

{

echo "<input name=Submit3 type=submit class=FeildButton id=Submit3 value=Submit />";

}

?>

</span></td>

</tr>

<tr>

<td class="FieldName">Student ID </td>

<td class="FieldValue"> </td>

<td class="FieldValue"> </td>

</tr>

<tr>

<td class="FieldName"> </td>

<td class="FieldValue"> </td>

<td class="FieldValue"><input name="TxtDepthLevel" type="text" class="FieldValue" id="TxtDepthLevel" value="<?PHP echo $StoreDepthLevel; ?>" size="2" maxlength="50"/>

<span class=" ">

 

</span></td>

</tr>

</table>

</form>

</body>

</html>

"

 

 

"

Link to comment
Share on other sites

I don't feel like reworking your code, or writing something else, so I'll just post the basic idea you should follow.... (It actually looks like you have it pretty well).

 

It looks like you have the concept right, but hopefully this will help you:

 

if nothing is set {
do the stuff for outputting countries
}
elseif country is set and state is not set {
if country is valid {
	if rows exist for it {
		echo the states or what ever for the country
	}
	else {
		echo some message about no states for that country or something like that....
	}
}
else {
	show country form
}
}
elseif state is set {
make the city form based off the state input
}
elseif city is set {
make the student ID form from the city selected
}
else {
uhh this should never be reached, but I guess if it does just show the country form or something ;p
}

Link to comment
Share on other sites

Dear Corbin,

Thanks for your advice, but I am lost still.

Is it OK if you quickly browse through my code, i know i need twitching, i do not know where.

Sorry i never ask this type of help , but please help me. I am going arround this for 16 hrs now, you will know what i mean.

SORRY for the bother.

Link to comment
Share on other sites

Why would you need to use a session?

 

And I would suggest never sending unnecessary info to the client....  When using a session, it sends the user a session id which goes into a cookie.... Then that gets checked by the server and if it correlates to a session file, then that session file is assigned to them, and the session variables are set from it.

 

So basically, it saves bandwidth and increases security to keep as much as possible on the server side.... 

Link to comment
Share on other sites

thanks corbin,

 

please stick my code onto your screen, you will find the flaw, i am walking like a dog chasing after its own tail, i am in bad shape.

please help.

 

i think we need cookie, because, country selection fills state and waits for user, than state sellection fills city then waits for user,

Link to comment
Share on other sites

just do something like

 

if($_POST['city']) {
//display student id form
}
elseif($_POST['state']) {
//display city form
}
elseif($_POST['country']) {
//display state form
}
else {
//display country form
}

 

This would assume all the forms lead to the same page, and don't pass any variables from the past submits.

 

As for what you meant by sticking the code on my screen, I have no idea.... lol ;p

Link to comment
Share on other sites

Try this:

$step = isset($_GET['step']) ? $_GET['step'] : 1 ;

switch($step){

case "1":
# Got nothin'!
run_mysql_query("SELECT * FROM countries");
echo "Select Country<br />"
foreach($country as $country_name){
echo "<a href=\"{$_SERVER['PHP_SELF']}?step=2&country=$countryname\">$countryname</a><br />";
}
break;

case "2":
#Gotta country name!
if(!isset($_GET['country'])){
die("No Country");
}
echo "Pick state for {$_GET['country']}<br />";
run_mysql_query("SELECT * FROM states WHERE country = {$_GET['country']}");
foreach ($state as $statename){
echo "<a href=\"{$_SERVER['PHP_SELF']}?country={$_GET['country']}&state=$statename&step=3\">";
}
break;

case "3":
#Gotta country name & state name!
if(!isset($_GET['country']) AND !isset($_GET['state'])){
die("We need a country and a state to continue!");
}
run_mysql_query("SELECT * FROM cities WHERE state={$_GET['state']}");
foreach($city as $cityname){
echo "<a href=\"{$_SERVER['PHP_SELF']}?country={$_GET['country']}&state={$_GET['state']}&city=$cityname&step=4\">$cityname</a><br />";
}
break;

case "4":
# gotta country, gotta state, gotta city!
if(!isset($_GET['country']) AND !isset($_GET['state']) AND !isset($_GET['city'])){
die("We need a country and a state and a city to continue!");
}
run_mysql_query("SELECT * FROM studentids WHERE city={$_GET['city']}");
echo "Pick Student ID <br />";
foreach ($studentid as $studentidname) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?country={$_GET['country']}&state={$_GET['state']}&city={$_GET['city']}&studentid={$studentidname}&step=5\">$studentidname</a>";
}
break;

case "5":
# got everything!
if(!isset($_GET['country']) AND !isset($_GET['state']) AND !isset($_GET['city']) AND !isset($_GET['studentid'])){
die("Why are you here?");
}
do_stuff();
break;

default:
echo "You will NEVER see this page printed on your browser. *evil laugh*";
break;

}

 

I omitted some of the mysql stuff, since you have that down. This basically brute forces it into steps by defining which step to take next in the previous one.

Link to comment
Share on other sites

Thanks Ravo and Corbin,

My fist country is a fix combo box with already entered values,

can you please twitch your code, i am gettnig foreach error for country.

may i say that you want me to change my post to get.

Link to comment
Share on other sites

I used $_GET variables because URLs have less text in them than forms. That meant less typing for me. =) The point I was trying to make is that if you are specific about what code you're trying to run at what time (using the variable $step as nothing more than a placeholder) it can make those long processes easier.

Link to comment
Share on other sites

People,

 

It seems working, but my country combo which already has the value always gets to the first entry after page reloads due to posting to itself, let posting to itself be i like it, can you help me to make the country value staty after selection. i did it some time ago but forgot.

Link to comment
Share on other sites

I found this very difficult thus i implement one search per page (1.5 days with one problem)

not very professional, but it works and had all my requirements meet.

 

I need another help, can you please show me how to draw table for each entry from database.

 

Lets say i have one col header, 5 fields. the number of repetition i can handel

just give me the "content in the for loop" and the header maker.

 

thanks.

Link to comment
Share on other sites

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#6A89C2" width="88%">
                      <tr>
                      <td height = 18 width="5%" bgcolor="#6A89C2" align='center'><font >No</font></td>
                      <td width="10%" bgcolor="#6A89C2" align='center'><font >User No</font></td>
                      <td width="35%" bgcolor="#6A89C2">  <font >Name</font></td>
                      <td width="20%" bgcolor="#6A89C2">  <font >Login</font></td>
                      <td width="18%" bgcolor="#6A89C2">  <font >Password</font></td>


                      </tr>
                      <?php
                      $num = $offset + 1;
                      while($row = mysql_fetch_array($result_list)) {
                         $sql="Your query here";
                         $result= mysql_query($sql) or err_handler();
                         $row = mysql_fetch_object($result);
                                                 
                         echo "<tr>";
                         echo "<td align='center'>$num </td>";
                         echo "<td align='center'>$row->nruser</td>";
                         echo "<td> $row->Name</td>";
                         echo "<td> $row->Login</td>";
                         echo "<td> $$row->Pass</td>";

                         echo "</tr>";
                         $num++;
                      } ?>

Link to comment
Share on other sites

Mmarif4u,

Don't get me wrong,

(i)how can you fatch before query

 

I always use

"

/*DO SQL;*/

if (mysql_num_rows($result))

{

while($row = mysql_fetch_assoc($result))

{

echo $row['somthing'];

}

 

}

else

 

 

"

you are using "while($row = mysql_fetch_array($result_list))"

 

any difference.

Link to comment
Share on other sites

I did this

"

 

 

 

if (mysql_num_rows($result))

{

while($row = mysql_fetch_assoc($result))

{

echo "<tr>";

echo "<td class=FieldName>".$row['RegTime']."</td>";

echo "</tr>";

}

}

 

 

 

 

"

 

I can get only one feild, can any one extend my code to get two feilds, my another column is $row['RegDate']

Link to comment
Share on other sites

people i got it

 

  if (mysql_num_rows($result))

  {

      while($row = mysql_fetch_assoc($result))

      {

          echo "<tr>";

          echo "<td class=FieldName>".$row['RegTime']."</td>";

echo "<td class=FieldName>".$row['RegDate']."</td>";

          echo "</tr>";

      }

  }

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.