Psycho
Moderators-
Posts
12,159 -
Joined
-
Last visited
-
Days Won
130
Everything posted by Psycho
-
It would have been helpful if you had provided your current code. But, here is one sample solution <?php //Config var to determine # of columns $max_columns = 5; //Function to create a table row function createRow($rowRecords, $columns) { $rowHTML = ''; if(count($rowRecords)<1) { return $rowHTML; } $rowHTML .= "<tr>\n"; for($i=0; $i<$columns; $i++) { //If less than 5 records, a space is used for the remaining cells $data = (isset($rowRecords[$i])) ? $rowRecords[$i] : ' '; $rowHTML .= "<td>{$data}</td>\n"; } $rowHTML .= "</tr>\n"; return $rowHTML; } //Run the query to get the data $query = "SELECT something FROM table"; $results = mysql_query($query); //Create the output $tableHTML = ''; //Var to hold the output $records = array(); //Temp array for the records while ($records[] = mysql_fetch_assoc($result)) { if(count($records) == $max_columns) { //Create output for a complete row $tableHTML .= createRow($rowRecords, $max_columns); $records = array(); //Reset the array } } //Complete the final row $tableHTML .= createRow($rowRecords, $max_columns); ?> <html> <body> <table> <?php echo $tableHTML; ?> </table> </body> </html>
-
Absolutely. Humans are far superior to computers in making "judgements" on interpreting that type of input. An address - as entered by a person in a forum post - can be very dynamic. A human can identify the address because we do more than just intidentify the individual characters on the page. We can make judgements based upon position, capitalization and look at the contect in which the data was displayed. A computer can only make those determinations based upon the information you give it. Or, you can build a program that learns - but that might require you to go back to school and get a Phd in artificial intelligence. You have a couple of options. 1) Scour the internet to see if anyone has something that will do an adequate job. Although I would expect most solutions would require a payment 2) Build your own solution. This will require some time an effort on your part. You would need to come up with the rules and create the code to apply it. The most difficult part will be in coming up with the rules to ensure you have the most success at finding the addresses without any false positives. Here is a common way to write an address: 123 Main St., Anywhere, CA 12345 Now, you could create a rule to find instances int he text where a number exists and then capture everything to the next number. But, that would return too many false positives. Example: So, you have to keep making the rule more specific, but the more specific you make it the greater chance real addresses won't be found.
-
I was thinking of a slightly different approach as well which only require you to do two checks for each x point or each y point (whichever is shorter). In the example above you would just check the position at the point just above the first grid (such as 1.1) and then at the very end of the grid (1.9). You could then get the number of y grids that are included in that range. Then do the same thing for the grids in the x position of 2. The only thing you would have to calculate is the amount of offset to check at the boundires. That could be done using the slope of the line. The example above would only require four calculations.
-
Automatically numbering rows with repeat region
Psycho replied to RyanMinor's topic in PHP Coding Help
<?php include ('restrict.php' ); ?> <?php require_once('../Connections/conndb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $SSAdv_colors1 = array("#CCCCCC","#FFFFFF"); mysql_select_db($database_conndb, $conndb); $query_rsadmin = "SELECT id, firstname, lastname, address, city, `state`, zip, phone, email, organization, insertdate FROM TrioGrants ORDER BY insertdate DESC"; $rsadmin = mysql_query($query_rsadmin, $conndb) or die(mysql_error()); $row_rsadmin = mysql_fetch_assoc($rsadmin); $totalRows_rsadmin = mysql_num_rows($rsadmin); $output = ''; $rowCount = 0; while ($row_rsadmin = mysql_fetch_assoc($rsadmin)) { $rowCount++; $bgcolor = $SSAdv_colors1[($rowCount%count($SSAdv_colors1))]; $firstname = stripslashes($row_rsadmin['firstname']); $lastName = stripslashes($row_rsadmin['lastname']); $organization = stripslashes($row_rsadmin['organization']); $output .= "<tr bgcolor=\"{$bgcolor}\">\n"; $output .= "<td>{$row}</td>\n"; $output .= "<td><a href=\"detail.php?id={$row_rsadmin['id']}\">{$firstname} {$lastName}</a></td>\n"; $output .= "<td>{$organization}</td>\n"; $output .= "<td>{$row_rsadmin['city']}</td>\n"; $output .= "<td>{$row_rsadmin['state']}</td>\n"; $output .= "</tr>\n"; } mysql_free_result($rsadmin); $currentDate = date("F j, Y, g:i a"); ?> <!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>TRIO Grants</title> <style type="text/css"> <!-- .style4 {color: #FFFFFF; font-weight: bold; } --> </style> </head> <body> <table width="720" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><a href="index.php"><img src="../images/sss.banner.gif" width="720" height="74" border="0" /></a></td> </tr> <tr> <td><div align="center"><strong>Administrator Page</strong><br /> </div> </table> <br /> <table width="70%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="50%"><div align="left">Washington, DC Registration Report<br /> as of <?php echo $currentDate; ?> (<a href="excel.php">Generate Report</a>)</div></td> <td width="50%"><div align="right">Total Number of Registrants: <?php echo $rowCount ?> </div></td> </tr> <tr> <td colspan="2"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td bgcolor="#000000" class="style4">#</td> <td bgcolor="#000000"><span class="style4">Name</span></td> <td bgcolor="#000000"><span class="style4">Organization</span></td> <td bgcolor="#000000"><span class="style4">City</span></td> <td bgcolor="#000000"><span class="style4">State</span></td> </tr> <?php $output; ?> </table></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </body> </html> -
Build youself a static HTML page of how you would like the output to be displayed. Then modify the code to output in that format.
-
No, it doesn't. You do not need to use javascript to set the hidden value. You would still have to validate that value on the server-side, so the hidden field really provides no useful information. So, on the processing page, if the Head of Household option is yes, just set the parent ID (in the PHP code) to 0. In the processing page you would want to check the user input and validate based upon the selections. Here is a quick example (I left off a lot of validations needed, empty fieldsm escaping for the query, ensuring the parent id is valid, etc) $name = trim($_POST['name']); //Determine if entry is head of household $parent = ($_POST['hoh']=='yes'); if($parent) { //Entry was head of household validate address data $address = trim($_POST['hoh']); $city = trim($_POST['city']); $state = trim($_POST['state']); $zip = trim($_POST['zip']); $query = "INSERT INTO table (name, parent_id, address, city, state, zip) VALUES ('{$name}', 0, '{$address}', '{$city}', '{$state}', '{$zip}')"; } else { //Entry was NOT head of household validate hoh selection $parent_id = (int) $_POST['hoh_id']; $query = "INSERT INTO table (name, parent_id) VALUES ('{$name}', {$parent_id})"; }
-
Unless I am misunderstanding something this isn't complicated at all. For the select list of heads of household you would need to queery the list and their IDs to populate the select list. I think the problem you are having is that based upon whther the entry is a head of household or not, you need them to enter data into different fields. You can use javascript to hide/show the correct fields to display - but you will need to validate on the server-side as well. Another option that can be used in combination with the javascript would be to put the different group of fields into boxes that make it intuitive to the user which options they need to fill out. Example: <html> <body> Name: <input type="text" name="name" /> <br /><br /> Is this entry a head of household? <table border="0"> <tr valign="top"> <td><input type="radio" name="hoh" value="yes" /> Yes</td> <td><fieldset> Address: <input type="text" name="address" /><br /> City, ST ZIP: <input type="text" name="city" />, <input type="text" name="state" size="2" /> <input type="text" name="zip" size="5" /></td> </fieldset> </tr> <tr valign="top"> <td><input type="radio" name="hoh" value="no" /> No</td> <td><fieldset> Select the head of household: <select name="hoh_id"> <option value="1">Name of HOH1</option> <option value="2">Name of HOH2</option> <option value="3">Name of HOH3</option> </select> </fieldset> </td> </tr> </table> </body> </html>
-
<?php //Var to adjust number of columns $max_columns = 6; function create_row($row_data) { if(count($row_data)<1) { return false; } $row_output = "<tr>\n"; foreach($row_data as $row) { $row_output .= "<td>"; $row_output .= "<a href=\"questiondetails.php?recordID={$row['ID']}\">{$row['item']}<br />\n"; $row_output .= "{$row['image_tb']}</a>\n"; $row_output .= "</td>\n"; } $row_output .= "<tr>\n"; return $row_output; } $current_col = 0; $row_data = array(); $table_output = ''; while($row_sixities = mysql_fetch_assoc($sixities)) { $current_col++; $row_data[] = $row_sixities; if($current_col%6==0) { $table_output .= create_row($row_data); $row_data = array(); } } $table_output .= create_row($row_data); ?> <table border="1" align="center"> <?php echo $table_output; ?> </table>
-
Well, duh! You said it was a multi-dimensional array and you wanted to select a row, i.e. one of the sub arrays. Be a little more specific in your requests and then there woul dbe no need for this post to require 6+ replies! Well, there is always extract(): $index = 2; extract($array[$index]); echo "Patient ID: {$patientid}<br />\n"; echo "Forename: {$forename}<br />\n"; echo "Surname: {$surname}<br />\n"; echo "DOB: {$dob}<br />\n"; Output: Patient ID: 2 Forename: Samue Surname: Williams DOB: 17/08/1985
-
$selectedRow = $array[2];
-
I suspected there might be something like that out there, I just relied on the old standby y = mx +b. However, that algorithm does have a flaw for what the OP wanted since it does not count grid squares that the line "barely" intersects since it is trying to approximate a strait line. It does give me an idea on how the previous code I created could be optimized though.
-
The second solution does exactly that. The regular expression returns all word matches that do not contain any lower case letters. So it can contain anything else: upper case letters, numbers, or special characters.
-
You need to learn to use JOINs in your queries. I would also advise against duplicating field names between tables (unless they are foreign keys) as it can cause confusion. I had to give aliases for the 'name" fields from the members and ranks tables to be able to query them at the same time. $query = "SELECT members.name as username, steamid, ranks.name as rankname FROM members JOIN ranks ON members.rank = ranks.id ORDER BY ranks.id, members.name"; $result = mysql_query($query); $current_rank = ''; while($row = mysql_fetch_assoc($result)) { //Show rank header if different from last if($current_rank != $row['rankname']) { $current_rank = $row['rankname']; echo "<h1>{$current_rank}</h1>\n"; }; //Show player details echo "<b>Name:</b> {$row['username']}<br />\n"; echo "<b>Steam ID:</b> {$row['steamid']}<br />\n"; echo "<b>Rank:</b> {$row['rankname']}<br /><br />\n"; }
-
OK, after a little research I have greatly improved the code. Again, this returns the word parts that contain at least one number and no lower case letters: function getModelNumber($productName) { preg_match_all('#(?=\b.*[0-9]+.*\b)\b[^a-z]*\b#', $productName, $modelNameParts); return implode(' ', $modelNameParts[0]); } If the model number can be a string with just upper case letters and does not require a number, then the regular expression is much easier since all it needs to do is ensure there are no lower case letters: function getModelNumber($productName) { preg_match_all('#\b[^a-z]*\b#', $productName, $modelNameParts); return implode(' ', $modelNameParts[0]); } EDIT: Moving this topic to the RegEx forum where it belongs.
-
Your criteria contains information on what the model number can contain, but it does not categorically state the specific rules on how to differentiate a model number from other text. Based upon your examples, I *think* a possible rule is that any string which contains at least a single number and no lower case letters should be considered a model number. Without knowing ALL the possible inputs I can't say if this is a good rule or not. You will need to make that determination. The problem with things such as this is that humans are very good at making judgements whereas computers are not. Computers simply apply the criteria they are given. So, unless you know what all the possible inputs and expected outputs are you won't know if your rules will create false positives or negatives. For example, let's say you have the following product "Simtex PLAY4SURE Recorder XPR45XZ". You and I would be able to understand that "PLAY4SURE" is the product name and not the model number - but how would a computer know that? Here is a possible solution. It may not be the most efficient, but it works according to the rules I stated at the top function getModelNumber($productName) { $modelNameParts = array(); $words = explode(' ', $productName); foreach($words as $word) { if(preg_match('#[0-9]+#', $word) && !preg_match('#[a-z]+#', $word)) { $modelNameParts[] = $word; } } return implode(' ', $modelNameParts); } echo getModelNumber('Sony DCSW380B 14MP Camera'); //Output: DCSW380B 14MP echo getModelNumber('Casio 10MP Camera EX-Z3/3'); //Output: 10MP EX-Z3/3 echo getModelNumber('Panasonic Lumix Camera DMC-G1 12MP'); //Output: DMC-G1 12MP
-
I had a solution yesterday, but AlexWD beat me to it. After a couple of modifications this morning I think this solution is a little easier to work with. This solution allows you to pass the actual grid square "points" instead of having to calculate the midpoints. Simply pass the starting and endpoints in the format ('A', 1, 'B', 5): <?php function getGrids($startX, $startY, $endX, $endY) { //Create output array $gridSquares = array(); //Convert X letter values to number $xRange = range('A', 'J'); $startX = array_search(strtoupper($startX), $xRange) + 1; $endX = array_search(strtoupper($endX), $xRange) + 1; //Determine slope and offset $m = ($endY-$startY) / ($endX-$startX); $b = $startY - ($m * $startX); //Calculate a step value to find all grid squares $step = 1/(ceil(abs($m))+1); //Find the grid squares for($x=min($startX, $endX); $x<=max($startX, $endX); $x=$x+$step) { $y = ($m * $x) + $b; $grid_y = round($y); $grid_x = $xRange[round($x)-1]; $gridPosition = "$grid_x, $grid_y"; if(!in_array($gridPosition, $gridSquares)) { $gridSquares[] = $gridPosition; } } return $gridSquares; } $grids = getGrids('A', 1, 'B', 5); echo "<pre>"; print_r($grids); echo "</pre>"; ?> Output: Array ( [0] => A, 1 [1] => A, 2 [2] => A, 3 [3] => B, 3 [4] => B, 4 [5] => B, 5 )
-
As I plainly stated above: 1) That code assumes you have implemented company_id as the autoint field for the company table and used the same field name in the two other tables to associate the records. If you have not done that then it obviously won't work. 2) That code has not been tested. Also, that code will display all the phonen companies and list all of their phones and each phone option under each phone. Your original post said nothing about how you wanted the results displayed. Then in your last post you throw in different requirements about the user selecting a phone company and then geting different options in a select list to chooses from. None of that is extremely difficult and the sample code I provided should give you the correct direction to go. I am not going to write this whole thing for you for free. Either make an attempt to write it yourself (and seek help where you have problems) or post in the freelancing forum to find someone to do it for you for money.
-
You should use the auto-increment "id" field from the company table to link all the records. I would suggest renaming the field to "company_id" and use that in all the tables. So, I would also assume that the the phones and plans only associate back to the companies table - i.e. there is no direct association between phones and planes. In other words, a companies plans are available for all phone models. If not, you will need to create an association between plans and the phones. Since it would be a many-to-many relationship you would need a fourth table to make the associations. The one thing you didn't provide is a description of how you want to output the data. Do you want to show every plan for every phone? Assuming you do, here is one possible solution (I am using "company_id" as the auto-in in the company table and the associative field in the phone and plans tables). This is just a rough example and has not been tested <?php $query = "SELECT co.companyname, co.image as company_image, ph.phonename, ph.image as phone_image, ph.price as phone_price pp.planname, pp.minutes, pp.price as plan_price FROM `phonecompany` co JOIN `phones` ph using(`company_id`) JOIN `priceplan` pp using(`company_id`) ORDER BY co.companyname, ph.phonename"; $result = mysql_query($query); $output = ''; $current_company = ''; $current_phone = ''; while($record = mysql_fetch_assoc($result)) { //Display company name header if($current_company != $record['companyname']) { $current_company = $record['companyname']; $output .= "<tr><th colspan=\"2\">"; $output .= "<img src=\"{$record['company_image']}\" />{$record['companyname']}"; $output .= "</th></tr>\n"; } //Display phone if($current_phone != $record['phonename']) { $current_phone = $record['phonename']; $output .= "<tr>"; $output .= "<td><img src=\"{$record['phone_image']}\" /></td>"; $output .= "<td>{$record['phonename']}<br />{$record['phone_price']}</td>"; $output .= "</tr>\n"; $output .= "<tr>"; $output .= "<td> </td>"; $output .= "<td>Available Plans</td>"; $output .= "</tr>\n"; } //Display plans $output .= "<tr>"; $output .= "<td> </td>"; $output .= "<td>{$record['planname']}: Minutes{$record['minutes']}} ({$record['plan_price']})</td>"; $output .= "</tr>\n"; } ?> <html> <body> <table> <?php echo $output; ?> </table> </body> </html>
-
I would expect there is a relationship between the three tables - which you have not provided. You would want to do a single query that JOINs the tables to get all the data you want. Please specify how the tables are releated (i.e. what fields are available in each and identify the foreign keys) and detail how you want the information displayed. We can then help in constructing the appropriate query.
-
I have no clue what you are talking about. On the page that receives the form data you would simply use something like: $full_email = $_POST['username'] . $_POST['domain']; If that doesn't work, then use the folloing on the processing page to validate that the data is being received. print_r($_POST);
-
Script working on local database, but not 000webhost´s?
Psycho replied to Fenhopi's topic in PHP Coding Help
Did you validate that you have actually connected to the DB before trying to run a query? -
The fact that the page is PHP has nothing to do with the problem. Your PHP code is only setting a couple of variables and have no effect on the HTML page sent to the browser. You are apparently using some 3rd party script for doing your validation. I'm not really interested in trying to decypher 800+ lines of code to figure out why it doesn't work. This forum is for helping people with code they have written. Why don't you ask the author of that script why it isn't working. have you done ANY debugging to track down the problem to at least determine the specific function(s) in that script are causing the problem? All that being said, I would suggest changing the name and id of the field from "id" to anything else. "id" is a reserved word and should not be used for a form field if you want to reference in JS.
-
It is not going to work how you apparently think it will. You have to submit the form data before you can take any action on it. It seems you expect the form fields to be concatenated because of the cade you have at the bottom of the page. Since that code takes place before the form is ever sent to the user, that code has no purpose whatsoever. You will need to concatenate the values on the page that receives the POST data.
-
Your usage of functions is completely wrong. You are defining the functions in the if/else statements - not calling them. And, those functions are only defined to echo $price. The lines at teh bottom for best_cost() and extra_cost() would do nothing - except maybe produce errors. Try this: <?php function calculatePrice($area, $quality) { switch($quality) { case: 'best': $price_psf = 119.95; break; default: $price_psf = 79.95; break; } $total = $area * $price_psf; return $total; } $quality = $_POST['quality']; $width = (int) $_POST['width']; $length = (int) $_POST['length']; $area = $width * $length; $total = calculatePrice($area, $quality); ?> <html> <head><title>calculation</title> <style> body { background-color:#D8D8D8; color:#09F; } </style> </head> <body> Width: <?php echo $width; ?><br /> Length: <?php echo $length; ?><br /> Price per sq. foot: <?php echo $price_psf; ?><br /> Total Price: <?php echo $total; ?><br /> </body> </html>
-
And what is your problem? What is the code not doing that you want it to or what is it doing that you don't want? You didn't ask a question and I'm not sure from looking at the code what you are trying to accomplish. But, I will say that your function divisible() is only returning the remainder of the number divided by three - is that what you wanted?