Jump to content

turpentyne

Members
  • Posts

    220
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

turpentyne's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

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