Really new in PHP
So don't know what to do now??
I have a form which have one select button have different catalog. And i want to do when i choose one catalog, my page will show what's that related.
here is my form code:

<form action="index.php" method=GET name=chcat >
               
 <select name=id onChange="document.forms['chcat'].submit();">
 <option value=0>All</option>
 <option value="2">Pizza</option>  
 <option value="4">Special Dinners</option>  
 <option value=5>Side Orders</option>  
 <option value=6>Salads</option> 
 <option value=7>Spaghetti or Ziti</option> 
 <option value=8>Home made Lasagna Ravioli or Manicotti</option>
 <option value=9>Homemade Galzones</option>
 <option value=10>Wraps</option>
 <option value=10>Grinders</option>
</select>
</form>

And do i need to add some PHP code here??
Really appreciate with that!

If you want it so that when the above menu is submitted then another menu will appear then try the following:

<form action="index.php" method=GET name=chcat >
               
 <select name=id onChange="document.forms['chcat'].submit();">
 <option value=0>All</option>
 <option value=2>Pizza</option>  
 <option value=4>Special Dinners</option>  
 <option value=5>Side Orders</option>  
 <option value=6>Salads</option> 
 <option value=7>Spaghetti or Ziti</option> 
 <option value=8>Home made Lasagna Ravioli or Manicotti</option>
 <option value=9>Homemade Galzones</option>
 <option value=10>Wraps</option>
 <option value=10>Grinders</option>
</select>
</form>
<?
if (isset($_GET['id'])) {
    if ($_GET['id']==0) {
        //display 'all' menu
        }
    if ($_GET['id']==2) {
        //display 'Pizza' menu
        }
    if ($_GET['id']==4) {
        //display 'Special Dinners' menu
        }
    if ($_GET['id']==5) {
        //display 'Side Orders' menu
        }
    if ($_GET['id']==6) {
        //display 'Salads' menu
        }
    if ($_GET['id']==7) {
        //display 'Spaghetti or Ziti' menu
        }
    if ($_GET['id']==8) {
        //display 'Home mad Lasagna Ravioli or Manicotti' menu
        }
    if ($_GET['id']==9) {
        //display 'Homemade Galzones' menu
        }
    if ($_GET['id']==10) {
        //display 'Wraps/Grinders' menu
        }
    }
?>

So do i need to put any id number or change any code inside my menu html code part?? like mark some special number there??
Thanks.

So do i need to put any id number or change any code inside my menu html code part?? like mark some special number there??
Thanks.

Although I don't 100% understand that (slightly fragmented), besically to use my example script, place the each possible second menu where the comments are. And as for the id number, the if statment id number needs to match the id number to gets put into the url bar which if you don't change I have allready done.

Sorry, but i am really new in php.
So if this sounds stupid then really sorry.
Here is the thing i want to do:
like you said display the each menu according to the id number.

<form action="index.php" method=GET name=chcat >
               
 <select name=id onChange="document.forms['chcat'].submit();">
 <option value=0>All</option>
 <option value=2>Pizza</option>  
 <option value=4>Special Dinners</option>  
 <option value=5>Side Orders</option>  
 <option value=6>Salads</option> 
 <option value=7>Spaghetti or Ziti</option> 
 <option value=8>Home made Lasagna Ravioli or Manicotti</option>
 <option value=9>Homemade Galzones</option>
 <option value=10>Wraps</option>
 <option value=10>Grinders</option>
</select>
</form>
<?
if (isset($_GET['id'])) {
    if ($_GET['id']==0) {
        //display 'all' menu
        }
    if ($_GET['id']==2) {
        //display 'Pizza' menu
<table>
<tr>
cheese pizza
</tr>
<tr>
another pizza
</tr>
</table>
        }
    if ($_GET['id']==4) {
        //display 'Special Dinners' menu
        }
    if ($_GET['id']==5) {
        //display 'Side Orders' menu
        }
    if ($_GET['id']==6) {
        //display 'Salads' menu
        }
    if ($_GET['id']==7) {
        //display 'Spaghetti or Ziti' menu
        }
    if ($_GET['id']==8) {
        //display 'Home mad Lasagna Ravioli or Manicotti' menu
        }
    if ($_GET['id']==9) {
        //display 'Homemade Galzones' menu
        }
    if ($_GET['id']==10) {
        //display 'Wraps/Grinders' menu
        }
    }
