PHP - Reading From Table Or Something Else
Similar TutorialsI have created code that allows a table of 'X' rows and 'Y' columns to be made (the user enters the X and Y value) with each table cell being uniquely identified through name as (X, Y). Each cell is has a value of 5 and all cells needs to be filled in before the table is submitted, which is where the problem arises. How exactly would one be able to verify that every cell has been filled and then calculate the sum of all the values entered into the cells for all those which have the same X value? The code to generate the table is as follows: echo "<td align='left'><b>$X<b></td>"; For($Y = 1; $Y <= $num; $Y++) { ?> <td align="center"><input type="text" name="<?php echo "$X,$Y";?>" value="<?php echo 5; ?>" /> </td> <?php } Thanks. Hi, I am trying to write the code the read a search form however it is not reading my table 'productdbase' to return any results. I can echo from this table so I know it works but so far it just returns "Your search for 'Keyword' returned no results" as per below. Can anyone advise please. Code: [Select] $results = "SELECT 'description', 'fulldescription' FROM 'productdbase' WHERE $where"; Code: [Select] <?php if (isset($_POST['keywords'])){ $keywords = mysql_real_escape_string (htmlentities(trim($_POST['keywords']))); } $errors = array(); if (empty($keywords)) { $errors[] = 'Please enter a search term'; } else if (strlen($keywords)<3) { $errors[] = 'Your search must be three or more characters'; } else if (search_results($keywords) === false) { $errors[] = 'Your search for '.$keywords.' returned no results'; } if (empty($errors)) { search_results ($keywords); } else{ foreach($errors as $error) { echo $error, '</br>'; } } ?> <?php function search_results ($keywords) { $returned_results = array(); $where = ""; $keywords = preg_split('/[\s]+/', $keywords); $total_keywords = count($keywords); foreach($keywords as $key=>$keyword) { $where .= "'keywords' LIKE '%$keyword%'"; if ($key != ($total_keywords - 1)) { $where .= " AND "; } } $results = "SELECT 'description', 'fulldescription' FROM 'productdbase' WHERE $where"; $results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0; if ($results_num === 0) { return false; }else{ echo 'something found.'; } } ?> I am reading in a table and ordering it by a column labeled "sub" and generating an HTML table. The "sub" column entries are in numerical order (i.e. 1 2 3 4 5 6 7 8 10 11 12 etc. etc.). There are over 100 entries in this table as well. The problem I'm facing is probably obvious to some of you as the display is
1 Obviously I'd like the display to be in numerical order.
What can I do?
Okay I don't mind telling you I am very perplexed on how to read a text file delimited with TAB into a HTML Table using PHP. I don't know where to begin, I have read about 12 examples and get more confused each time. I hope someone can help me. I am looking to read this delimited (TAB) file skipping the first line and reading array's 2,5,6,7,8,9, and 10, then displaying in a HTML Table. Corresponding Headers would be nice. The php file does not work at the present because I am trying to read the array sections by row.
Thank You in advance
Attached Files
ParseText.php 852bytes
3 downloads
JimTest.txt 16.88KB
1 downloads Hello
Is it possible to save data from saved htm table from other website in our mysql database system
as I have problem that there is one htm page where i can get data but i want to save it in mysql table. as data is large on htm page
it was hard to copy so i want access it direct from php and save it in mysql table
please guide
awaiting your valuable reply.
Thank in advance
Hi
I come from a desktop (vb.net) background and have used oridinary text files for my databases. I use file locking to prevent other processes from writing to the same file simultaneously.
Now I am moving over the PHP/MySQL - what precautions should I take to stop a simultaneous processes from writing to a table at the same time.?
Do I need to lock the table before writing to it?
Does MySQL deal with this automatically and just block my process until the table becomes free?
(I am talking about a single table here, not multiple dependant tables - I know that is another issue)
Thanks
Nigel
PHP 5.3.8 XAMPP on Windows XP I have an XML file that manages the input to an mp3 player on this page http://www.jimslounge.com/segovia/ The structure looks like this Code: [Select] <content> <auto_play>yes</auto_play> <loop>yes</loop> <volume>60</volume> <artist> <song_title><![CDATA[Bach - Suite No. 3 - Allemande]]></song_title> <artist_name><![CDATA[Andre Segovia]]></artist_name> <image_path>load/images/segovia.jpg</image_path> <mp3_path>load/songs/Bach - Suite No. 3 (for solo cello, arr. Duarte)- Allemande.mp3</mp3_path> <url target="_blank" open="yes">http://en.wikipedia.org/wiki/Andr%C3%A9s_Segovia</url> </artist> <artist> ... with <artist> being the repeating element I want to be able to read and eventually write to If I run this Code: [Select] $xml = simplexml_load_file("load.xml"); var_dump($xml); I get this object(SimpleXMLElement)#1 (4) { ["auto_play"]=> string(3) "yes" ["loop"]=> string(3) "yes" ["volume"]=> string(2) "60" ["artist"]=> array(22) { => object(SimpleXMLElement)#2 (5) { ["song_title"]=> object(SimpleXMLElement)#24 (0) { } ["artist_name"]=> object(SimpleXMLElement)#25 (0) { } ["image_path"]=> string(23) "load/images/segovia.jpg" ["mp3_path"]=> string(74) "load/songs/Bach - Suite No. 3 (for solo cello, arr. Duarte)- Allemande.mp3" ... [/color] which is overwhelming This cleans it up but doesn't give me the artist name and song name I'm looking for. Code: [Select] $xml = simplexml_load_file("load.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } The Output: content auto_play: yes loop: yes volume: 60 artist: artist: artist: My experience with simplexml only goes back a couple of hours so I'm pretty inept at this point. Any help will be greatly appreciated. Hello, I'm trying to read some XML by name this is the XML: Code: [Select] <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <imgdir name="01040000.img"> <imgdir name="info"> <canvas name="icon" width="29" height="30" basedata="iVBORw0KGgoAAAANSUhEUgAAAB0AAAAeCAYAAADQBxWhAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAMuSURBVEhLlZcBlatADEWxUAu1gAUs1AIWsIAFLGChFmphLXwL83ND3jQwlO5yTg6FmcnNSzLDbtf97io27Zv9ztOHWY3zZezKOHSl7/ud8Y6x1/IxoK+BOGwd+zIN99LfN4dnQGAVuG5zmD8Nt7I87u6D55SdU3jh2hZuwPK6lfJvKq9wmkH/nhtId+bPBvtZRgeOva219WQgZaEB++DjfqtQHArs9wjCnVkgCoZ1QIGhEuBgfvyyoJlPgKG6gn1AwKo0FjjcfisIqXOwAW83MysLqZ0MyD0r9Wy9a/6GKloBH7YYZx4plwUlqGBE70CZgVGaU4xifJ+pdZWkRw0AlGhx+JwDHmnNsN7GZahVioFLsac66ptTvKXFjNr0/bB1LvWxptqpCVUERaAC4hgo5kAbVxdL7THFNSUZiuPF1KvW+TdjlAKHgAVFicCoJtVqLvf93kZbWngxPMaqVGpwzsLcaAIKChgYUHxUxWquyCTzleK6TaZp9kUMKEJg7jwiBahtIZVZrXwo3Vp3VEobOyxDmQSw7rc4KDwjEUhOsdTiY56X6ktwZSKfED4Rk1Lvutir+XTxIy8aqnZudLHv14BmMM15PBxc6bI+a4SLPb/Mfsxstt95xhjDprCH3TGeee/1XNed2jOoR5ehcpDBGX4FPkJzyZrUCkp6z5RK7TelW9bWRm1z9qqeiupuCzF92vR505fm7MDQO5zj75jiBiqYmsj3KJ+naCR9VThVCEDj3POW4FlQ+fQT7qqRmMgiTpLnNOzA+qThmDHN4aSabe9iOnGkUh181rnevdlwxB4kZXIodfrQa85RtdQefF7+2eIKstJcP4BSmefxTor9UIk0f/0DKSb4YlSycPCvzvuPMaLXYc88zdV81fjP0FwrAcdxLJhvB4NltfzOSinHX6A7lR61qcxAg9reP1d7Udvv9VTU27e1gfaf1CrdufGimVhj294Dbq5ayw9AOx072a621FSW925AR7vb8dwBb8CeXprnuIXseTazE3BnzX7NezZ8EOQl1OsVRmRMxrLC4++r/2/wMYTCj+kl34CZICMlR5Oj4/u8ThD8NSn9D9wL1z9uxdBdAAAAAElFTkSuQmCC"> <vector name="origin" x="-2" y="30"/> </canvas> <canvas name="iconRaw" width="29" height="29" basedata="iVBORw0KGgoAAAANSUhEUgAAAB0AAAAdCAYAAABWk2cPAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAL4SURBVEhLlZYBtYMwDEVnAQuzgAUsYAELWMACFrAwC7MwC99Cf27o6wJ0sO2cHAZNc/PStHC7ffdL5nZl30X64HUIPg+3NHS31LbtxnjG2HP+mNBlIg5bhjaN3T219zVgDQisAJfVB/+xa9Lc3z0G96E6VXjit05cgenZpPQ3pmcOGkF/jxWkK/6TwV7z4MChtbk2nwqEKhzAPtjfmwIloMB+zUl4MEtEyTAPKDBUAuwsjv8safxJMKsuYB8QsCjNExxu/5WE1DnYgE1jZstCaUcDco1KvVrvNX9Dla2AvU0mmGfKz5ISVDCyd6DMwCiNJUYxsWtqXSXlUQMAJVsCPqYMz2WNsNbGZahViYFLsZc6r28s8VoWM9ambbu1c1kfa6qNmqyKpEhUQAIDxRxo4+piqd2XuJQkQgk8m3qtdfzPGEtBQMCCokRgVFNqNZfHfm+jtSw86PqhKJUagjMxNpqAggIGBpQYRbGaK1cSf5W4bJNxnHwSA8oQmAfPmQLUtpDKqFYxVG7N2yuljR0WoTgBLPstHxRekZxILLHUEmOa5hJLcFUinhDuiEmpd13eq/F08SMvN1Tp3NzFvl8zNIJpzv3h4Ern5VEynO3+afYyM2+/co8xho3Zerti3PPc13NZNmprUM8uQhUggiP8DLyHxiU7lFZQyltTKrVXSteqLQe1h7NX66ms7jYR06tNrze9aWoHhp4RnHj7Eh+ggqmJfI/yesqNpLcKpwoJaJxr3BLcC6qYfsKdNRKOTOIkeYzdBqxXGoEZkw8n1WR7F9OJI5Xq4FrnevdGIxB7kJIpoNTpRS+fvWqp3cU8/WxxBVFpXD+AUhn9eCbFfqjkMl9+IGUHn4xKJnb+1nl/jJG9Dnv85Ct/rfHP0LhWAg7DkDDfDgaLavkflbIcv0A3Kj1rUxmBqkZN7cnaXq+nsl7frXVoTa3KHRvvU9duTiatzQlQ/pu1ZZ4s7t2voGRL8+y30If6HPZr3LPfAIuCX5wryV1+1QP6B07yxunYFCcQAAAAAElFTkSuQmCC"> <vector name="origin" x="-2" y="30"/> </canvas> <string name="islot" value="Ma"/> <string name="vslot" value="Ma"/> <int name="reqJob" value="1"/> <int name="reqLevel" value="40"/> <int name="reqSTR" value="130"/> <int name="reqDEX" value="0"/> <int name="reqINT" value="0"/> <int name="reqLUK" value="0"/> <int name="incDEX" value="3"/> <int name="incMMP" value="10"/> <int name="incPDD" value="45"/> <int name="tuc" value="7"/> <int name="price" value="6700"/> <int name="cash" value="0"/> </imgdir> Say I want to get reqJob and print it onto the page. Also I would need to get the BaseData of the iconRaw canvas. I just can't wrap my head around it, but I am trying to integrate weather into my website using NOAA. 1. Here is the NOAA page: http://forecast.weather.gov/MapClick.php?CityName=Mio&state=MI&site=APX&lat=44.663&lon=-84.1446 2. Here is the XML to that page: http://forecast.weather.gov/MapClick.php?lat=44.66300&lon=-84.14460&FcstType=dwml Now what I want to do is to have PHP on my website that reads the XML from the NOAA site and create the "Forecast At A Glance". Possible or too challenging? The following script just validates some form inputs, and then puts any errors inside an array. I get this error: Fatal error: Cannot use [] for reading in C:\xampp\htdocs\Game\includes\validation.php on line 104 I've looked around, and this still does not make any sense to me. public function ValidateEmail($email, $reemail){ /* Sanatize. User filter_var to validate. Make sure both emails match. Check if email already exists or not. */ trim($email); strip_tags($email); mysql_real_escape_string($email); trim($reemail); strip_tags($reemail); mysql_real_escape_string($reemail); if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $this->valid = false; //Line 104 $this->error[] - "The E-Mail that you provided is not valid."; } else { $this->valid = true; } if($email !== $reemail){ $this->valid = false; $this->error[] = "The E-Mail's that you provided do not match."; } else { $this->valid = true; } if(filter_var($email, FILTER_VALIDATE_EMAIL) && $email == $reemail){ $checkmail = mysql_query("SELECT users.email, temp_users.email FROM users, temp_users WHERE email = '$email'"); if(mysql_mum_rows($checkmail) == 1){ // email is found, throw out error $this->valid = false; $this->error[] = "That E-Mail is already in use."; } else { $this->valid = true; } } return $this->error; } Line 104 is commented out. Thanks! how can I read a url coming from another site by header('Location:') command [xml]<category id="SOCMENEURASTVICLEA" order="26800">Aus. Victoria League</category>[/xml] I have the above xml, I can read the category id, order but I dont no how to read the value "Aus. Victoria League" foreach($description->children() as $category) { foreach($category->attributes() as $a => $b) { echo "<br/> -------- "; echo $a,'="',$b,"\"\n"; } echo "category name" . $category->asXML(); } the asXML() i have no idea what that is but am guessing I need thats where the php function which returns the value needs to go Thank you I've never been very good with arrays, and am totally new to them in PHP... If I have this array... Code: [Select] $concertDates = array('201105071'=>'May 7, 2011 (9:00am - 12:00pm)', '201105072'=>'May 7, 2011 (1:00pm - 4:00pm)', '201105141'=>'May 14, 2011 (9:00am - 12:00pm)'); ...and I know the key, e.g. Code: [Select] $concertDate = '201105072' Then how do I get the corresponding value, i.e. Code: [Select] May 7, 2011 (1:00pm - 4:00pm)' ...from the array?? Debbie Hi People. Here is a form that is supposed to read from my database. My primary key is called "index" and I have about 300 records in the database. I wanted to be able to view the records but when I load this page the "php" part is empty. I simply get given a blank form. I know it is connecting to the DB OK because I changed one letter in the password and then got a "can't connect to the database error" just to test it out. Code: [Select] <?php $host = 'localhost'; $usr = "the_db_user"; $password = 'not_shared_on_forum'; $db_name = 'stranded'; function cr($string){ $clean_string = str_replace("rn","<BR>",$string); return $clean_string; } //$id = 11; if (!isset($id)) $id = $_GET['id']; mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $read_query = "select * from HelperFormData where index = '$id'"; $results = mysql_query($read_query); $rs = mysql_fetch_array($results); ?> <!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> <style type="text/css"> <!-- body,td,th { font-size: 12px; } --> </style></head> <body> Surname: <? echo $rs["surname"]; ?> <table width="500" border="1" bordercolor = "#2c2cf6" textcolor = "#2c2cf6"cellspacing="1" cellpadding="2"> <tr> <td colspan="5">Record number: <? echo $rs["index"]; ?></td> </tr> <tr> <td width="120" bgcolor = #E6F8EB>Surname</td> <td width="120" bgcolor = #E6F8EB>First Name</td> <td width="120" bgcolor = #E6F8EB>phone1</td> <td width="120" bgcolor = #E6F8EB>phone2</td> <td width="120" bgcolor = #E6F8EB>Location</td> </tr> <tr> <td bgcolor = #E6F8EB textcolor = #AC1636><strong><? echo $rs["surname"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["firstname"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["phone1"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["phone2"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["location"]; ?></strong></td> </tr> <tr> <td bgcolor = #dbeff8>Qualifications</td> <td bgcolor = #dbeff8>Expertise</td> <td bgcolor = #dbeff8>Assistance</td> <td bgcolor = #dbeff8>Languages</td> <td bgcolor = #dbeff8>E-Mail</td> </tr> <tr> <td bgcolor = #dbeff8><strong><? echo $rs["qualifications"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["expertise"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["assistance"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["languages"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["e_mail"]; ?></strong></td> </tr> <tr> <td bgcolor = #E6F8EB>Consent</td> <td bgcolor = #E6F8EB>Published</td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> </tr> <tr> <td bgcolor = #E6F8EB><strong><? echo $rs["consent"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["radio_callsign"]; ?></strong></td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> </tr> <tr> <td colspan="5"><p>Comments:<br /> <strong><? echo $rs["comments"]; ?></strong></td> </tr> </table> </body> </html> </html> Hi there I am working on PHP form which has an array named: $productOptions. When I do: print_r($productOptions); it returns: Array ( [124] => Array ( [optionId] => 124 [optionName] => acer aspire [optionListId] => 28 [dateCreated] => 2010-11-04 12:48:53 [enabled] => 1 [optionQtyId] => 84 [productId] => 40 [quantity] =>7 ) [114] => Array ( [optionId] => 114 [optionName] => acer fast [optionListId] => 28 [dateCreated] => 2010-11-01 02:04:53 [enabled] => 1 [optionQtyId] => 83 [productId] => 40 [quantity] => 0 ) Now from this Array, I would like to check if the quantity if greater than Zero. so I tried: if (productOptions[quantity] > 0){ echo "blah blah..." } But for getting the quantity, the part: productOptions[quantity] returns nothing. Am I doing this correctly? Please reply. Thank you I am trying to go through all of the emails in an inbox with php. I saw a way to do it with imap_open, but I don't have the imap functions installed. Does anyone know of another way to do this? I would think someone would have written a 3rd party library that just uses sockets -- kind of like phpmailer but for receiving instead of sending. I am trying to use this weeklyReport1Boles.html: Code: [Select] <html> <head> <title>Weekly Report</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>Weekly Report</h1> <p> <form action = "weeklyReport1Boles.php" method = "post" > <p> <input type = "submit" value = "Display the Report" /> </p> </form> </body> </html> TO PULL data from weeklyDataBoles.txt lines 1-8 1 236.00 2 284.00 3 148.00 4 128.00 5 0.00 6 110.00 7 0.00 8 THE RESULTING WEB PAGE SHOULD BE: Weekly Report TOTAL INCOME FROM PAINT CONTRACTS: $0.00 AVG DAILY INCOME FROM PAINT CONTRACTS: $0.00 NUMBER OF DAYS with NO INCOME: . MY PHP CODE IS: <?php $total = $_POST['total']; $avgDailyIncome = $_POST['avgDailyIncome']; $badDays = $_POST ['badDays']; $paintFile = fopen("weeklyDataBoles.txt","r"); $year = fgets($weeklyDataBoles); $total = 0; for ($count= 1; $count <=7; $count = $count +1) { $nextDay = fgets($weeklyDataBoles); $total = $total + $nextDay; } fclose($weeklyData); $avgDailyIncome = $total/7; print("<p>TOTAL INCOME FROM PAINT CONTRACTS: "); print("$".number_format($total, 2)."</p>"); print("<p>AVG DAILY INCOME FROM PAINT CONTRACTS: "); print("$".number_format($avgDailyIncome, 2)."</p>"); print("<p>NUMBER OF DAYS with NO INCOME: $badDays.</p>"); ?> </body> </html> THE AVERAGES ARE BASED ON ONE WEEK OR SEVEN DAYS, WHY CANT I OPEN THE FILE AND GET THE PROGRAM TO READ IT, I AM A STUDENT AND VERY, VERY, VERY BAD AT THIS, MAKES ME CRAZY CAUSE I REALLY LOVE IT I have been studying PHP for a long time. I can write a simple PHP guestbook now. But you know, it's so so so simply, even the green hand can attack on my site. I want to improve my PHP skill, so i decide to read a big php program such as a shopping cart. Finally i choose the cart Eclime. But when i read the code, i find it's so difficult for me to understand it. Maybe i am in the wrong way to study PHP. Anyone tell me what i should do now ... Hi all, how do I read emails sent to an email account on my site such as admin@mysite.com? hi i am a making a site in which m saving a songs information in database then fetching that out for inserting song link m using readdir function that read all song in a folder then save them in database but i have problem when that read file name .mp3 also include with that which i don't want to show on page where i fetch that mean simply i want that i can insert song name separately and file separately... and i want to use readdir also for getting file name becoz that easy way instead of upload through panel ..? any idea or solution about adding separately file name |