[MAJOR PROBLEM renamed] load database data into flash with php

Hello,
I am building a flash site for a friend and I have setup a PHPCatalog for his sales made by http://www.siliconsys.com/content/applications/phpcatalog/

the problem is Im building his whole site in flash right now and need to call to the phpcatalog scripting and input it into my swf… I have searched and read many posts on doing this but this is kinda tricky because of how complex the phpcatalog is. What I need to figure out is how to call the different peices of the php… if you want to see what it looks like goto www.customwheelsales.com/phpcatalog as you will see it is running on a MYSQL database to access all of the variables… which makes me think is there anyway to make this phpcatalog into a html file and load it into flash?

I really am above my head on this one mainly because I dont really know that much about phpscripting when it comes to dealing with flash interaction so maybe someone has some experience?

ok,
I have a flash video that I have created that I need to load info from a phpcatalog that I have created. This is a catalog that I d/led that is all php driven and is completly setup and working in html but I need to load it into my video. I have been following multiple tutorials but I have still not been able to intergrate this properly. I understand that I need to use loadvars within doing this but I am at a loss as to how Im actually supposed to code it to work! WARNING : this is going to be alot to read

this is the php server side script that I have

  <?php
/*
** $Id: index.php,v 1.3 2003/09/16 20:31:48 damonp Exp $
**
** Copyright (C) 2002 siliconsys.com <dev@siliconsys.com>
** See LICENSE file in root directory of this installation for
** licensing information.
*/
 require_once('./include/config.inc');
  $cat_id    = passed_var('cat_id', 'get', 'integer');
  $catalog_id  = passed_var('catalog_id', 'both', 'integer');
 $category = isset($sel_category) ? $sel_category:'%';
 $_SESSION['category'] = $category;
 $d_category = $category == '%' ? 'All Categories':$category;
 $cat_id = $sel_category == '' ? $cat_id:$sel_category;
 if(isset($cat_id)) $cat = get_category_name($cat_id);
 set_default($CFG->tmpl_header, $CFG->libdir . '/template/header.inc');
 set_default($CFG->tmpl_footer, $CFG->libdir . '/template/footer.inc');
 set_default($CFG->tmpl_prev_next, $CFG->libdir . '/template/tmpl.prev_next.inc');
 set_default($CFG->tmpl_box, 'tmpl.box.inc');
 set_default($CFG->tmpl_detail, 'tmpl.detail.inc');
 set_default($CFG->tmpl_image_view, 'tmpl.image_view.inc');
 set_default($CFG->tmpl_list, 'tmpl.list.inc');
 set_default($CFG->tmpl_page, 'tmpl.page.inc');
 $T->set_file('page', $CFG->tmpl_page);
 $CFG->color_tbl1 = '#cccccc';
 $CFG->color_tbl2 = '#eeeeee';
 $T->set_var(array(
		  'me'   => me(),
		'base'  => $CFG->wwwroot,
		'currency' => $_SESSION['config']['currency_sym'],
		'category' => $d_category,
		'select_category' => select_category($cat_id, true)));
 if($id != '' && $function == '') $function = 'detail';
 elseif(($cat_id != '' || $start != '' || $query != '') && $function == '') $function = 'list';
 if($_SESSION['config']['catalog_name'] == '') throw_error('internal configuration error, rebuild config table');