?>

Or another way to do that like following??

<form action="index.php" method=GET name=chcat >
               
 <select name=id onChange="document.forms['chcat'].submit();">
 <option value=0>All</option>
 <option value=2>Pizza</option>  
 <option value=4>Special Dinners</option>  
 <option value=5>Side Orders</option>  
 <option value=6>Salads</option> 
 <option value=7>Spaghetti or Ziti</option> 
 <option value=8>Home made Lasagna Ravioli or Manicotti</option>
 <option value=9>Homemade Galzones</option>
 <option value=10>Wraps</option>
 <option value=10>Grinders</option>
</select>
</form>
<?
if (isset($_GET['id'])) {
    if ($_GET['id']==0) {
        //display 'all' menu
        }
    if ($_GET['id']==2) {
        //display 'Pizza' menu--could i put like the following??

        }
    if ($_GET['id']==4) {
        //display 'Special Dinners' menu
        }
    if ($_GET['id']==5) {
        //display 'Side Orders' menu
        }
    if ($_GET['id']==6) {
        //display 'Salads' menu
        }
    if ($_GET['id']==7) {
        //display 'Spaghetti or Ziti' menu
        }
    if ($_GET['id']==8) {
        //display 'Home mad Lasagna Ravioli or Manicotti' menu
        }
    if ($_GET['id']==9) {
        //display 'Homemade Galzones' menu
        }
    if ($_GET['id']==10) {
        //display 'Wraps/Grinders' menu
        }
    }
?>

//the html table here do i need to mark some special id here to related to the php code??
<table>
<tr>
cheese pizza
</tr>
<tr>
another pizza
</tr>
</table>

Maybe its really simply question and i am kind of stuck here!!
Sorry about that!!
Learn something from www.w3schools.com couldn't help me solve the problem la!!

Hi....

here i am using ONCHANGE event to select box....i dont know is it useful or not?? just i am trying to help u....

<script language="javascript">
	 function switchProduct()
	 {
	 if(window.document.formname.selectboxname.options.selectedIndex!=0)
	 
	 window.location=window.document.formname.selectboxname.options[window.document.form1.category.options.selectedIndex].value
	 }
	  </script>
<?php
 include("config.php");
 $category=$_GET['selectboxname'];
switch($category)
{
case "1":
 $c="1";
 break;
case "2":
 $c="2";
 break;
case "3":
 $c="3";
 break;
case "4":
 $c="4";
 break;
 
case "5":
 $c="5";
 break;

}
[B]  <select name="selectboxname" id="category" onchange="switchProduct();" >
<option value="">aaaa</option>.
.
.
</select>



[/B]
		 
          ?>

try to do this....if u want more explanation i will send u..

ahmksssv, thanks.

Three questions:

First: where is the config.php?? Its that mean my current php file??
Second: the $c means??
Third: is that mean i could put my html code under the php code and it still show what it should been showed??

First, i really don't know the PHP code at all.
So pleas forgive me if i made some stupid mistakes.
Thanks so much.
If you don't understand my english, please tell me.

here is my php code, pleas help me check it and tell me how to make it works.

<?php
    // load the XML file
    $xml = simplexml_load_file("store.xml");
    // store the header text in a variable that can be appended to below
    $subheader[1] = "Pizza";
    $subheader[2] = "Special Dinners";
    $subheader[3] = "Sider Order";
    $subheader[4] = "Salads";
    $subheader[5] = "Homemade Calzones";
    $subheader[6] = "Wraps $4.95";
    $subheader[7] = "Grinders";
     
    // determine whether we need to search or show all of the store's items
    if(isset($_POST["search"]) && !empty($_POST["search"]))
    {
        // use the search term supplied by the user to create an XPath query
        $search = $_POST["search"];
        $results = $xml->xpath("//item[contains(name, '$search')]");

        // append the search term to the header element so we can show the user what they searched for
       //here i want to do one loop which related to the search form but i don't know how to do it
        for($i=1;$i<=7;$i+=1)
     {
        $subheader[i] = $subheader[$i] . " - Search '{$search}'";
     }
    }
    else
    {
        // no search term was provided, so we'll show all of the store's items
       //here i also want to do one loop which the results could have different according to the "i" and related to the results
        for($i=1;$i<=7;$i+=1)
        {
        $results[i] = $xml->items->catalog;
        }
    }
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
         <h1><?php print($subheader[1]);?></h1>//here i want to show different header name according to the different subheader name which i defined on my top code
        <img src="img/pizza.png" border="0"/>
        <div>
        <table border="0" cellpadding="4px">
         <tr>
         <th width="96">Name</th>
         <th width="96">Description</th>
         <th width="72">Price(L)</th>
         <th width="74">Price(S)</th>
         <th width="173">Add to Cart</th>
         </tr>
         <?php
          foreach($results[1] as $item)//same thing here, i want to show different results
         {
          print("<tr><th>{$item->name}</th><th>{$item->description}</th><th>{$item->size->large->price}</th><th>{$item->size->small->price}</th><th><a href='add.php?id={$item['id']}'>add to cart</a></th></tr>");
                }
          ?>
        </table>
