Jump to content

Help with building array to dynamically select links-(ignore previous post)


Lassie

Recommended Posts

I am trying to adapt an ajax script to allow content to be dynamically selected and diplayed.

The contant is held in a db as refences to the page locations ie field p1= chapters.html

and the ref field holds the folder name.

I need to create an array of the page references and pass this to a javascript var.

I cant figure how to cycle through the pages array and make a valid location reference.

Can anyone help please.

The relevant code is


//get product_id
$product_id=13;
//connect to db
$connection=db_connect();

echo "<script type='text/javascript'>\n"; //Dynamically output JavaScript opening tag
echo "var mysettings={}\n"; //Dynamically output javascript variable

$pageids=mysql_query("select p1,p2,p3 from ajax WHERE product_id='$product_id'"); 
$idarray=array();
while ($theid=mysql_fetch_array($pageids)){
  array_push($idarray, "'http://localhost/folder/?id=" . $theid[id] . "'");//create folder and page locations 
}
echo "mysettings.page=[" . implode(",", $idarray) . "]\n";
echo "mysettings.selectedpage=0\n";
echo "</script>\n"; //Dynamically output JavaScript closing tag

 

 

 

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.