Jump to content

turpentyne

Members
  • Posts

    220
  • Joined

  • Last visited

Everything posted by turpentyne

  1. Hi... A scenario: A client has their own database. I don't know what what kind of database just yet. Waiting to hear back. But they want put a csv file or some kind of mysql dump file outside of their firewall every friday for us to use to populate a mysql database on a different server where their website is hosted - where we are building their website. Can this be done feasibly? How would we do this?
  2. I have a database generated list of images and hidden divs. When the user clicks on an image, the hidden div with that database-generated id appears. Simple enough. But I can't figure out how to make that div disappear when they click elsewhere. I've got this, so far, but the Function to hide the div doesn't seem to be doing anything. <script type="text/javascript"> var shownDiv; var parDiv; function showdiv(id,el){ document.getElementById(id).style.display = "block"; shownDiv=id; parDiv=el.id; } function hideDiv(e){ var target=e?e.target:event.srcElement; if(shownDiv&&target.id!=parDiv){ document.getElementById(shownDiv).style.display = "none"; } } document.onclick=hideDiv; </script> <!-- php code is here, and it generates each image in code like this. The first line shows where the showdiv is activated --> <a class'hide' href="#%4\$s" target="_self" onclick="showdiv('%4\$s',this);" ><img src="%3\$s" style="border: solid 0px #000000;max-width:150px;"></a></div> <!-- this is the hidden div --> <div id="%4\$s" style="display:none;width:700px;z-index:109;height:0px;overflow:visible;color:#000;overflow:visible;scrollbar:none;"> data here: %4\$s </div>
  3. I have a catch-22. I built a simple page that pulls several items from the database, and lists them. Now I need to add a "pop-up" div that shows detailed information for an item, if they click on it. I have it working right now, but instead of reloading the page with the div showing and done, it somehow shows the div with the information from the database, then reloads the page without it showing. I'm not quite sure how I can send the info to the javascript <!-- the simple javascript at top of page --> <script type="text/javascript"> function showdiv(id){ document.getElementById(id).style.display = "block"; } </script> <?php /* other code that pulls the initial information here */ /* including... this, where the _get id is passed, and includes the call to the javascript function that shows */ $ExpandImageTemplate = <<<OutHTML <div style='width:70px;padding:15px 15px 5px 10px;float:left;width:150px; min-height:140px;overflow:auto;'> %4\$s <br> <a class'hide' href="http://www.mcmillanusa.com/mcmillan-rifles-alias-accessories.php?id=%4\$s" target="_self" onclick="showdiv('pop-div');" ><img src="%3\$s" style="border: solid 0px #000000;max-width:150px;"></a></div> OutHTML; /* taking some query results to create the above - irrelevant to the question */ $Output .= sprintf ($ExpandImageTemplate, htmlspecialchars ($row['comp_cat_name']),htmlspecialchars ($row['folder_path']),htmlspecialchars ($row['image_filepath']),htmlspecialchars ($row['component_name'])); ?> <!-- then, further down on the page, here's the code that I was trying to write to create the pop-up div I couldn't put it above because it's screwing up a database query for other unrelated stuff --> <?php /* still need to add security for the _get statement, but on page reload, this variable $which_one is set */ $which_one = ($_GET["id"]); $result = mysql_query("SELECT * FROM `tbl_components` WHERE `component_name` = '$which_one'") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo "<center><div id=\"pop-div\" style=\"display:none;width:700px;z-index:99;height:0px;overflow:visible;color:#000;\"><p style=\"position:relative;left:-48px;background-image: url('../../images/alias/alias-pop-bg.png');width:605px;height:400px;padding:10px;\"><b><span style=\"width:200px;\"><font style=\"color:#fff;\">".$row['component_name']."</font></b><br><br>"; echo "<font style=\"color:#fff;\">".$row['component_description']."</font>>/span><br><br>"; echo "<img src='".$row['image_filepath']."'><br></p></div></center></div>"; ?>
  4. dear lord! False alarm! It helps if I include that field in my query!!! problem solved!
  5. I tried your suggestion and still get the same thing. That row in MySQL is just: 2012-09-02 00:00:00 a datetime field.
  6. I'm trying to figure out how to get this to generate the date field pulled from a query that pulls a datetime field called "date". But It's just giving me some default: 12/31/69 7:00 PM $Output .= sprintf ($ExpandImageTemplate, htmlspecialchars ($row['title']),htmlspecialchars ($row['content']),htmlspecialchars ($row['img_url_small']),htmlspecialchars ($row['img_url_large']),htmlspecialchars ($row['deck']),date("m/d/y g:i A",($row['date'])));
  7. No worries, on the delay! I spent a little time last night looking into how to set up classes and functions, so this looks like it's working off of what I was researching. Thanks!
  8. yeah... I was just posting a new forum entry to get people's take on the general flow of how they'd do this so I can.. well, start over, I think.
  9. Ok... I'm starting from scratch. I know there's an easier way to do what I want to do, but I dove in head-first with an empty pool of knowledge on this apparently. So, starting from the beginning, how would I go about doing this. I think it's probably easier than I've made it. Everything about my current code is broken/ inneficent. I want to build a page where t customer builds their own product from different components. After they choose option A1 or A2, the page reloads, or a div shows that lists the B options available to what they picked, after that, they get the C choice they made. And so on. As they make each choice in the form, I also want to give them a running list of their choices to the side: I.E. "you have chosen: A: 2, B: 5, C: 1, etc. I have three main tables that they're working from: 1. component_categories: the different categories of items - essentially A, B, C, D as shown above. 2. Components: the 1 or 2 or 3, etcetera. 3. I also have a many-to-many link table, components_to_components, that lists the component id, and then the compatible component id. for example: A1 is compatible with B2 A1 is compatible with B4 A2 is compatible with B2 A2 is compatible with B3 B2 is compatible with C3 and so on. A loose outline, anything would help. I can post what I have right now, but it's such a confusing mess and I'd really like to start over from scratch with the simplest, most elegant solution, so I know how to do this for the future. How would you build such a section?
  10. Welll, I've been avoiding this, because I know it's frightening to look at my beginner's mess, but here's the whole code. I have a table of all components, a table of all categories, and a table that shows which components are compatable. The page pulls 2 options. They choose one or the other, and the page reloads after php queries the database and selects the new information to show. The whole thing is a mess, but I've got it mostly working. I just can't get the 'rolling' results of what they've chosen to work. <?php session_start(); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ if(isset($_POST['reset'])){ // set to empty if they've pressed the reset button. unset($_SESSION['options_picked']); unset( $_POST['chosen'] ); $results_done = ''; $page = $_SERVER['http://www.website.com/build-your-own.php']; $sec = "1"; } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ if(!isset($_SESSION['options_picked'])){ // set my empty session at the beginning of everything - This is the array that I use to fill the results variable. $_SESSION['options_picked'] = array(); } if (!isset($_POST['chosen'])) { // set my $var at the beginning of everything $var = "4"; $query_text = "SELECT tbl_component_categories.ID, tbl_component_categories.folder_path, tbl_component_categories.comp_cat_name, tbl_components.component_name, tbl_components.image_filepath, tbl_components.component_category, tbl_components.ID AS comp_id FROM tbl_components JOIN tbl_component_categories ON tbl_components.component_category = tbl_component_categories.ID AND tbl_component_categories.ID = $var ORDER BY tbl_components.component_category"; // $_SESSION['options_picked'] = array(); } elseif(isset($_POST['chosen'])) { $choicetest = $_POST['chosen']; // echo "and it is ".$choicetest; // print_r($_SESSION['options_picked']); // for testing . delete at completion. // below section is hard coded for the moment. // maybe I query the database for categories and category id, then I can loop to create the below statements // so it would be like: if post == 'row[x] { var = row[y]; $var = ""; if((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Buttstocks')){ $var = "1"; } else if((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Accessory_Rail_Mounts')){ $var = "11"; } else if((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Caliber')){ $var = "2"; } else if((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Barrel_length')){ $var = "10"; } else if((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Suppressors')){ $var = "9"; } $query_text = "SELECT DISTINCT tbl_component_to_component.component_ID, tbl_component_to_component.compatible_component_ID, tbl_component_categories.ID, tbl_component_categories.folder_path, tbl_component_categories.comp_cat_name, tbl_components.component_name, tbl_components.image_filepath, tbl_components.component_category, tbl_components.ID AS comp_id FROM tbl_components JOIN tbl_component_categories ON tbl_components.component_category = tbl_component_categories.ID AND tbl_component_categories.ID = $var JOIN tbl_component_to_component ON $choicetest = tbl_component_to_component.component_ID AND tbl_components.ID = tbl_component_to_component.compatible_component_ID"; } // echo $query_text; array_push($_SESSION['options_picked'],$choicetest); // need to add in category. // choice test = e.g. tactical buttstock include("database connection link"); $query = $query_text; $result = mysql_query($query) or die(mysql_error()); // create templates $ExpandTemplate = <<<OutHTML <img style="position:relative;top:-2px;" src="images/structural/red-plus.gif" /> %1\$s <!--</a>--> <br><form name="aliasbuilder" id="aliasbuilder" action="" method="post"> OutHTML; $ExpandImageTemplate = <<<OutHTML <button type="submit" name="chosen" id="chosen" value="%5\$s"> <img src="%3\$s" width="147" height="34" alt="image to come" title="choice" /> </button> <input type="hidden" name="what_category" value="%2\$s"> <!-- this hidden field is what I can use to determine what category, I compare it to --> OutHTML; $Output = ''; //output section and sprintf while ($row = mysql_fetch_assoc ($result)) { if ($category != $row['component_category']) { $category = $row['component_category']; if (!$firstime) { $Output .= '<br><br>'; } else { $firstime = true; } $Output .= sprintf ($ExpandTemplate, htmlspecialchars ($row['comp_cat_name']), htmlspecialchars ($row['folder_path'])); } $Output .= sprintf ($ExpandImageTemplate, htmlspecialchars ($row['comp_cat_name']),htmlspecialchars ($row['folder_path']),htmlspecialchars ($row['image_filepath']),htmlspecialchars ($row['component_name']),htmlspecialchars ($row['comp_id'])); // when I get a chance, I need to figure out how to escape the /s in the image_filepath in code line above. It wasn't working when it was written: htmlspecialchars (rawurlencode($row['image_filepath'])). it just put %s } ?> <script language="javascript">AC_FL_RunContent = 0;</script> <script src="js/AC_RunActiveContent.js" language="javascript"></script> <link href="includes/mcm.css" rel="stylesheet" type="text/css" /> <div id = 'content'> <table width="800" border="0" cellspacing="0" cellpadding="0"> <tr> <td class='subnavbg' width="148" align="left" valign="top"> <? $sublinks = '2'; $sublinks2 = '2'; $nav='branch2'; include ('content/subnav-alias2'.$test.'.php');?> </td> <td align="center" valign="top"><table width="652" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center" valign="top" class='contentbody'> <table width="625" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td ><p class="contenttitlered">BUILD YOUR OWN ALIAS</p> <p class="">Aasdfasdfasdf S</p></td> <td colspan="2" align="right" valign="top"><span class="topictitle"> </span></td> </tr> <tr> <td align="left" valign="top" class='contenttext' colspan='2' > <?php echo $Output; echo "<br><br><input id='reset' name='reset' type='submit' onClick='window.location.reload()' value='Start over!'></form>"; echo "</div>"; ?> <!-- now show the results of what they've picked so far -------------- This Is The Section I've Been Asking About. --> <?php $query_cats = "SELECT ID, folder_path, comp_cat_name FROM tbl_component_categories"; // echo $query_cats; $result = mysql_query($query_cats) or die(mysql_error()); $results_done = $_SESSION['options_picked']; echo "<div style='background-color:#000;width:170px;padding:15px; margin:10px;float:left;posiiton:absolute;Top:-100px; right:10px;'><font color='#ffffff'> <h3>You've chosen</h3>"; print_r($results_done); // adding suggested switch solution. foreach($results_done as $key => $val) { echo $key." and ".$val; switch($key) { case 0: $q_cat = 4; break; // Without this statement, the page would continue checking the other cases, albeit, they would all get evaluated as false case 1: $q_cat = 4; break; case 2: $q_cat = 1; break; case 3: $q_cat = 11; break; case 4: $q_cat = 2; break; case 5: $q_cat = 10; break; case 6: $q_cat = 9; break; default: // If the key is not 1-6, have a fallout. You can log the error, or do whatever you want. $q_cat = -1; } $query_cats = mysql_query("SELECT tbl_component_categories.ID, tbl_component_categories.folder_path, tbl_component_categories.comp_cat_name, tbl_components.component_name FROM tbl_components JOIN tbl_component_categories on $q_cat = tbl_component_categories.ID where tbl_components.ID = $val"); if (!$query_cats) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query_cats; die($message); } while ($row = mysql_fetch_array($query_cats)) { echo $row['comp_cat_name'].": ".$row['component_name']."<br>"; } } function RecursiveWrite($results_done) { foreach ($results_done as $vals) { echo $vals['0'] . "\n"; RecursiveWrite($vals['1']); } } echo "</font></div>"; // Print_r($results_done); ?> </td> </tr> <tr><td colspan=2><a name="b" id="b"></a><br /> <span class="anchor">(<a href="#header">Return to Top</a>)</span><br /> <br /> <br /> </td></tr> </table></td> </tr> </table></td> </tr> </table> </div> </body> </html>
  11. Yeah, that was the part I was thinking - that there has to be a way to run the query once, but I couldn't think how. I do have the $results_done printing out to the page, i just didn't put it in here. Sorry about that. I'm getting this: When the page first loads, it prints out: Array ( [0] => ) When they make a selection, the page reloads and $results_done = Array ( [0] => [1] => 34 ) I'm sure my entire page is all screwy but I don't really know how else to do this page. I've been going in circles on it. Such a simple concept, but not easy for my artist brain to understand.
  12. The way I understood what I'm doing, I need to query the database each time, because the next selection is contingent on what they chose. Scenario.. choose between A1 or A2. If you choose A, the page reloads with options B1, B3, and B4 If you choose B, the page loads from the database with options B2, B3 or B5 And it continues on from there, using a many-to-many link table to add what I want to each page. I'm sure there's a better way, but in the meantime, can somebody tell me why the variables aren't getting into the query?
  13. I'm pushing variables into an array, based on a selection. The page reloads, and the array is one longer. Then I have a little bit of code that and then I want to loop through the array to print out the selections to the page. First of all, is there a more sensible, shorter way to write this? Second, my variables $val and $q_cat aren't getting inserted into the query. If I switch those variables out and use hard values, the query works fine, Here's what I have: foreach($results_done as $key => $val) { $q_cat = ""; if ($key == "1") { $q_cat = "4";} elseif ($key == "2") { $q_cat = "1";} elseif ($key == "3") { $q_cat = "11";} elseif ($key == "4") { $q_cat = "2";} elseif ($key == "5") { $q_cat = "10";} elseif ($key == "6") { $q_cat = "9";} $query_cats = mysql_query("SELECT tbl_component_categories.ID, tbl_component_categories.folder_path, tbl_component_categories.comp_cat_name, tbl_components.component_name FROM tbl_components JOIN tbl_component_categories on $q_cat = tbl_component_categories.ID where tbl_components.ID = $val"); if (!$query_cats) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query_cats; die($message); } while ($row = mysql_fetch_array($query_cats)) { echo $row['comp_cat_name'].": ".$row['component_name']."<br />"; } }
  14. This is something wayyy above my paygrade, but I wanted to get an idea of what to expect, time needed and difficulty: installation of an ODBC driver on the web server, so that customers can access the information on their database and track purchases from their website, using PHP.
  15. I have no idea how to explain this.. I have a terribly awkward page built and I'm trying to amend a query to pull only the results from the database that match, depending on their previous choice. My beginning query, pulls the first set of options: SELECT tbl_component_to_component.compatible_component_ID, tbl_component_categories.ID, tbl_component_categories.folder_path, tbl_component_categories.comp_cat_name, tbl_components.component_name, tbl_components.image_filepath, tbl_components.component_category, tbl_components.ID AS comp_id FROM tbl_components JOIN tbl_component_categories ON tbl_components.component_category = tbl_component_categories.ID AND tbl_component_categories.ID = $variable1 As the page reloads, I want to only pull selectable options that are compatible with/based on the first selection made. In the database, I have a linking table (tbl_component_to_component) that lists these connections. It has three columns: id, the product id, and compatible product id This query pulls what I need. $variable2 is what they previously chose: SELECT tbl_component_to_component.component_ID, tbl_component_to_component.compatible_component_ID FROM tbl_component_to_component JOIN tbl_components ON tbl_component_to_component.component_ID = tbl_components.ID JOIN tbl_component_categories ON tbl_components.component_category = tbl_component_categories.ID WHERE tbl_component_to_component.component_ID = $variable2 My problem is, that I can't figure out how to combine the two queries into one - if that's even my solution. I thought maybe there was a way to do this using UNION, but I can't get it to work, and I worry that will lump everything together or not work, because the two queries are pulling different number of columns? Not sure any of that made sense, but at least it's a starting point.
  16. good lord... I'll look into your suggestions as I improve the script. But it's solved on the stupidest thing. I was missing a couple of capital letters in the script. nothing more. gah!! solved for now. on to figuring out nested arrays. yippee.
  17. oh no.... That left me more in the dark.. I've made a correction to that session variable, because it wasn't even setting from the variable I wanted. My fault, I was trying to work through this last night to come up with a new solution and still have the problem. Here's what I have now in that section of the code. Everything seems fine but the $Var is still not setting the second time. I'm so sorry I'm not getting this stuff. Also, I know I need to take care of security. I'm just trying to get the basic goal finished before I tackle that. if(!isset($_SESSION['options_picked'])){ $_SESSION['options_picked'] = array(); } if (!isset($_POST['chosen'])) { $var = "4"; } elseif(isset($_POST['chosen'])) { $choicetest = $_POST['chosen']; echo "and ".$choicetest; array_push($_SESSION['options_picked'],$choicetest); // supposed to be this and not $var. if((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Buttstocks')){ $var = "1"; } elseif((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Accessory_rail_mounts')){ $var = "11"; } elseif((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Caliber')){ $var = "2"; } elseif((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Barrel_length')){ $var = "10"; } elseif((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Suppressors')){ $var = "9"; } echo "cat= ".$_POST['what_category']; echo "var= ".$var; }
  18. holy cow! I'm not seeing it. I can tell you're alluding to something obviously easy. I tabbed everything, and eliminated the div tags because they're irrelevant to this version and were confusing me. I double checked brackets and they appear to be all closed. I'm not seeing anything in the logic that's wrong. I'm just not seeing it. Maybe, give me another hint?
  19. I'm trying to redo a page from scratch, and simplify things. I've gotten a "beginner-stumping" error. It's a page where the user makes a selection from a form with fields generated by a database. Then the page reloads, with the php determining which options to pull from the database, based on which category they last chose. It loops through the first time, and works fine. But the second time, I get an error: "You have an error in your SQL syntax; ... near 'ORDER BY tbl_components.component_category' at line 6" I echoed the query and I see its not carrying over the $var that second time the page reloads: "SELECT ....... AND tbl_component_categories.ID = ORDER BY tbl_components.component_category" Considering it worked on first selection, I'm kind of stumped. I did run the queries in MySQL just to make sure they work, and they do. Not sure where I'm getting it wrong. <?php session_start(); if(!isset($_SESSION['options_picked'])){ $_SESSION['options_picked'] = array(); } if (!isset($_POST['chosen'])) { $var = "4"; } elseif(isset($_POST['chosen'])) { array_push($_SESSION['options_picked'],$var); // below section is hard coded for the moment. // Later, when other things figured out, maybe I query the database for categories and category id, then I can loop to create the below statements // so it would be like: if post == 'row[x] { var = row[y];} etc. if((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Buttstocks')){ $var = "1"; } // here's the loop that determines what they selected. the first one above works fine elseif((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Accessory_rail_mounts')){$var = "11";} // the second one, above, is where I suddenly get an error. elseif((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Caliber')){$var = "2";} elseif((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Barrel_length')){$var = "10";} elseif((isset($_POST['what_category'])) && ($_POST['what_category'] == 'Suppressors')){$var = "9";} echo "cat= ".$_POST['what_category']; echo "var= ".$var; } include("../builder-test-code/dbc.php"); // query here $query = "SELECT tbl_component_categories.ID, tbl_component_categories.folder_path, tbl_component_categories.comp_cat_name, tbl_components.component_name, tbl_components.image_filepath, tbl_components.component_category FROM tbl_components JOIN tbl_component_categories ON tbl_components.component_category = tbl_component_categories.ID AND tbl_component_categories.ID = $var ORDER BY tbl_components.component_category"; $result = mysql_query($query) or die(mysql_error()); // create templates // CF: Using sprintf () and templates makes things a whole lot easier to read. $ExpandTemplate = <<<OutHTML <div id="%1\$s" style="width:550px;padding-top:20px;"> <!-- <a class='select-toggler' href="javascript:showHide('%2\$s-expander');"> this was the old thing --> <img style="position:relative;top:-2px;" src="images/structural/red-plus.gif" /> %1\$s <!--</a>--><br> <div id="%2\$s-expander" style="float:left;padding-right:25px;" width="90"> OutHTML; $ExpandImageTemplate = <<<OutHTML <div style='width:140px;padding:10px;float:left;'> %4\$s <br> <form action="" method="post"> <button type="submit" name="chosen" id="chosen" value="%4\$s"> <input type="hidden" name="what_category" value="%2\$s"> <img src="%3\$s" width="147" height="34" alt="image to come" title="choice" /> </button> <!-- this hidden field is what I can use to determine what category, I compare it to --> </form> </div> OutHTML; $ExpandImageTafter = <<<OutHTML </div></div> OutHTML; $Output = ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Build my rifle</title> </head> <body> <div><!-- where the original image at top of page will go --> '; //output section and sprintf while ($row = mysql_fetch_assoc ($result)) { if ($category != $row['component_category']) { $category = $row['component_category']; if (!$firstime) { $Output .= '</div><br><br>'; } else { $firstime = true; } //CF: Changed output to be stored in a temp variable, as well as adding output escaping to prevent XSS etc. $Output .= sprintf ($ExpandTemplate, htmlspecialchars ($row['comp_cat_name']), htmlspecialchars ($row['folder_path'])); } //CF: Changed output to be stored in a temp variable, as well as adding output escaping to prevent XSS etc. $Output .= sprintf ($ExpandImageTemplate, htmlspecialchars ($row['comp_cat_name']),htmlspecialchars ($row['folder_path']),htmlspecialchars ($row['image_filepath']),htmlspecialchars ($row['component_name'])); // when I get a chance, I need to figure out how to escape the /s in the image_filepath in code line above. It wasn't working when it was written: htmlspecialchars (rawurlencode($row['image_filepath'])). it just put %s } ?> <?php echo $Output; ?> </body> </html>
  20. Forgive me for not knowing how to explain this. I'm new and I'm trying to do this with SprintF - something I've never worked with before. And maybe I'm going about this wrong.. The button name is written in PHP as: name="%3\$s" The %3\$s value comes from the sprintf (in this case, $row['component_name']) : $Output .= sprintf ($ExpandImageTemplate, htmlspecialchars ($row['comp_cat_name']),htmlspecialchars ($row['folder_path']),htmlspecialchars ($row['component_name']),htmlspecialchars ($row['image_filepath'])); This value, in turn, comes from a query to the database. What they clicked on, could be one of a dozen possibilities, in this case. I don't know what that key is, because I didn't set it. the database essentially determined it, via a loop. When they make their selection, the page refreshes and I need to add that choice to my session variable.
  21. I have a php loop that generates values from the database. I want to push their choice _POST into a string session variable, but how if I don't know the _POST name? did that make any sense? So I have this code (extracted from a loop): $ExpandImageTemplate = <<<OutHTML %4\$s <br> <button type="submit" name="%3\$s" id="go" value="%2\$s"> <img src="%3\$s" width="147" height="34" alt="image to come" title="choice" /> </button> OutHTML; $Output .= sprintf ($ExpandImageTemplate, htmlspecialchars ($row['comp_cat_name']),htmlspecialchars ($row['folder_path']),htmlspecialchars ($row['image_filepath']),htmlspecialchars ($row['component_name'])); I won't know what name each button will have when it submits. but I want to do something: session_start(); if(!isset($_SESSION['options_picked'])){ $_SESSION['options_picked'] = ""; } // here's where I'm stumped if (isset($_POST["?????????"])) { $_SESSION['options_picked'] .= $_POST["????????"]; } Or maybe there's an easier way?
  22. A somewhat general question. Being a beginner, I think I painted myself into a corner. Imight not have thought through what/how to do what I'm doing. What I'm trying to do is build a page of 5 categories of options. These are contingent on the previous choice. You make a choice from category one, and the form auto-reloads the page in order to change what will appear in category 2 - and populate a box next to the choices so they can see what they've chosen so far. Then category 3 shows it's options, based on the restraints from category 2 - and so on. I got so caught up in trying to get the open/close functionality, and getting the data to simply populate the divs (thanks greatly to some help from ChristianF - I'm starting to learn a little about sprintf and templates.) But did I paint myself into a corner? Looking at the code below, is there a way to salvage what I've got to do this? Maybe there is, maybe it just seems daunting. I don't know what to do from here. gah! I'm soooo minor-league! <?php include("dbc.php"); $query = "SELECT tbl_component_categories.ID, tbl_component_categories.folder_path, tbl_component_categories.comp_cat_name, tbl_components.component_name, tbl_components.image_filepath, tbl_components.component_category FROM tbl_components JOIN tbl_component_categories ON tbl_components.component_category = tbl_component_categories.ID ORDER BY tbl_components.component_category"; $result = mysql_query($query); $category = false; // CF: Using sprintf () and templates makes things a whole lot easier to read. $ExpandTemplate = <<<OutHTML <div id="%1\$s" style="width:550px;padding-top:20px;"> <a class='select-toggler' href="javascript:showHide('%2\$s-expander');"> <img style="position:relative;top:-2px;" src="images/structural/red-plus.gif" /> %1\$s </a><br> <div id="%2\$s-expander" style="float:left;padding-right:25px;display:none;" width="90"> OutHTML; $ExpandImageTemplate = <<<OutHTML <div style='width:140px;padding:10px;float:left;'> %4\$s <br><img src='%3\$s'></div> OutHTML; $ExpandImageTafter = <<<OutHTML </div> OutHTML; $JSVariables = ''; // and here's the loop that creates the page $Output = ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <div id="builder-box-entire-code"> <div style="float:left;"> <form> <div> '; while ($row = mysql_fetch_assoc ($result)) { if ($category != $row['component_category']) { $category = $row['component_category']; if (!$firstime) { $Output .= '</div><br><br>'; } else { $firstime = true; } //CF: Changed output to be stored in a temp variable, as well as adding output escaping to prevent XSS etc. $Output .= sprintf ($ExpandTemplate, htmlspecialchars ($row['comp_cat_name']), htmlspecialchars ($row['folder_path'])); $JSVariables .= "'".htmlspecialchars ($row['folder_path']). "-expander', "; } //CF: Changed output to be stored in a temp variable, as well as adding output escaping to prevent XSS etc. $Output .= sprintf ($ExpandImageTemplate, htmlspecialchars ($row['comp_cat_name']),htmlspecialchars ($row['folder_path']),htmlspecialchars (rawurlencode ($row['image_filepath'])),htmlspecialchars ($row['component_name'])); } $finaljsstring = substr_replace($JSVariables ,"",-2); ?> <?php echo $Output; ?> <div id="main-text" style="width:350px;float:left;"> <!-- uncomment & change when style sheet is pulled to its own file <link rel="stylesheet" type="text/css" href="x.css" /> --> <p> <a class="select-toggler" href="#"> <img src="images/structural/view-my-rifle.gif" /></a></p> <hr /> <a class="select-toggler" href="#"> <img src="images/structural/redo-arrow.gif" style="position:relative;top:-2px;"/> START OVER</a> </div> <!-- end selector divs container div --> </form> <!-- start 'your selections' div container div --> <div id="results-box" style="float:right;"> <div style="background-color:#000; padding:1px 10px 10px 10px ; "> <p class="selector-paragraphs-header">YOUR SELECTIONS:</p> <p class="selector-paragraphs"> Action: <span id="span-action" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Barrel: <span id="span-barrel" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Length: <span id="span-length" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Trigger: <span id="span-trigger" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Bolt: <span id="span-bolt" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Pistol Grip: <span id="span-pistol-grip" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Magazine: <span id="span-magazine" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Hand Guard: <span id="span-hand-guard" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Suppressor: <span id="span-suppressor" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Muzzle Brake: <span id="span-muzzle-brake" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Accessory Rail Mounts: <span id="span-accessory-rail-mounts" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Finish: <span id="span-finish" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Weight: <span id="span-weight" class="chosen-data">x</span> </p> <p class="selector-paragraphs"> Carry Case: <span id="span-carry-case" class="chosen-data">x</span> </p> </div> <p id="price"> <span id="total-span">TOTAL:</span> $xxxxxx</p> <p id="send-specs"> SEND SPECS <img src="images/structural/green-arrow.gif" /></p> </div> <!-- end 'your selections' divs container div --> </div> <SCRIPT LANGUAGE="JavaScript1.2"> function showHide(d) { var onediv = document.getElementById(d); var divs=[<?php echo $finaljsstring; ?>]; for (var i=0;i<divs.length;i++) { if (onediv != document.getElementById(divs[i])) { document.getElementById(divs[i]).style.display='none'; } } onediv.style.display = 'block'; } </script> </body> </html>
  23. dang! I was so proud of myself for figuring out the "append a variable" trick, and was going to post that I figured it out. But you beat me to it AND improved the code! I got a loong way to go.
  24. Yeah, those are the two lines I'm thinking through. I just put $variable1 because I wouldn't know what the variables actually are. I know how to just echo a known variable into javascript, like html and any other. But if I don't know what that variable will be, then the whole idea fell apart. If I understand you right, I do want it to write this in at the same time all the rest of the html code is written from the server. Maybe I should just write the javascript script inline on the divs I want to toggle on and off?
  25. dang! Another new one for me.. I had a javascript solution to view/hide div tags, but when I got the php loop set up the way I want, I realized, that it creates a problem with the div names. I decided maybe I could automatically create a variable for to match each div that is created in the loop, but I'm not sure how to write those to the javascript? Assuming I've got the right forum on this one. Here's what I got: <!-- here's the script I need to put the variables into --> <SCRIPT LANGUAGE="JavaScript1.2"> function showHide(d) { var onediv = document.getElementById(d); var divs=[<$php echo "'".$variable1."'," and so on.... ]; for (var i=0;i<divs.length;i++) { if (onediv != document.getElementById(divs[i])) { document.getElementById(divs[i]).style.display='none'; } } onediv.style.display = 'block'; } </script> <?php // and here's the loop I'm talking about. while($row = mysql_fetch_assoc($result)) { if($category != $row['component_category']) { $category = $row['component_category']; if(!$firstime){ echo '</div><br><br>'; }else{ $firstime=true; } echo " <div id=\"{$row['comp_cat_name']}\" style=\"width:350px;padding-top:20px;\"> <a class=\"select-toggler\" href=\"javascript:showHide('{$row['comp_cat_name']}-expander');\"> <img src=\"images/structural/red-plus.gif\" style=\"position:relative;top:-2px;\"/> {$row['comp_cat_name']}</a><br>\n"; // here's how I thought maybe I could create the variable. Seems to work fine. Just don't know how to get it to the javascript $var{$row['comp_cat_name']} = "var_".$row['comp_cat_name']; } echo "<div id=\"{$row['comp_cat_name']}-expander\" style='float:left;padding-right:25px;display:none;' width='90'>{$row['component_name']} <br><img src='{$row['image_filepath']}'></div> \n"; } ?>
×
×
  • 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.