<form action="index.php" method="post">
<p>Search food names: <input type="text" name="search" value=""/><input type="submit" value="Go!"></p>
</form>    
</body>
</html>

Thanks again.

Forgive the bad format above.


If you don't understand my english, please tell me.

here is my php code:

<?php
    // load the XML file
    $xml = simplexml_load_file("store.xml");
    // store the header text in a variable that can be appended to below
    $subheader[1] = "Pizza";
    $subheader[2] = "Special Dinners";
    $subheader[3] = "Sider Order";
    $subheader[4] = "Salads";
    $subheader[5] = "Homemade Calzones";
    $subheader[6] = "Wraps $4.95";
    $subheader[7] = "Grinders";
     
    // determine whether we need to search or show all of the store's items
    if(isset($_POST["search"]) && !empty($_POST["search"]))
    {
        // use the search term supplied by the user to create an XPath query
        $search = $_POST["search"];
        $results = $xml->xpath("//item[contains(name, '$search')]");

        // append the search term to the header element so we can show the user what they searched for
       //[B]here i want to do one loop which related to the search form but i don't know how to do it[/B]
        for($i=1;$i<=7;$i+=1)
     {
        $subheader[i] = $subheader[$i] . " - Search '{$search}'";
     }
    }
    else
    {
        // no search term was provided, so we'll show all of the store's items
       //[B]here i also want to do one loop which the results could have different according to the "i" and related to the results[/B]
        for($i=1;$i<=7;$i+=1)
        {
        $results[i] = $xml->items->catalog;
        }
    }
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
         <h1><?php print($subheader[1]);?></h1>//[B]here i want to show different header name according to the different subheader name which i defined on my top code[/B]
        <img src="img/pizza.png" border="0"/>
        <div>
        <table border="0" cellpadding="4px">
         <tr>
         <th width="96">Name</th>
         <th width="96">Description</th>
         <th width="72">Price(L)</th>
         <th width="74">Price(S)</th>
         <th width="173">Add to Cart</th>
         </tr>
         <?php
          foreach($results[1] as $item)//[B]same thing here, i want to show different results[/B]
         {
          print("<tr><th>{$item->name}</th><th>{$item->description}</th><th>{$item->size->large->price}</th><th>{$item->size->small->price}</th><th><a href='add.php?id={$item['id']}'>add to cart</a></th></tr>");
                }
          ?>
        </table>
<form action="index.php" method="post">
<p>Search food names: <input type="text" name="search" value=""/><input type="submit" value="Go!"></p>
</form>    
</body>
</html>

Thanks again.

...
here is my php code, pleas help me check it and tell me how to make it works.
...

What seems to be the problem. Do errors get reported or does it not function properly. If so how is it not functioning properly or what errors are reported?

<form action="index.php" name="catalogFormName" id="catalogFormId" method=GET name=chcat >
               
 <select name="catalogName" id="catalogId" onChange="getCatalogDetails(this)">
 <option value=0>All</option>
 <option value="2">Pizza</option>  
 <option value="4">Special Dinners</option>  
 <option value=5>Side Orders</option>  
 <option value=6>Salads</option> 
 <option value=7>Spaghetti or Ziti</option> 
 <option value=8>Home made Lasagna Ravioli or Manicotti</option>
 <option value=9>Homemade Galzones</option>
 <option value=10>Wraps</option>
 <option value=10>Grinders</option>
</select>