/*****************************
 * main
 ****************************/
 include($CFG->tmpl_header);
 switch($function) {
/****************
 * detail
 ***************/
  case('detail'):
   $CFG->dbh->Query("SELECT phpc.*, cat.category_name AS product_category
		 FROM $CFG->phpc_table AS phpc
		 LEFT JOIN phpcatalog_categories AS cat USING (category_id)
		 WHERE product_id = '$id'");
   if($CFG->dbh->RowCount > 0) {
	$T->set_file('content', $CFG->tmpl_detail);
	$r = $CFG->dbh->FetchObject('', 1);
	format_product_row($T, $r, $function);
	$T->set_var(array(
		  'bottom' => "<tr height=\"70\"><td colspan=\"2\" align=\"center\" valign=\"bottom\"><a href=\"javascript:history.go(-1)\" class=\"bold\">back</a></td></tr>
",
		  'select_category' => select_category($r->category_id, true)));
	stats_log_hit($id);
   } else {
	$T->set_var('content', 'Item not found');
   }
   break;
/****************
 * image_view
 ***************/
  case('image_view'):
   $T->set_file('content', $CFG->tmpl_image_view);
   $T->set_var('bottom', "<tr height=\"70\"><td colspan=\"2\" align=\"center\" valign=\"bottom\"><a href=\"javascript:history.go(-1)\" class=\"bold\">back</a></td></tr>
");
   $CFG->dbh->Query("SELECT image_path
		 FROM $CFG->phpc_table
		 WHERE product_id = '$id'");
   $r = $CFG->dbh->FetchObject();
   $T->set_var('image_path', $r->image_path);
   break;
/****************
 * list
 ***************/
  case('list'):
   $T->set_file('content', $CFG->tmpl_list);
   catalog_list($query, $start, $cat_id);
   if($show_msg) {
	$T->set_var('msg', $msg);
	$T->parse('msg', 'msg');
   }
   $T->set_var('pagetitle', $d_category);
   break;
/****************
 * index
 ***************/
  default:
   $T->set_file('page', $CFG->tmpl_page);
   $T->set_file('content', 'tmpl.index.inc');
   $T->set_var('pagetitle', '');
   break;
 }
 push_template();
 include($CFG->tmpl_footer);
/*****************************
 * functions
 ****************************/
 function catalog_list($query, $start, $cat_id) {
  global $CFG, $T;
  set_default($start, 0);
  $num_items_page = $_SESSION['config']['num_items_page'] != '' ? $_SESSION['config']['num_items_page']:10;
  $db_cat_id = $cat_id == '' ? '%':$cat_id;
  if($query != '') {
   $msg = "<tr><td colspan=\"6\" height=\"30\" valign=\"top\">Searching for &lt;<b>$query</b>&gt; returned ";
   $search_string = '%' . $query . '%';
   $like   = $CFG->dbh->Ident() == "DBI_PG" ? "ILIKE":"LIKE";
   $db_query  = "AND (product_name $like '$search_string'";
   $db_query  .= " OR product_sku $like '$search_string'";
   $db_query  .= " OR product_desc $like '$search_string')";
   $show_msg  = true;
   $db_limit  = '';
  } else {
   $db_limit = ($CFG->dbh->Ident() == "DBI_PG") ? $num_items_page. ", $start":"$start, " . $num_items_page;
   $db_limit = "LIMIT $db_limit";
   $db_query = '';
  }
  $CFG->dbh->Query("SELECT count(product_id) as num_rows
		FROM $CFG->phpc_table as phpc
		LEFT JOIN phpcatalog_categories as cat USING(category_id)
		WHERE cat.catalog_id = $CFG->catalog_id
		 AND phpc.category_id LIKE '$db_cat_id'
		 $db_query
		ORDER BY product_name ASC",
		__FILE__, __LINE__);
  $r = $CFG->dbh->FetchObject('', 1);
  $num_items = $r->num_rows;
  set_default_null($num_items, 0);
  $num_pages = ceil($num_items / $num_items_page);
  if(isset($msg)) {
   $product = $num_items > 1 ? 'products':'product';
   $msg .= "$num_items $product.</td></tr>";
  }
  $T->set_block('content', 'row', 'rows');
  if($num_items > 0) {
   $CFG->dbh->Query("SELECT *
		 FROM $CFG->phpc_table as phpc
		 LEFT JOIN phpcatalog_categories as cat USING(category_id)
		 WHERE cat.catalog_id = $CFG->catalog_id
		  AND phpc.category_id LIKE '$db_cat_id'
		  $db_query
		 ORDER BY product_name ASC
		 $db_limit",
		 __FILE__, __LINE__);
   while($r = $CFG->dbh->FetchObject()) {
	format_product_row($T, $r, 'list');
	$T->parse('rows', 'row', true);
   }
   if(isset($msg))
	$T->set_var('search_msg', $msg);
   if($num_items > $num_items_page && $query == '')
	show_prev_next($num_items, $num_pages, $start, $db_cat_id);
  } else {
   $T->set_var('rows', '<tr><td align="center">No Products Found</td></tr>');
   $T->implodeBlock('row');
  }
 }

 function show_prev_next($num_items, $num_pages, $start, $category) {
  global $CFG, $T;
  $T->set_file('bottom', $CFG->tmpl_prev_next);
  $category = ($category == '' || $category == '%') ? '':"cat_id=$category&";
  $num_items_page = $_SESSION['config']['num_items_page'] != '' ? $_SESSION['config']['num_items_page']:10;
  if($start > 0) {
   $prev = "<a href=\"./?".$category."start=" . ($start - $num_items_page) . "\">&lt;prev</a> | ";
  } else $prev = "&lt;prev | ";
  $i = 0;
  while($i < $num_pages) {
   $page = $i * $num_items_page;
   $i++;
   if($page != $start) {
	$pages .= "<a href=\"./?".$category."start=$page\">$i</a> | 
";
   } else $pages .= "<b>$i</b> | 
";
  }
  if($start < (($num_pages - 1) * $num_items_page)) {
   $next .= "<a href=\"./?".$category."start=" . ($start + $num_items_page) . "\">next&gt;</a>";
  } else $next .= "next&gt;";
  $T->set_var(array(
	   'prev' => $prev,
	   'next' => $next,
	   'pages'=> $pages));
  array_push($CFG->page_arr, 'bottom');
 }
?>

Now my question is I want it to showup just as it does at
www.customwheelsales.com/phpcatalog/

How do I do it? I have been trying for 2 days but am really stuck and could REALLY use some help here…

what about if you was to output the php to xml and then load that into flash. Check out the tutorials http://www.kirupa.com/web/mysql_xml_php.htm

Is the data coming from a database (I guess)?
Then you’ll need to rewrite the data retrieval PHP script to get the data, and send them (raw) to Flash, and handle all the display in Flash, either using the datagrid or a custom interface…
Check out this BEST site with source codes for MX '04 : http://philflash.inway.fr/

As it’s a french site, **here’s a direct link ** to an example you may want to look at, I found the code quite easy to customize…
Hope this helps. (and don’t ask me to write the PHP for you :slight_smile: )

cool thanks for responding. Im checking it out right now… Heres a question on top of what I already asked… has anyone heard of PHPObject? I guess it is a opensource flash remoting thing with a gateway… Im at a loss as to how it works but maybe this might help me?
[color=#800080]http://ghostwire.com/resources/phpobject/[/color]

see I think my biggest problem is I dont really understand the PHP that is required to be the go between for the flash to work correctly… If someone might be able to help me write a sample php file that will just pull up 1 complete table then Im sure I could do the rest I just need an example… anyone up for helping me out? I really want to learn how to do this

ok Ive followed some tutorials but still no luck!!! Im completly confused and have no idea how Im gonna pull this off!! I tried the mysql_xml_php.htm tut but It still isnt working out for me… I set it up and saw some info in xml but it wasnt what I was wanting to see ( I dont know syntax of mysql) but what I wanted to do to test was to try to pull a whole catagory from the database and just project the results… just to see if its working but couldnt even do that… And another question I have is once I do get the info into xml how do I load it into flash? I understand that this is kinda a tuff question being Im a beginner trying to do some pretty advanced things that I dont fully understand but the way I see it this is the only way Ill learn is to jump right into the line of fire (not to mention I have to do this for a customer so I have no choice).

So my main 2 questions are 1.)how do I write a PHP script to output things in the database into XML and 2.)HOW DO I INPUT THEM INTO FLASH?

Heres the PHP code that I used from the tut to turn the tables in SQL to xml… Can someone help me edit this to pull a specific catagory from the MYSQL database so I can see this in action and try to make a little more sense of it??

heres the PHP code

 <?php 

header("Content-type: text/xml"); 

$host = "localhost"; 
$user = "root"; 
$pass = ""; 
$database = "test"; 

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 

$query = "SELECT * FROM blog ORDER BY date DESC"; 
$resultID = mysql_query($query, $linkID) or die("Data not found."); 

$xml_output = "<?xml version=\"1.0\"?>
"; 
$xml_output .= "<entries>
"; 

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ 
	$row = mysql_fetch_assoc($resultID); 
	$xml_output .= "	<entry>
"; 
	$xml_output .= "		<date>" . $row['date'] . "</date>
"; 
		// Escaping illegal characters 
		$row['text'] = str_replace("&", "&", $row['text']); 
		$row['text'] = str_replace("<", "<", $row['text']); 
		$row['text'] = str_replace(">", "&gt;", $row['text']); 
		$row['text'] = str_replace("\"", "&quot;", $row['text']); 
	$xml_output .= "		<text>" . $row['text'] . "</text>
"; 
	$xml_output .= "	</entry>
"; 
} 

$xml_output .= "</entries>"; 

echo $xml_output; 

?>  

(note in this example hes talking about a blog and the end of the script (the $row[‘text’] thing) was really confusing because it didnt pertain to what I was doing and everytime I tried to munipulate it it would cause the script to error out…

help!?

my small 2 cents… you can’t use your php script that’s driving the HTML… you’ll need to custom format a new script to handle the variables.

this is a very basic php script that retrieves 3 variables, one $parent which is a number and two $pagetitle and $page which are HTML text from a mySQL DB:

<?php

//	include configurations (db connection..)
include('../includes/config.php');
//	query for page
	$result = mysql_query('SELECT * FROM tbl_pg WHERE pgID="'.$page .'"',$dbcnx);

// if page was returned, output it
if(mysql_num_rows($result)>0){
// $data is an array of every field in a row
$data = mysql_fetch_array($result);
// because the output is mySQL & HTML formatted yah got to pre-process it for flash to understand
$str = $data[‘pg_body_text_en’];
$str = str_replace(" “,”",$str);
$str = str_replace("\r","",$str);
$str = stripslashes($str);
$str = urlencode($str);
// again more string (text) processing
$title = $data[‘pg_title_en’];
$title = str_replace(" “,”",$title);
$title = str_replace("\r","",$title);
$title = stripslashes($title);
$title = urlencode($title);
// and the output, dataSent being a control to let me know in flash if everything went well on the php side
echo ‘&dataSent=success’;
echo ‘&parent=’.$data[‘prtID’];
echo ‘&pagetitle=’.$title;
echo ‘&page=’.$str; }
?>

on the other side the Flash would look something like this:

sendData = new LoadVars();
//where myPageVariable is the page requested
sendData.page = this.myPageVariable;
this.chapterText.htmlText = “Loading”;
sendData.onLoad = function() {
if (sendData.dataSent == “success”) {
// I’m only using two of the variables requested here
this.chapterHeading.htmlText = sendData.pagetitle;
this.chapterText.htmlText = sendData.page;
} else {
this.chapterHeading.htmlText = “Data Missing!”;
}
};
sendData.sendAndLoad(“flashPage2.php”, sendData, “GET”);

ok cool
I think I kinda understand the code that youve posted… Is most of this something that I can plug and play? Im trying to make sense of it… your php script that you sent me is doing the same thing that the original was doing - without the html right? so I dont need to edit the php? Also there was a couple of errors in your php script that I corrected (the only one was ./include/config.inc instead of what you had and also could you go into a little bit more detail on setting up the flash side of it? the mypagevariable part is kinda confusing me … How do you think I should go about actually showing the data its recieving? Can I actually make it show up like it does in the regular catalog? Im sorry for my incompitence with this but like I said Im kinda new to this so Im trying to make heads and tails of it so I can learn :wink:

also here is what config.inc (the file that houses the connection info and etc…) this is the version that I havent filled in yet but youll get the gist.

 <?php
/*
** $Id: config.inc,v 1.6 2003/09/16 21:24:53 damonp Exp $
**
** Copyright (C) 2002 siliconsys.com <[email="dev@siliconsys.com"]dev@siliconsys.com[/email]>
** See LICENSE file in root directory of this installation for
** licensing information.
*/
 /* define a generic object */
 class object {};
 /* setup the configuration object */
 $CFG = new object;
/***********************************
** begin configuration parameters
***********************************/
 $CFG->dbtype  = 'mysql';   // database server type (mysql, ifx, oci, pg)
 $CFG->dbhost  = 'localhost';   // hostname of db server
 $CFG->dbname  = 'PHPCatalog';  // database name
 $CFG->dbuser  = '';		// database user authorized for this database
 $CFG->dbpass  = '';		// password for this user
 $CFG->wwwroot  = 'http://yourdomain.com/url/path/to/PHPCatalog';  // without ending slash, url path to PHPCatalog
 $CFG->dirroot  = '/dir/path/to/PHPCatalog';		 // full directory path to PHPCatalog; windows systems use the form 'c:/path/to/PHPCatalog'  (with forward slashes '/' instead of backslashes '\')
 $CFG->libdir  = $CFG->dirroot . '/include';
 $CFG->imagedir  = $CFG->dirroot . '/image';
 $CFG->admin_items_page = 20;
 /* catalog interface display variables */
 $CFG->max_img_size = '500000'; // in kb
 $CFG->max_price  = '100000';
 define('DEBUG', true);				// uncomment this line for debugging
 if(defined('DEBUG')) error_reporting(E_ALL & ~E_NOTICE);
 else {
  error_reporting(0); 		   // uncomment this line and
  //error_reporting(E_ALL & ~E_NOTICE);	  // comment this line if you are having problems
 }
/***********************************
** end configuration parameters
** do not edit anything below this
***********************************/
 $CFG->msg   = array();
 $CFG->page_arr  = array();
 $CFG->appversion = '2.6.12';
 $CFG->prod_dir  = $CFG->imagedir . '/products/';
 define('T_STAMP', time());
 define('SHORT_TIME', "m/d/y G:i");
 define('LONG_TIME', "j M Y g:i:s T");
 /* load up standard libraries */
 require_once($CFG->libdir . '/class/class.Template.inc');
 require_once($CFG->libdir . '/stdlib.inc');
 require_once($CFG->libdir . '/phpcatalog.inc');
 /* connect to the database */
 $CFG->dbh = dbi_conn($CFG->dbtype, $CFG->dbname, defined('DEBUG'));
 /* initialize template */
 $T = new Template($CFG->libdir . '/template', 'remove');
 /* start session, register vars */
 session_start();
 if(get_cfg_var('register_globals')) session_register('SESSION');
  $form = add_all_slashes($_POST);
 $action   = passed_var('action');
 $function  = passed_var('function');
 $id 	= passed_var('id', 'both', 'integer');
 $method   = passed_var('method');
 $mod_name   = passed_var('mod_name');
 $query    = passed_var('query');
 $sel_category  = passed_var('sel_category', 'get');
 $sort	= passed_var('sort', 'get');
 $start   = passed_var('start', 'get', 'integer');

 if(! defined('NO_PROCESS')) {
  set_default_null($start, 0);
  set_default_null($catalog_id, 1);
  $CFG->catalog_id = $catalog_id;
  set_default($_SESSION['SESSION']['category'], '%');
  $_SESSION['SESSION']['category'] = isset($form['sel_category']) ? $form['sel_category']:$_SESSION['SESSION']['category'];
  get_config($catalog_id, defined('ADMIN'));
 }
 $CFG->phpc_table  = 'phpc_' . $_SESSION['config']['catalog_name'];
 if(defined('ADMIN')) {
  require_once($CFG->libdir . '/phpcatalog_admin.inc');
 }
?>