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

 

 

 

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.