<?php
   @extract($_GET);	
   if(@isset($catalogName)) {
	switch($catalogName) {
	   case 0:
		$display = "All category Details";
		break;	
	   case 2:
		$display = "Display Pizza Details";
		break;	
	   default:
		$display = "SELECT catalog.......";
	       break;	
	}
   } 	
   print "<div>$display</div>";	
?>

</form>

<script>
function getCatalogDetails(catalogControl) {

   if(catalogControl.value != 0)	
	document.catalogFormName.submit();
}
</script>

-- save this file as index.php and try it out.....

-- save this file as index.php and try it out.....

I just saved it as index.php and ran it on xampp and it runs accordingly to what the script design appears to be. So could you please express your scripting problem?

<script type="text/javascript">

function getCatalogDetails(catalogControl) {

   if(catalogControl.value != 0)	
	document.catalogFormName.submit();
}
</script>
<form action="forum1.php" name="catalogFormName" id="catalogFormId" method=GET name=chcat >
               
 <select name="catalogName" id="catalogId" onChange="getCatalogDetails(this)">
 <option value=0>All</option>
 <option value="2">Pizza</option>  
 <option value="4">Special Dinners</option>  
 <option value=5>Side Orders</option>  
 <option value=6>Salads</option> 
 <option value=7>Spaghetti or Ziti</option> 
 <option value=8>Home made Lasagna Ravioli or Manicotti</option>
 <option value=9>Homemade Galzones</option>
 <option value=10>Wraps</option>
 <option value=10>Grinders</option>
</select>

<?php
   @extract($_GET);	
   if(@isset($catalogName)) {
   	$display = loadCatalogDetails($catalogName);
   } 	
   print "<div>$display</div>";	


	function loadCatalogDetails($catalogItem) {
	
	$xml = simplexml_load_file("store.xml");
	
	// store the header text in a variable that can be appended to below
	
	$subheader[1] = "Pizza";
	
	$subheader[2] = "Special Dinners";
	
	$subheader[3] = "Sider Order";
	
	$subheader[4] = "Salads";
	
	$subheader[5] = "Homemade Calzones";
	
	$subheader[6] = "Wraps $4.95";
	
	$subheader[7] = "Grinders";
	

	
	// determine whether we need to search or show all of the store's items
	
	if(isset($catalogItem) && !empty($catalogItem))
	
	{
	
	// use the search term supplied by the user to create an XPath query
	
	$search = $catalogItem;
	
	$results = $xml->xpath("//item[contains(name, '$search')]");
	
	 
	
	// append the search term to the header element so we can show the user what they searched for
	
	//[b]here i want to do one loop which related to the search form but i don't know how to do it[/b]
	
	for($i=1;$i<=7;$i+=1)
	{
	
	$subheader[$i] = $subheader[$i] . " - Search '{$search}'";
	
	}
	
	}
	
	else
	
	{
	
	// no search term was provided, so we'll show all of the store's items
	
	//[b]here i also want to do one loop which the results could have different according to the "i" and related to the results[/b]
	
	for($i=1;$i<=7;$i+=1)
	
	{
	
	$results[i] = $xml->items->catalog;
	
	}
	
	}
	$html = "<h1><?php print($subheader[1]);?></h1>";//[b]here i want to show different header name according to the different subheader name which i defined on my top code[/b]
	
	$html .= '<img src="img/pizza.png" border="0"/>';
	
	$html .= '<div>
	<table border="1" cellpadding="4px">
	
	<tr>
	
	<th width="96">Name</th>
	
	<th width="96">Description</th>
	
	<th width="72">Price(L)</th>
	
	<th width="74">Price(S)</th>
	
	<th width="173">Add to Cart</th>
	
	</tr>';
	
	
	foreach($results[1] as $item)
	
	{
	
	  $html .= "<tr><th>{$item->name}</th><th>{$item->description}</th><th>{$item->size->large->price}</th><th>{$item->size->small->price}</th><th><a href='add.php?id={$item['id']}'>add to cart</a></th></tr>";
	
	}
	$html .= "</table></div>";
	 return $html;	
	}
	/**/
?>



</form>
commented: Almost 11 months and you still don't use [code] tags ? It is really difficult for others to read your code. -2

Could you attach the xml file to your next post so that I could check the code and clean up the code a bit (and add those extra features).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.