
turpentyne
Members-
Posts
220 -
Joined
-
Last visited
Everything posted by turpentyne
-
Well, that was certainly easier... quick follow-up question and I'll call this thread solved. what about a footer? I've got a header , but I also need a footer, and didn't think about that... Is there some similar method to the header snippet that can be used to detect when to put a bit of code before going on to the next grouping?
-
I was told by someone that they felt the best way to generate a list with headers was to put them in a multidimensional array and then loop through it to create something like this. They mentioned the other way that Xyph suggested at the start of this thread (and that you just suggested), but said the array method was better in their mind. CATEGORY 1 item 1 item 2 item 3 CATEGORY 2 item 4 item 5 item 6 and so on... Is this not a good way to do this? maybe I'm taking the long way around? Or are there benefits you can think of? right now, it's printing everything to the page, but not breaking it apart.
-
haha! Now my head is spinning from the replies! I've gotten to here, but now I'm not sure how/where I echo a header for each nested array, when I'm printing to the page? $categorized_items = array(); $query_options = "SELECT component_name, image_filepath, component_category FROM tbl_components"; $result = mysql_query($query_options); while($row = mysql_fetch_assoc($result)){ $categorized_items[$row['component_category']][] = array($row['component_name'], $row['image_filepath']); } function PrintArray($categorized_items) { if(is_array($categorized_items)) { foreach($categorized_items as $key=>$value) { if(is_array($value)) { PrintArray($value); } else { echo " $key: $value<br>"; } } } } ?> <!--html --> <?php echo "and now...<br>"; PrintArray($categorized_items); ?>
-
I'm trying to find a good simple tutorial on how to take my query and turn it into a multidimensional array, but can't seem to find anything. basically I have this: ?php include("../builder-test-code/dbc.php"); $query_options = "SELECT component_name, image_filepath, component_category FROM tbl_components"; $result = mysql_query($query_options); while($row = mysql_fetch_assoc($result)){ $categorized_items = array(); // something remotely like this? $categorized_items[$row['component_category']] = array($row['component_name'], $row['image_filepath']); } ?> basically I am pulling all the results from a table with these three rows, and I'm trying to group them into individual arrays by the column "component_category" so I can figure out how to print the results of each array out to the page.
-
I can't think of how I'd do this... I have a database query that pulls results. Then, within that while statement I want to generate a subheader: Options 1, and show the results that match that category, then generate a 2nd subheader, Options 2, and so on.. Here's what I've got so far, and it's obviously looping the headers for each result right now... <?php include("dbc.php"); $query_options = "SELECT component_name, image_filepath, component_category FROM tbl_components"; $result = mysql_query($query_options); ?> <!-- html code code code --> <?php while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row[component_category]=="1") { ?> <!-- start what shows only once for this if statement - this is what I don't know how to set up --> <div id="accessory-rail-mounts"> <a class="select-toggler" href="javascript:showHide('accessory-rail-expander');"> <img src="images/structural/red-plus.gif" style="position:relative;top:-2px;"/> ACCESSORY RAIL MOUNTS</a><!-- end --> <!-- what I want looping within this category --> <div style='float:left;padding-right:25px;' width='90'><?php echo $row['component_name']; ?> <br> <img src="<?php echo $row['image_filepath']; ?>" width='90'></div> <!-- end what I want looping within this category --> <!-- start what shows only once for this if statement --> </div><!-- end --> <?php } // 2nd category, like the first... if ($row[component_category]=="11") { ?> <div id="calibers"> <a class="select-toggler" href="javascript:showHide('caliber-expander');"> <img src="images/structural/red-plus.gif" style="position:relative;top:-2px;"/> CALIBERS</a> <div id="caliber-expander" style="display:none;"><?php echo $row['component_name']; ?><br /> <?php echo "<img src=\"{$row['image_filepath']}\" width='90'></div> "; ?> <br /> </div> </div> <?php } // and so on, through four or five different categories // then, close while statement... } ?> <!-- html code code code --> </body>
-
Ok.. I know. probably a really simple thing, but I'm not sure how I should do this. I have a query at the top of my page that pulls data from mysql. Then I want to generate the page and have the data populate specific divs in the page, based on which category the data is. (I'll also want to control this, so that if they select one options, it redoes the query to pull more specific data for the other divs. But I should stick to one thing at a time) It's looping through the whole page code right now. I understand what's happening, but I'm just not sure how to create the page once, do the query once, and just loop through the data (unless I shouldn't do it) Here's what I have right now... <?php include("dbc.php"); $query_barrel_options = "SELECT component_name, image_filepath, category_ID FROM tbl_components"; $result = mysql_query($query_barrel_options); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <!--html code--> <div id="1"> <?php echo "<div style='float:left;padding-right:25px;' width='90'>{$row['component_name']} <br>" . "<img src=\"{$row['image_filepath']}\" width='90'></div> "; ?> </div> <div id="11"> <?php if ($row[category_ID]=="11") { echo "<div style='float:left;padding-right:25px;' width='90'>{$row['component_name']} <br>" . "<img src=\"{$row['image_filepath']}\" width='90'></div> "; } ?> </div> <div id="1"> <?php if ($row[category_ID]=="12") { echo "<div style='float:left;padding-right:25px;' width='90'>{$row['component_name']} <br>" . "<img src=\"{$row['image_filepath']}\" width='90'></div> "; } ?> </div> <!--rest of html --> <?php } ?> </body> </html> <?
-
So far that's making sense... it breaks it down further than I had. One question... so if I needed to include a connection between the components themselves, is there a feasible way to catalog the relation between siblings? for example: riflestock A is compatible with trigger A and trigger C But riflestock B is compatible with trigger B and Trigger C Do I just need to build a new table: table_component-to-component * ID * component ID -> table_components * compatible component id??? -> table_components does that make sense? Or would i use the table_component_categories to include this data? I could mock up some data, but the client hasn't given me any thing yet for real-world information. I'm trying to get the logic all figured out so I'm ready.
-
Many of the descriptors repeat across a few tables, but some would be unique to the component. caliber is a column that might be found in the barrel, but it's irrelevant to a rifle stock. hope that made sense.
-
Each component table is built with an autogenerated key ID in the first column, a name and a few descriptors of the item ID | Name | Description | length | weight | Make | price
-
I need an extra brain to help me think this through, give me a couple extra opinions/suggestions on how to structure this database. It's a "build your own" component that I'm doing for a rifle company - the challenge being that there is some tiered options. I could just do a many to many set up where I have a table of the product. Table_rifles :: includes ID, name, descriptors, etc. Then the components :: a table for each category.... table_barrel_options , table_bolts , table_stocks, magazine, magazine_receiver. Then I assume I'd do a connection_table with the columns: ID, Rifle_ID, component_category, component_ID Here's where things get tricky. I have a javascript menu of options where they pick, for example, "magazine receivers" I want to be able to query the database to only show the magazines that would fit into the magazine receiver. How can I add some conditionals to these, so that I can do what I need? Is there a separate column somewhere that is my silver bullet? Or is there another way to do the whole thing? A different table? Etc
-
I'm trying to add a new section to somebody's existing site. I need to connect to the database, and I'm not sure what to do with the error I got: Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/m/c/m/mcmfamily/html/builder-test-code/dbc.php on line 10 Here's what I'm using as my connection: <?php function dbconn() { if(!include_once('../filepath/dbc_include.php')) { die('Error include file...'); } if(!$link = mysql_connect($db['hostname'],$db['username'],$db['password'])) { die('Error connecting...'); } if(!mysql_select_db($db)) { die('Error selecting...'); } return $link; echo @mysql_ping() ? 'true' : 'false'; } $link = dbconn(); ?>
-
Trying to figure out how to do that, but I'm wondering if that's not going to help me? Does it count the number of times the loop occurs? each time will be a different amount, so how would it do the math? I need each individual total.
-
Hmmm.. Still no luck. Here's what I've got right now: $p = array(); foreach ($classes as &$class) { if ($class['discount_type'] == OFF_INDIVIDUAL) { $total = $class_cost * $class['quantity']; $discount = $class['quantity'] * $class['discount_value']; $total = $total - $discount; /* $grand_total += $total;*/ $grand_total += (float)$total; } if ($class['discount_type'] == PERC_INDIVIDUAL) { $total = $class_cost * $class['quantity']; // did say $total = $class['cost'] * $class['quantity']; $discount = ($class['discount_value'] / 100) * $class_cost; $total = $total - $discount; /* $grand_total += $total;*/ $grand_total += (float)$total; } if ($class['discount_type'] == OFF_FRIEND) { $firstclass = $class_cost-$class['discount_value']; $total = $class_cost * $class['quantity'] - $class['discount_value']; /* $grand_total += $total;*/ $grand_total += (float)$total; } if ($class['discount_type'] == PERC_FRIEND) { $discount = ($class['discount_value'] / 100) * $class_cost; $total = $class_cost * $class['quantity'] - $discount; /* $grand_total += $total;*/ $grand_total += (float)$total; } if($discount_type == PERC_TOTAL) { $total = mysql_escape_string($_POST['total']); $discount = ($class['discount_value'] / 100) * $total; $grand_total = $total - $discount; } if ($class['discount_type'] == OFF_TOTAL) { $discount_value = $class['discount_value']; $grand_total = ($class_cost * $class['quantity'])-$discount_value; } $p[] = $grand_total; } $final_total = array_sum($p); ?>
-
update: I just tried to add in the following buts but it didn't work. $p = array() and to each math section: $p[] = $grand_total; then at the end: $p[] = $grand_total; $final_total = array_sum($p) This just gave me '0'
-
I got this script, and it didn't dawn on me to total up the results. What I have below runs through each class, checks the database for what discount is applied. Then the math is done and I get a total. at the end. But I'm not quite sure how to do that - down at the bottom of the script below. <?php /* set the cache limiter to 'private' */ session_cache_limiter('private'); $cache_limiter = session_cache_limiter(); /* set the cache expire to 7 minutes */ session_cache_expire(7); $cache_expire = session_cache_expire(); /* start the session */ // connect to database include("db.php"); $discount = mysql_escape_string($_POST['discount']); $donation = mysql_escape_string($_POST['donation']); /*here, is the total cost from all classes selected on previous page */ $total = mysql_escape_string($_POST['total']); /* start insert of new math */ $discount_code = mysql_escape_string($_POST['discount']); //The discount code, if entered. //$selected_classes = array(217 => 1, 215 => 2); //How many of each class was selected. class_id => quantity $selected_classes = $_SESSION['s_filtered']; $grand_total = ""; // Built an array with information about each class, and what discount it can get. $classes = array(); foreach ($selected_classes as $class => $quantity) { $testquery = "SELECT * FROM `active_discounts` LEFT JOIN tbl_discount ON active_discounts.disc_id = tbl_discount.discount_id WHERE `code` = '{$discount_code}' AND `class_id` = '{$class}'"; $result = mysql_query($testquery); if (mysql_num_rows($result) > 0) { $discount_row = mysql_fetch_assoc($result); $discount_type = $discount_row['discount_type']; $discount_value = $discount_row['discount_amount']; $discount_name = $discount_row['discount_name']; $active_inactive = $discount_row['active_inactive']; $result = mysql_query("SELECT * FROM `tbl_workshops` WHERE `workshop_id` = '{$class}'"); $class_row = mysql_fetch_assoc($result); $class_name = $class_row['workshop_title']; $class_cost = $class_row['workshop_price']; $classes[$class]['workshop_title'] = $class_name; $classes[$class]['workshop_price'] = $class_cost; $classes[$class]['active_inactive'] = $active_inactive; $classes[$class]['discount_name'] = $discount_name; $classes[$class]['discount_type'] = $discount_type; $classes[$class]['discount_value'] = $discount_value; $classes[$class]['quantity'] = $quantity; } // The section below was supposed to be for when there was no discount. (nothing in the active_discounts table) else { $discount_value = "0"; $result = mysql_query("SELECT * FROM tbl_workshops WHERE workshop_id = '{$class}'"); if (mysql_num_rows($result) > 0){ $row = mysql_fetch_assoc($result); $grand_total = $row['workshop_price'] * $quantity; } else { // The class doesnt exist } } } // set some constants to make the code more readible. define("OFF_TOTAL", 1); define("OFF_INDIVIDUAL", 2); define("PERC_TOTAL", 3); define("PERC_INDIVIDUAL", 4); define("OFF_FRIEND", 5); define("PERC_FRIEND", 6); // Now we loop through each class and take off any valid discounts foreach ($classes as &$class) { if ($class['discount_type'] == OFF_INDIVIDUAL) { $total = $class_cost * $class['quantity']; $discount = $class['quantity'] * $class['discount_value']; $total = $total - $discount; $grand_total += $total; } if ($class['discount_type'] == PERC_INDIVIDUAL) { $total = $class_cost * $class['quantity']; // did say $total = $class['cost'] * $class['quantity']; $discount = ($class['discount_value'] / 100) * $class_cost; $total = $total - $discount; $grand_total += $total; } if ($class['discount_type'] == OFF_FRIEND) { $firstclass = $class_cost-$class['discount_value']; $total = $class_cost * $class['quantity'] - $class['discount_value']; $grand_total += $total; } if ($class['discount_type'] == PERC_FRIEND) { $discount = ($class['discount_value'] / 100) * $class_cost; $total = $class_cost * $class['quantity'] - $discount; $grand_total += $total; } } if($discount_type == PERC_TOTAL) { $total = mysql_escape_string($_POST['total']); $discount = ($class['discount_value'] / 100) * $total; $grand_total = $total - $discount; } if ($class['discount_type'] == OFF_TOTAL) { $discount_value = $class['discount_value']; $grand_total = ($class_cost * $class['quantity'])-$discount_value; } /* end insert of new math */ $final_total = $grand_total; $_SESSION['s_total_price'] = $final_total; if ($_SESSION['s_total_price'] == 0) { $_SESSION['$pay_or_not'] = "1"; /*header("Location: register4free.php"); */ echo $grand_total; } /* now I need to total them up but how*/ ?>
-
I have no idea how to fix this problem. because I'm not even sure where the problem's coming from. The user completes a multi-page form. When they get to register2.php, they enter a discount code. register3.php takes that code, checks the database to see if it exists, and/or is active. But for some reason, when they enter a non-existent discount code, "BREAK" it doesn't work. There are a couple of other nonexistent codes that cause the same problem. What's happening is that the Grand_total and Final_total are zeroing out which makes the user get kicked to register4free.php because it thinks they've registered for a $0.00 /free class. If they enter no discount, or an existing discount, the dollar amount does what it's supposed to. ANd Here's the page: <?php /* start the session */ session_start(); // connect to database include("dbconnect.php"); $discount = mysql_escape_string($_POST['discount']); // this is the part causing problems. $donation = mysql_escape_string($_POST['donation']); //just a donation. irrelevant. $total = mysql_escape_string($_POST['total']); // the total cost of the class from previous page. discount is subtracted below /* start insert of math */ $discount_code = mysql_escape_string($_POST['discount']); //The discount code, if entered. //$selected_classes = array(217 => 1, 215 => 2); // i.e. How many of each class was selected. class_id => quantity $selected_classes = $_SESSION['s_filtered']; $grand_total = ""; // Built an array with information about each class, and what discount it can get. $classes = array(); foreach ($selected_classes as $class => $quantity) { $testquery = "SELECT * FROM `active_discounts` LEFT JOIN tbl_discount ON active_discounts.disc_id = tbl_discount.discount_id WHERE `code` = '{$discount_code}' AND `class_id` = '{$class}'"; $result = mysql_query($testquery); if (mysql_num_rows($result) > 0) { $discount_row = mysql_fetch_assoc($result); $discount_type = $discount_row['discount_type']; $discount_value = $discount_row['discount_amount']; $discount_name = $discount_row['discount_name']; $active_inactive = $discount_row['active_inactive']; $result = mysql_query("SELECT * FROM `tbl_workshops` WHERE `workshop_id` = '{$class}'"); $class_row = mysql_fetch_assoc($result); $class_name = $class_row['workshop_title']; $class_cost = $class_row['workshop_price']; $classes[$class]['workshop_title'] = $class_name; $classes[$class]['workshop_price'] = $class_cost; $classes[$class]['active_inactive'] = $active_inactive; $classes[$class]['discount_name'] = $discount_name; $classes[$class]['discount_type'] = $discount_type; $classes[$class]['discount_value'] = $discount_value; $classes[$class]['quantity'] = $quantity; } // The section below was supposed to be for when there was no discount. (nothing found in the active_discounts table) may be what's not working? else { $discount_value = "0"; $result = mysql_query("SELECT * FROM tbl_workshops WHERE workshop_id = '{$class}'"); if (mysql_num_rows($result) > 0){ $row = mysql_fetch_assoc($result); $grand_total += $row['workshop_price'] * $quantity; } else { // The class doesnt exist } } } // setting some constants to make the code more readible. define("OFF_TOTAL", 1); define("OFF_INDIVIDUAL", 2); define("PERC_TOTAL", 3); define("PERC_INDIVIDUAL", 4); define("OFF_FRIEND", 5); define("PERC_FRIEND", 6); // Now looping through each class to take off any valid discounts foreach ($classes as &$class) { if ($class['discount_type'] == OFF_INDIVIDUAL) { $total = $class_cost * $class['quantity']; $discount = $class['quantity'] * $class['discount_value']; $total = $total - $discount; $grand_total += $total; } if ($class['discount_type'] == PERC_INDIVIDUAL) { $total = $class_cost * $class['quantity']; // did say $total = $class['cost'] * $class['quantity']; $discount = ($class['discount_value'] / 100) * $class_cost; $total = $total - $discount; $grand_total += $total; } if ($class['discount_type'] == OFF_FRIEND) { $firstclass = $class_cost-$class['discount_value']; $total = $class_cost * $class['quantity'] - $class['discount_value']; $grand_total += $total; } if ($class['discount_type'] == PERC_FRIEND) { $discount = ($class['discount_value'] / 100) * $class_cost; $total = $class_cost * $class['quantity'] - $discount; $grand_total += $total; } } if($discount_type == PERC_TOTAL) { $total = mysql_escape_string($_POST['total']); $discount = ($class['discount_value'] / 100) * $total; $grand_total = $total - $discount; } if ($class['discount_type'] == OFF_TOTAL) { $discount_value = $class['discount_value']; $grand_total = ($class_cost * $class['quantity'])-$discount_value; } $_SESSION['s_total_price'] = $grand_total; // here's where it's kicking them to another page because the total is zero. if ($_SESSION['s_total_price'] == 0) { $_SESSION['$pay_or_not'] = "1"; header("Location: register4free.php"); echo $grand_total; } /* end insert of new math */ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <!--[if !IE]><!--> <link rel="stylesheet" type="text/css" href="css/master3.css"/> <!--<![endif]--> <!--[if IE 6]> <link rel="stylesheet" type="text/css" href="css/master3_ie9.css"/><![endif]--> <!--[if IE 7]> <link rel="stylesheet" type="text/css" href="css/master3_ie9.css"/><![endif]--> <!--[if IE 8]> <link rel="stylesheet" type="text/css" href="css/master3_ie9.css"/> <![endif]--> <!--[if IE 9]> <link rel="stylesheet" type="text/css" href="css/master3_ie9.css"/> <![endif]--> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="Description" /> <meta name="keywords" content="Keywords" /> <meta name="author" content="workshopsaz.org" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>Workshops for Youth and Families - Building character. Inspiring confidence.</title> <script type="text/javascript"> function showMe(id){ document.getElementById(id).style.visibility='visible' } timer=null function hideMe(){ clearTimeout(timer) timer=setTimeout("document.getElementById('div_name').style.visibility='hidden'",500) } </script> <script type="text/javascript">function randRange(data) { var newTime = data[Math.floor(data.length * Math.random())]; return newTime; } function toggleSomething() { var timeArray = new Array(200, 300, 150, 250, 2000, 3000, 1000, 1500); // do stuff $("#orho1").toggleClass("visible"); // end stuff clearInterval(timer); timer = setInterval(toggleSomething, randRange(timeArray)); } var timer = setInterval(toggleSomething, 1000); // 1000 = Initial timer when the page is first loaded</script> </script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> // initialise variable to save cc input string var ccnumber_saved = ""; function checkLuhn(input) { var sum = 0; var numdigits = input.length; var parity = numdigits % 2; for(var i=0; i < numdigits; i++) { var digit = parseInt(input.charAt(i)) if(i % 2 == parity) digit *= 2; if(digit > 9) digit -= 9; sum += digit; } return (sum % 10) == 0; } </script> </head> <div id="containermain"> <? include("header.php"); ?> <div id="div_name" style="visibility:hidden;solid #aaa; z-index:5000;height:0px;position:relative;top:-96px;left:-55px;"><div style="background-color:#ffffff;width:100px;z-index:5001;padding:9px;-moz-border-radius: 17px; -webkit-border-radius: 17;border-radius: 17px;"> Hi! I'm ORHO! <br>Find out more about me here...</div> </div> <p><!-- start central content area --> <img src="images/head/head_reg4.gif" style="position:relative;left:-43px;top:5px;"/><br> <font face="georgia" size=5em><b>Step 4 - Credit Card Info</b></font><br><br> <form method="post" class="registration_form" action="register4.php" onsubmit="return myForm()"><br> <table border="0"> <?php $final_total = ($final_total + $donation); $_SESSION['s_total'] = $final_total; $reg_id = $_POST['reg_id']; $fname = mysql_escape_string($_POST['fname']); $lname = mysql_escape_string($_POST['lname']); $address = mysql_escape_string($_POST['address']); $address2 = mysql_escape_string($_POST['address2']); $city = mysql_escape_string($_POST['city']); $state = mysql_escape_string($_POST['state']); $zip = mysql_escape_string($_POST['zip']); $phone = mysql_escape_string($_POST['phone']); $fax = mysql_escape_string($_POST['fax']); $email = mysql_escape_string($_POST['email']); $hear = mysql_escape_string($_POST['hear']); $how1 = mysql_escape_string($_POST['how1']); $how2 = mysql_escape_string($_POST['how2']); $how3 = mysql_escape_string($_POST['how3']); $how4 = mysql_escape_string($_POST['how4']); $discount_name = mysql_escape_string($_POST['discount']); $how = $how1 . $how2 . $how3 . $how4; $query_insertItem = "UPDATE tbl_registration set reg_total_price = '$final_total', discount_used = '$discount_name' where reg_id=$reg_id"; $dberror = ""; $ret = mysql_query($query_insertItem); ?> <tr><td><?php if(!empty($_POST['discount'])){ if($discount_type == 4 || $discount_type == 3 || $discount_type == 6){echo "%";} else{echo "$";} echo " Discount: ";} ?> </td><td><?php if($active_inactive == 1){echo $discount_value;} elseif($discount_code !="") {echo "<font color='#990000'>inactive/invalid discount code</font>";} ?></td></tr> <tr><td><?php if(!empty($_POST['donation'])){ echo "Donation:";}?> </td><td> <?= $donation ?></td></tr> <tr><td>Total: </td><td>$<?= grand_total ?></td></tr> <tr><td>Credit Card: </td><td> </td></tr> <!-- save input string and strip out non-numbers --> <!-- restore saved string --> <tr><td> Credit Card #:</td><td><input type="text" name="ccnumber" id="ccnumber" size="46" onblur="ccnumber_saved = this.value; this.value = this.value.replace(/[^\d]/g, ''); if(!checkLuhn(this.value)) { alert('Sorry, that is not a valid number - please try again!'); this.value = ''; }this.className='reg_off';" onfocus=" if(this.value != ccnumber_saved) this.value = ccnumber_saved;this.className='reg_live'; "> </td></tr> <tr><td>Expiration:</td><td> </td></tr> <tr><td>Card Verification:</td><td><input type="text" name="cc_code" id="cc_code" size="4" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" ><font size=2> (the 3 digits on back of card)</font></td></tr> <tr><td>Name on Card:</td><td><input type="text" name="cc_name" id="cc_name" size="46" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" ></td></tr> </table><br /><br /> <!-- end central content area --> </div> </p></div> </div> <div class="clearfooter"></div> </div><!—End Container—> <div id="footer"><? include("footer.html"); ?></div>
-
never mind! typo. I got it.
-
I have a basic javascript to change the text in a span, based on a select dropdown. THe basic script worked, but when I tried adding in an if statement to make it change to the selected color only if the dropdown is a value greater than the default value. I tried != '0', != null and != ''. Still nothing. <script> function highlighter(nameit,adderup) { var e = document.getElementById(adderup); var strUser = e.options[e.selectedIndex].value; if (stringUser != '') { elementtochange = document.getElementById(nameit); elementtochange.style.color = "orange"; } else { elementtochange = document.getElementById(nameit); elementtochange.style.color = "black"; } } </script> <!-- looped dropdowns, from php and mysql --> <select style="width:70px;" name="participantqty[<?= $c_row['workshop_id'] ?>]" id="participantqty<?= $c_row['workshop_id'] ?>" onChange="highlighter('selectedclass<?= $c_row['workshop_id'] ?>', 'participantqty<?= $c_row['workshop_id'] ?>')"> <option value="">select </option> <option value="1" width=45>1 </option> <option value="2" width=45>2 </option> </select>
-
I have a "read more" toggle button on my page that uses this basic script - I want it to also change the background image listed in the stylesheet, but it doesn't work. Any thoughts? <script type="text/javascript"> function showme(id, linkid) { var divid = document.getElementById(id); var toggleLink = document.getElementById(linkid); if (divid.style.display == 'block') { toggleLink.innerHTML = '<img src="images/readmore.png">'; divid.style.display = 'none'; document.container_homepage.style.backgroundImage="url('http://www.workshopsaz.org/images/bgx.jpg')"; } else { toggleLink.innerHTML = '<img src="images/readless.png">'; divid.style.display = 'block'; document.container_homepage.style.backgroundImage="url('http://www.workshopsaz.org/images/bgx2.jpg')"; } } </script>
-
Maybe somebody knows a good way to do this... I have a simple query that seasonal categories - plus one special events header. then for each header I pull all the classes in that category. Right now it just pulls and orders by id. So, regardless of year, they come out in the same order: spring, winter, fall, special events. I'm trying to see if there's a way to make them show in order of relevance to the current time. right now, the "cat" table just has two fields: cat_id, cat_name. In other words, in autumn, I want them to order: Autumn, winter, summer, spring - then special events. In summer, I want them to order: Summer, spring, autumn, winter - then special events. any thoughts on how to do this? step one, order by relevence to current date. step two, special events is always last. $query1 = "select * from tbl_cat ORDER by cat_id"; $result_cats = mysql_query($query1) or die(mysql_error()); while ($row = mysql_fetch_array($result_cats)) { $query_selectall = "select *,workshop_date AS tester from tbl_workshops WHERE category={$row['cat_id']} and active_inactive = '1' ORDER by workshop_date"; $result_all = mysql_query($query_selectall) or die(mysql_error()); $catid = $row['cat_id']; $catname = $row['cat_name']; echo "<font face='georgia' size=5><b>".$catname." </b></font><br><div style='color:#fff;'>"; while ($c_row = mysql_fetch_array($result_all)){ // rest of code pulls items that match that specific category id. }
-
AHA! fixed. I changed the variable setting to: var fname = document.getElementsByName("kfname[]"); var lname = document.getElementsByName("klname[]"); var birth_month = document.getElementsByName("bdate2[]"); var birthday = document.getElementsByName("bdate[]"); var birthyear = document.getElementsByName("bdate3[]"); works like a charm.
-
yay! and boo. I didn't even notice those two issues. Moved the <form... > outside of the loop, and got rid of the extra brackets. But still no good. Then I went through firebug's console to see what errors I get. Nada. grrr..
-
Forgive me, I don't think I explained properly. the php is just generating a looped series of forms. On the completed page, clientside, I have the javascript at top verifying the form fields before they continue onto the next page. This is what's not working - not related to php issues. So, this prints to the page, but doesn't seem to get to the javascript: <form name="register1" class="registration_form" method="post" action="register2.php" target="_self" onsubmit="return validation1()"> onsubmit="return validation1()" calls the javascript before it sends to the next php location. But it doesn't seem to be working.
-
I'm completely stumped on this one. I'm posting the whole page of script, because I just can't see why this form wouldn't call the validation script. <?php /* set the cache limiter to 'private' */ session_cache_limiter('private'); $cache_limiter = session_cache_limiter(); /* set the cache expire to 7 minutes */ session_cache_expire(7); $cache_expire = session_cache_expire(); /* start the session */ session_start(); $_SESSION['page'] = 1; if ($_SESSION['page'] != 1) { header("Location: register.php"); exit; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type='text/javascript'> function validation1(){ alert("sometext"); // Make quick references to our fields // doesnt even make it this far { // Make quick references to our field *ARRAYS*: var fname = document.register1["kfname[]"]; var lname = document.register1["klname[]"]; var birth_month = document.register1["bdate2[]"]; var birthday = document.register1["bdate[]"]; var birthyear = document.register1["bdate3[]"]; for ( var f = 0; f < fname.length; ++f ) { var n = f+1; if( ! isAlphabet(fname[f], "Please enter only letters for first name " +n) || ! isAlphabet(lname[f], "Please enter only letters for last name " +n) || ! madeSelection(birth_month[f], "Pleace choose a birth month for name " +n) || ! madeSelection(birthday[f], "Please choose a birth day for name " +n) || ! madeSelection(birthyear[f], "Please choose a birth year for name " +n) ) { return false; } } return true; } function isAlphabet(elem, helperMsg){ var alphaExp = /^[a-zA-Z ]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphanumeric(elem, helperMsg){ var alphaExp = /^[0-9a-zA-Z\s]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function madeSelection(elem, helperMsg){ if(elem.value == ''){ alert(helperMsg); elem.focus(); return false; }else{ return true; } } </script> </head> <div id="container"> <? include("header.php"); ?> <div id="div_name" style="visibility:hidden;solid #aaa; z-index:5000;height:0px;position:relative;top:-96px;left:-55px;"><div style="background-color:#ffffff;width:100px;z-index:5001;padding:9px;-moz-border-radius: 17px; -webkit-border-radius: 17;border-radius: 17px;"> Hi! I'm ORHO! <br>Find out more about me here...</div> </div> <p><!-- start central content area --> <img src="images/head/head_reg2.gif" style="position:relative;left:-43px;top:5px;"/><br> <?php if (isset($_POST["submit"])) { if ($_POST["unique_id_form"] == $_SESSION["unique_id"]) { $_SESSION["unique_id"] = ''; } else echo 'error'; } else { $_SESSION["unique_id"] = uniqid (rand (),true); } if ( (isset($_POST['fname'])) && ($_POST['fname'] !='') && (isset($_POST['email'])) && ($_POST['email'] !='') && (isset($_POST['phone'])) && ($_POST['phone'] !='') ){ function isValidEmail($email){ return eregi('^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$', $email); } if (isset($_POST['participantqty']) && max($_POST['participantqty']) > 0){ // connect to database include("Dbconn.php"); $_SESSION['s_fname'] = mysql_escape_string($_POST['fname']); $_SESSION['s_lname'] = mysql_escape_string($_POST['lname']); $_SESSION['s_address1'] = mysql_escape_string($_POST['address1']); $_SESSION['s_address2'] = mysql_escape_string($_POST['address2']); $_SESSION['s_city'] = mysql_escape_string($_POST['city']); $_SESSION['s_state'] = mysql_escape_string($_POST['state']); $_SESSION['s_zip'] = mysql_escape_string($_POST['zip']); $_SESSION['s_phone'] = mysql_escape_string($_POST['phone']); $_SESSION['s_fax'] = mysql_escape_string($_POST['fax']); $_SESSION['s_email'] = mysql_escape_string($_POST['email']); /*$_SESSION['s_hear'] = mysql_escape_string($_POST['hear']); $_SESSION['s_how1'] = mysql_escape_string($_POST['how1']); $_SESSION['s_how2'] = mysql_escape_string($_POST['how2']); $_SESSION['s_how3'] = mysql_escape_string($_POST['how3']); $_SESSION['s_how4'] = mysql_escape_string($_POST['how4']); */ $_SESSION['s_resident'] = mysql_escape_string($_POST['resident']); $_SESSION['s_phone2'] = mysql_escape_string($_POST['phone2']); } } $filtered = array_filter($_POST['participantqty']); $_SESSION['s_participantqty'] = array_filter($_POST['participantqty']); echo "<br><p style='font-size:1.25em;color:#f67026;padding-bottom:10px;'>Enter the name(s) that you want to enroll in each class</p></b><br>"; // start the form generation based on class selection from previous page foreach($filtered as $key => $line) { $query_class = "SELECT workshop_title FROM tbl_workshops WHERE workshop_id = $key"; //$result_class = mysql_query($query_class); $r = mysql_query($query_class) or die(mysql_error()); //$g_row = mysql_fetch_array($query_class); while($row = mysql_fetch_array($r)) { echo "<p style='font-size:1.25em;color:#000;padding-bottom:10px;'><span style='font-size:.9em;color:#7E3F0F;'>ENROLLEES FOR: </span>".$row['workshop_title']."</p>";} $count = $line; $i = 1; while ($i <= $count) { $i++; /* the printed value would be $i before the increment (post-increment) */ $x = $i-1; ?><form name="register1" class="registration_form" method="post" action="register2.php" target="_self" onsubmit="return validation1()"> <b><?= $reg_id ?><span style='color:#777777;padding-bottom:10px;'> Child #<?= $x ?> </span></b> <img src="/images/greenblack.gif" style="height:2px; width:450px;position:relative;left:5px;top:-3px;"><br><br> <div style="float:left; padding-right:20px;">Kid's First Name<br><input type="text" name="kfname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /></div> <div style="float:left; padding-right:20px;">Kid's Last Name<br><input type="text" name="klname[]" id="lname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /></div> <div>Birthdate<br><div style=""> <select style="width:75px;" id="birth_month" name="bdate2[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > <option value="">month</option> <option value="01">Jan</option> <option value="02">Feb</option> <option value="03">Mar</option> <option value="04">Apr</option> <option value="05">May</option> <option value="06">Jun</option> <option value="07">Jul</option> <option value="08">Aug</option> <option value="09">Sept</option> <option value="10">Oct</option> <option value="11">Nov</option> <option value="12">Dec</option> </select> <select style="width:57px;" id="birthday" name="bdate[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > <option value="">day</option> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> <option value="05">05</option> <option value="06">06</option> <option value="07">07</option> <option value="08">08</option> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select style="width:60px;" id="birthyear" name="bdate3[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > <option value="">year</option> <option value="1993">1993</option> <option value="1994">1994</option> <option value="1995">1995</option> <option value="1996">1996</option> <option value="1997">1997</option> <option value="1998">1998</option> <option value="1999">1999</option> <option value="2000">2000</option> <option value="2001">2001</option> <option value="2002">2002</option> <option value="2003">2003</option> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <!--<option value="2009">2009</option> <option value="2010">2010</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> <option value="2016">2016</option> <option value="2017">2017</option> <option value="2018">2018</option> <option value="2018">2019</option> <option value="2018">2020</option>--> </select></div></div> <br> <input type="hidden" name="workshop_id[]" id="workshop_id" value="<?php echo $key; ?>"> </td></tr></table><br><br> <?php } } ?><br /> <input type="submit" value="next" /> </form> <!-- end central content area --> <br /><br /><br /><br /> </div> </p></div> </div>
-
prechecking table generated boxes, using 2nd table in db.
turpentyne replied to turpentyne's topic in PHP Coding Help
Scratch that! All good. Thanks!