Jump to content

Using XML or array instead of mysql database


etrader

Recommended Posts

There is a "PHP ajax cascading dropdown using MySql" at codestips.com/php-ajax-cascading-dropdown-using-mysql/

 

I want to use this technique but with a XML or array file instead of mysql database, but my knowledge about mysql is very low. How I can modify this code to catch the categories and products from an array, instead of mysql database?

 $connect=mysql_connect($server, $db_user, $db_pass)
      or die ("Mysql connecting error"); 
echo '<table align="center"><tr><td><center><form method="post" action="">Category:<select name="category" onChange="CategoryGrab('."'".'ajaxcalling.php?idCat='."'".'+this.value);">';
$result = mysql_db_query($database, "SELECT * FROM Categories");
$nr=0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$nr++;
echo "<option value=".'"'.$row['ID'].'" >'.$row['Name']."</option>";
}
echo '</select>'."\n";
echo '<div id="details">Details:<select name="details" width="100" >';
$result = mysql_db_query($database, "SELECT * FROM CategoriesDetails WHERE CategoryID=1");
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
 echo "<option value=".$row['ID'].">".$row['Name']."</option>";
}
echo '</select></div>';
echo '</form></td></tr></table>';
mysql_close($connect);

 

ajaxcalling.php is

include("config.php");
$ID=$_REQUEST['idCat'];
$connect=mysql_connect($server, $db_user, $db_pass);
echo 'Details:<select name="details" width="100">';
$result = mysql_db_query($database, "SELECT * FROM CategoriesDetails WHERE CategoryID=".$ID);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
 echo "<option value=".$row['ID'].">".$row['Name']."</option>";
}
echo '</select>';
mysql_close($connect);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.