PHP - Array In Order To Work With The Data: Beginner Question
Hello dear friends, hello community,
i want to parse a site http://www.aktive-buergerschaft.de/buergerstiftungsfinder Well therefore i have a true beginner-question regarding Array in order to work with the data: beginner question The results should be stored in a MySQL-Database: well you see. i have a Curl-Approach: and i want to work with the parsed data: and in this case i want to give over the data into an array (if viewing the output in web browser, do view-source to see structured array). Here the musings that led to the code: Depending on num dimensions, we could do, foreach($result as $k => $v) {echo $k." ".$v} to view and work with data (adding sub foreach loops accordingly; i.e. if $v is itself an array) see the results: What do you think: Code: [Select] $ch = curl_init("http://www.aktive-buergerschaft.de/buergerstiftungsfinder"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $buffer = curl_exec($ch); curl_close($ch); $result = explode(",", $buffer); foreach($result as $k => $v) {echo $k." ".$v} if $v is itself an array) // print_r($result); look forward to hear from you!! db1 Similar TutorialsOk I am testing foreach in an array as my practice. I wonder how can I assign values in the key of the array.. Here's the code Code: [Select] <?php $username = me_mysql_prep(trim($_POST['username'])); $first_name = me_mysql_prep(trim($_POST['first_name'])); $last_name = me_mysql_prep($_POST['last_name']); $email = me_mysql_prep($_POST['email']); $position = me_mysql_prep($_POST['Position']); $password = me_mysql_prep($_POST['password']); $hashed_password = sha1($password); $required_fields = array($username,$first_name,$last_name, $email, $position, $password); foreach($required as $key => $value) { if($value == "") { echo $key . " Cannot be empty<br>"; } } ?> So the result would be like this... IF username, first name and last name are EMPTY it will echo: Quote username cannot be empty first name cannot be empty last name cannot be empty Anyone? Hello everyone.
I have some code that I need some assistance with. By the way I am using CentOS 6.5 on my Linux server.
Here is my current code:
<html> <head></head> <body> <?php if (!isset($_POST['q'])) { ?> <img src="/wvb-logo-slogen.png" border="0" /> //code for logo <h2>Search</h2> <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" /> </form> <?php } else { ?> <img src="/wvb-logo-slogen.png" border="0" /> //code for logo <h2>Search Results</h2> <?php try { // create object // $swish = new Swish('/usr/local/apache/htdocs/swish/index.swish-e'); $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from command-line $queryStr = htmlentities($_POST['q']); $result = $swish->query($queryStr); ?> Found <?php echo $result->hits; ?> match(es) for '<?php echo $queryStr; ?>'. <?php // iterate over result set // print details for each match while($r = $result->nextResult()) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (sco <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> <?php $file = '/var/www/html/active_colist.csv'; $fh = fopen($file, 'r'); $companies = array(); $row = fgetcsv($fh, 1024); // ignore header while ($row = fgetcsv($fh, 1024)) { $companies[$row[0]] = array('company' => $row[1], 'country' => $row[3]); //changed line } fclose($fh); //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $wvb_number = substr($filenames[1],1,12); $country = substr($filenames[1],1,3); echo 'Country: '.$companies[$wvb_number]['country']."<br />"; //echo 'Country Name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year."<br />"; //$filenames = explode(".", $r->swishdocpath); //$wvb_number = substr($filenames[1],1,12); echo 'WVB Number: '.$wvb_number."<br />"; echo 'Company Name: '.$companies[$wvb_number]['company']; ?> </p> //Suggested Pagination code. <?php ///////////////FILLING ARRAY WITH DUMMY DATA//////////////////// $key = array(); for($i=0; $i<200; $i++) { //fill array data $key[] = "num = ".$i; } //////////////////////////////////////////////////////////////// /////////////////////START OF ARRAY PAGINATION CODE///////////////////// $ptemp="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $pt=explode('&',$ptemp); if (strpos($ptemp,'pageno')) array_pop($pt); $pt=implode('&',$pt); $ptemp=$pt; $array=$key; // REPLACE $KEY WITH YOUR ARRAY VARIABLE $page = $_REQUEST['pageno']; $currentpage = isset($page) ? (integer)$page : 1; $numperpage = 10; //NUMBER OF RECORDS TO BE DISPLAYED PER PAGE $total = count($array); $numofpages = ceil($total / $numperpage); //TOTAL NUMBER OF PAGES if(isset($array)) { if (($currentpage > 0) && ($currentpages <= $numofpages)) { //STARTING LOOP FOR ARRAY DATA $start = ($currentpage-1) * $numperpage; for($i=$start;$i<=($numperpage+$start-1);$i++) { ///////////PLACE YOUR CODE HERE////////////////////////// echo $array[$i] .' '; //////////////////////////////////////////////////////// } } } if ($currentpage != 1) { //GOING BACK FROM PAGE 1 SHOULD NOT BET ALLOWED $previous_page = $currentpage - 1; $previous = '<a href="'.$ptemp.'?pageno='.$previous_page.'"> <</a> '; } $pages = ''; for ($a=1; $a<=$numofpages; $a++) { if ($a == $currentpage) $pages .= $a .'</u> '; else $pages .= '<a href="'.$ptemp.'?pageno='.$a.'" >'. $a .'</a> '; } $pages = substr($pages,0,-1); //REMOVING THE LAST COMMA (,) if ($currentpage != $numofpages) { //GOING AHEAD OF LAST PAGE SHOULD NOT BE ALLOWED $next_page = $currentpage + 1; $next = ' <a href="'.$ptemp.'?pageno='.$next_page.'"> ></a>'; } echo ' '. $previous . $pages . $next; //PAGINATION LINKS /////////////////////END OF ARRAY PAGINATION CODE///////////////////// ?> <?php } } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } } ?> </body> </html>As you can see from the code above when I implemented that code into my script I was able to get it to display but only after the </p> marker. When I did that I got the following results. Results: Found 736 match(es) for 'test'. 1 ./ITA000030192.2013.A.00.L.12.31.PDF (sco 1000) ./ITA000030192.2013.A.00.L.12.31.PDF Country: Italian Republic (Italy) Year: 2013 WVB Number: ITA000030192 Company Name: BEGHELLI num = 0 num = 1 num = 2 num = 3 num = 4 num = 5 num = 6 num = 7 num = 8 num = 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > 2 ./ITA000030164.2013.A.00.L.12.31.PDF (sco 976) ./ITA000030164.2013.A.00.L.12.31.PDF Country: Italian Republic (Italy) Year: 2013 WVB Number: ITA000030164 Company Name: CREDITO EMILIANO num = 0 num = 1 num = 2 num = 3 num = 4 num = 5 num = 6 num = 7 num = 8 num = 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > 127 ./IND000102048.2012.A.00.E.03.31.PDF (sco 457) ./IND000102048.2012.A.00.E.03.31.PDF Country: Year: 2012 WVB Number: IND000102048 Company Name: num = 0 num = 1 num = 2 num = 3 num = 4 num = 5 num = 6 num = 7 num = 8 num = 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > 128 ./NLD000030064.2013.A.00.E.12.28.PDF (sco 457) ./NLD000030064.2013.A.00.E.12.28.PDFThe results page shows that there are 736 matches. There are currently 5000 PDF files in the /var/www/html/pdf2 directory. What I am trying to accomplish in terms of pagination is twofold. First get the above page links to display on the top and bottom of the page and only display 10 results at a time on each page. Second have the links working correctly so that they can go to the correct results. Can this be accomplished with the above pagination code where it states //Suggested pagination code? Do I need to change my layout? Furthermore I was also told that I should focus on the following lines of code: <?php ///////////////FILLING ARRAY WITH DUMMY DATA//////////////////// $key = array(); for($i=0; $i<200; $i++) { //fill array data $key[] = "num = ".$i; }as well as the result variable $queryStr = htmlentities($_POST['q']); $result = $swish->query($queryStr);What would I need to change in these two areas in order to get what it is that I am trying to accomplish. Sorry for the large post. Any assistance would be greatly appreciated. Hi, I'm trying to explode an array into a multidimensional array using <br /> tags as splitters but just can't get the syntax right! I can do lines of the array one by one, but not the whole lot at once. I'd really appreciate a quick example of an explode inside an array. $myarray looks something like this with print_r: ( [0] => [1] => some_html<br />some_html<br />some_html<br /> [2] => some_html<br />some_html<br />some_html<br /> [3] => some_html<br />some_html<br />some_html<br /> ) and I want to turn it into this: ( [0] => [1] => [0]some_html [1]some_html [2]some_html [2] => [0]some_html [1]some_html [2]some_html [3] => [0]some_html [1]some_html [2]some_html ) I've tried this $myarray = explode ("<br />", $myarray); but it doesn't work … It doesn't matter too much if there's are a few empty lines in the array from the final <br /> tags. Many thanks, as ever, for any help. <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="stylesheet.css"> <meta charset="utf-8"> </head> <body> <?php $array = array(); echo "<table>"; for ($z=0; $z <=9; $z++) { echo "<tr>"; for ($s=0; $s <=9; $s++) { $r = mt_rand (1, 100); array_push ($array, $r); if ($r %2 != 0) { echo "<td bgcolor = red>"; echo $r; echo "</td>"; } else { echo "<td bgcolor= lightgreen>"; echo $r; echo "</td>"; } } echo "</tr>"; } echo "</table>"; echo "<br>"; echo "<table>"; sort($array); $arraysplit = array_chunk($array, count($array)/10); for ($z=0; $z <=9; $z++) { echo "<tr>"; for ($s=0; $s <=9; $s++) { if ($r %2 != 0) { echo "<td bgcolor = red>"; echo json_encode (arraysplit); echo "</td>"; } else { echo "<td bgcolor= lightgreen>"; echo json_encode ($arraysplit); echo "</td>"; } } echo "</tr>"; } ?> </body> </html> Hey absolute beginner here. Im working on a table that gives random numbers out and then colorizes them if they can be devided by 2. That works fine. Now i want to get those randomly generated numbers into a second table but sorted. I already managed to put the numbers i generated into an array and sort it but i cant figure out how to echo them 1 by 1 into the table. Maybe you can help me out. Hi all For example if you see this code: public function __set($varName,$varValue) { $this->$varName = $varValue; if ($varName == "varOne") { $this->varTwo = $this->varOne * 9; } } Why somewhere dollar sign exists and somewhere not: $this->$varName , $this->varTwo ? Thanks Any idea why I cant get the order by to work? $res = mysql_query ("SELECT COUNT(*), LEFT(`comment`, 3) AS truncated from comments where navn='$rows[navn]' AND adresse='$rows[adresse]' ORDER BY time desc" ) or die(mysql_error()); Hello all, I need to make a rotating banner system for a client. They want about 5 banners to rotate with Javascript. However they want the visitor to sort of step through each one on each refresh. So if I have 5 banners and I go to the site, I see banner 1 and then the javascript rotates through each one. When I go back to the site, they want it to start with banner 2 and then the javascript will rotate through each one. Then on and on. Go back and see banner 3, then step through again. I have a nice Javascript image slider I'd like to use. It basically just requires the images in order. Like: <img src="1.jpg"/> <img src="2.jpg"/> <img src="3.jpg"/> <img src="4.jpg"/> <img src="5.jpg"/> I've thought about it and I think the best way to do this would just be using PHP and a cookie. So when the viewer first goes to the site, PHP checks for the cookie. If it exists, it pulls the starting image #. If it doesn't, it starts at 0 and sets the cookie. As for the images part, I figured an associate array would work well. The key would be what the cookie logic is based on, and then the image HTML would be in the array. So you visit the site without a cookie it would be... 0 => <img src="1.jpg"/> 1 => <img src="2.jpg"/> 2 => <img src="3.jpg"/> 3 => <img src="4.jpg"/> 4 => <img src="5.jpg"/> Then when you go back to the site, I need the array to be re-ordered like this: 0 => <img src="2.jpg"/> 1 => <img src="3.jpg"/> 2 => <img src="4.jpg"/> 3 => <img src="5.jpg"/> 4 => <img src="1.jpg"/> What's the best way to go about this array logic? My experience with manipulating data inside arrays is rather limited. Basically I need it to say "Start with key # and then reorder array based on that" I have a search box with an input box. When the user enters a string in this box and then when it clicks submit, the form needs to go to the http://ww.mywebsite.com/wp-content/uploads/<?php echo $_POST["name"]; ?>.jpg where $_POST["name"] is what the user entered. how to make it work?? <form action="http://ww.mywebsite.com/wp-content/uploads/<?php echo $_POST["name"]; ?>.jpg" method="post" target="_blank"> <!-- form fields here --> <INPUT TYPE = "Text" NAME = "name"> <input type="submit" /> </form> i am brand new to php and thought a project looking at the weather undergound api would be a great place to "cut my teeth" and i am following up on a recent post i saw here http://www.phpfreaks.com/forums/index.php?topic=354658.msg1675207#msg1675207 the responder excellently described how to use the foreach function however i am not sure this is right for my application the project i am trying to accomplish is defining the freeze thaw cycle for the next ten days which i can accomplish in excel but thought this is a good way to learn to code. so my question is how should i do this, i have tried and failed with trying to pick out individual highs and lows data and define them as above or below freezing but i can't figure out how to pick out the right number my code for this part of the project is $json_line = file_get_contents("http://api.wunderground.com/api/{key}/geolookup/forecast10day/q/$zipcode.json"); $parsed_line = json_decode($json_line); echo $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'date'}->{'weekday'}; $temp_h = $parsed_line->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'high'}->{'farenheit'}; $temp_l = $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}->{'low'}->{'farenheit'}; echo "Forecast for ${day} is:\n"; echo "High Temp is ${temp_h}<br />"; echo "Low Temp is ${temp_l}\n"; another road i was looking at going down was trying to do an array shift any help would be greatly appreciated thanks jeremy I'm a beginner with php, but I have a few nifty things working, and I'm trying to enhance my project to do something at the next level. The project is a library database search tool, and I'm having trouble getting from the search results to the page which shows a record for an individual book. The search tool works well, and works a few different ways, so I feel I should be able to get this, but this is a first attempt.
I'm stuck on where and how to use $_GET. If I understand what I need to do, it's something like this:
My search results page has a link as part of the last column:
My first question is, how do I parse this link in php so that it pulls the Id. number from the database, (so that "Link" points to /book.php?0140441638 as a uri? That column looks something like this:
On the next page, (book.php) which should be the page which shows the information for the individual book, after connecting to my database I have $query="SELECT * FROM MyTable WHERE id='0140441638'". How would I go about passing the '0140441638' from the referring link?
The next question is how to concatenate this with the openlibrary link in the screenshot -- so that it is passed like src='..//covers.openlibrary.org/b/isbn/**RESULT**-L.jpg' />
Thank you to anyone who can help me with this!
My table has 250 rows, but COUNT only seems to see 162 of them. In phpMyAdmin, for instance, there is a notice in the browse tab: "Showing rows 0-161 (162 total, Query took 0.0030 sec)". On one of my php pages, I get the same 162 result from this attempt to count the number of entries to my auto-incrementing "id" column :
$result = mysql_query('SELECT COUNT(id) AS id_count FROM MyTable)';Can anyone suggest the kinds of things I should check/adjust to understand why about 90 rows are not being counted? Many thanks in advance for any help anyone can offer. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=354151.0 Hello dear php-experts - good day. note; i run linux opensuse 13.1 the final goal is to get stored some xml-files in a mysql-database. thats what i am looking for. - the xml-files are derived from a osm-request - at a OpenSteetpmap-api. and thats why i am here. Guess that you are good php and mysql-experts well i play around with some openstreetmap-requests - and want to store the results in a Mysql-db. see the tags: id lat lon name amenity operator vendingsee the table 'pois' that i want to create - and subsequently create some columns see the SQL-Script CREATE DATABASE `db123` DEFAULT CHARACTER SET latin1 COLLATE latin1_german2_ci; USE hans; CREATE TABLE `pois` ( `id` BIGINT(20) UNSIGNED NOT NULL, `lat` FLOAT(10,7) NOT NULL, `lon` FLOAT(10,7) NOT NULL, `name` VARCHAR(255) COLLATE utf8_bin NOT NULL, `amenity` VARCHAR(255) COLLATE utf8_bin NOT NULL, `operator` VARCHAR(255) COLLATE utf8_bin NOT NULL, `vending` VARCHAR(255) COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; first of all i thought that i can do the db creation with some hard coded methods: but instead of hard-coding the required column names as in $fields = array('id','lat','lon','name','amenity','operator','vending'); we could use this to pick up any additional columns added to your pois table $sql = "SHOW COLUMNS FROM pois"; $fields = array(); $res = $db->query($sql); while ($row = $res->fetch_row()) { $fields[] = $row[0]; } btw: see the data <node id="2064639440" lat="49.4873181" lon="8.4710548"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="turkish"/> <tag k="email" v="info@lynso.de"/> <tag k="name" v="Kilim - Café und Bar Restaurant"/> <tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/> <tag k="operator" v="Cengiz Kaya"/> <tag k="phone" v="06 21 - 43 755 371"/> <tag k="website" v="http://www.kilim-mannheim.de/"/> </node> <node id="2126473801" lat="49.4851170" lon="8.4756295"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="mannheim1@vapiano.de"/> <tag k="fax" v="+49 621 1259 779"/> <tag k="name" v="Vapiano"/> <tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/> <tag k="operator" v="Vapiano"/> <tag k="phone" v="+49 621 1259 777"/> <tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/> <tag k="wheelchair" v="yes"/> </node> <node id="667927886" lat="49.4909673" lon="8.4764904"> <tag k="addr:city" v="Mannheim"/> <tag k="addr:country" v="DE"/> <tag k="addr:housenumber" v="5"/> <tag k="addr:postcode" v="68161"/> <tag k="addr:street" v="Collinistraße"/> <tag k="amenity" v="restaurant"/> <tag k="name" v="Churrascaria Brasil Tropical"/> <tag k="phone" v="+496211225596"/> <tag k="wheelchair" v="limited"/> </node> <node id="689928440" lat="49.4798794" lon="8.4853418"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="greek"/> <tag k="email" v="epirus70@hotmail.de"/> <tag k="fax" v="0621/4407 762"/> <tag k="name" v="Epirus"/> <tag k="opening_hours" v="Mo-Sa 12:00-15:00,18:00-24:00"/> <tag k="phone" v="0621/4407 761"/> <tag k="smoking" v="separated"/> <tag k="website" v="http://epirus-ma.blogspot.com/"/> <tag k="wheelchair" v="no"/> </node> <node id="689928445" lat="49.4799409" lon="8.4851357"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="gianlucascurti@ristorante-augusta.de"/> <tag k="name" v="Ristorante Augusta"/> <tag k="opening_hours" v="Mo-Fr 12:00-14:00,18:00-23:00;Su 12:00-14:00,18:00-23:00"/> <tag k="phone" v="0621 449872"/> <tag k="website" v="ristorante-augusta.com/"/> <tag k="wheelchair" v="no"/> </node> with the following fields in the db: CREATE DATABASE `db123` DEFAULT CHARACTER SET latin1 COLLATE latin1_german2_ci; USE hans; CREATE TABLE `pois` ( `id` BIGINT(20) UNSIGNED NOT NULL, `lat` FLOAT(10,7) NOT NULL, `lon` FLOAT(10,7) NOT NULL, `name` VARCHAR(255) COLLATE utf8_bin NOT NULL, `amenity` VARCHAR(255) COLLATE utf8_bin NOT NULL, `operator` VARCHAR(255) COLLATE utf8_bin NOT NULL, `vending` VARCHAR(255) COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; EDITED BY MODERATOR - DB CREDENTIALS REMOVED see the dataset; - which is stored in the file mysql.txt the dataset - it is gathered from the request on the overpass-api which resides here http://www.overpass-turbo.eu cf. http://overpass-turb...Pg&c=BNJBWRBb1P you see a request on the left part of the screen note: to get the output - just press the button in the top-menu called "Ausführen" after this you press the button called "DATEN" on the top-right - just below the green button called "flatter this": after pressing this "DATEN"-button you see the data in the right window of the screen. note - it has got various ids - that means that the osm-file does not give back constantly all the tags... the last question; does this make any problems to our project - does this has any influence on our db-connection...!?!? see the output he <node id="2064639440" lat="49.4873181" lon="8.4710548"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="turkish"/> <tag k="email" v="info@lynso.de"/> <tag k="name" v="Kilim - Café und Bar Restaurant"/> <tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/> <tag k="operator" v="Cengiz Kaya"/> <tag k="phone" v="06 21 - 43 755 371"/> <tag k="website" v="http://www.kilim-mannheim.de/"/> </node> <node id="2126473801" lat="49.4851170" lon="8.4756295"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="mannheim1@vapiano.de"/> <tag k="fax" v="+49 621 1259 779"/> <tag k="name" v="Vapiano"/> <tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/> <tag k="operator" v="Vapiano"/> <tag k="phone" v="+49 621 1259 777"/> <tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/> <tag k="wheelchair" v="yes"/> </node> <node id="667927886" lat="49.4909673" lon="8.4764904"> <tag k="addr:city" v="Mannheim"/> <tag k="addr:country" v="DE"/> <tag k="addr:housenumber" v="5"/> <tag k="addr:postcode" v="68161"/> <tag k="addr:street" v="Collinistraße"/> <tag k="amenity" v="restaurant"/> <tag k="name" v="Churrascaria Brasil Tropical"/> <tag k="phone" v="+496211225596"/> <tag k="wheelchair" v="limited"/> </node> <node id="689928440" lat="49.4798794" lon="8.4853418"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="greek"/> <tag k="email" v="epirus70@hotmail.de"/> <tag k="fax" v="0621/4407 762"/> <tag k="name" v="Epirus"/> <tag k="opening_hours" v="Mo-Sa 12:00-15:00,18:00-24:00"/> <tag k="phone" v="0621/4407 761"/> <tag k="smoking" v="separated"/> <tag k="website" v="http://epirus-ma.blogspot.com/"/> <tag k="wheelchair" v="no"/> </node> <node id="689928445" lat="49.4799409" lon="8.4851357"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="gianlucascurti@ristorante-augusta.de"/> <tag k="name" v="Ristorante Augusta"/> <tag k="opening_hours" v="Mo-Fr 12:00-14:00,18:00-23:00;Su 12:00-14:00,18:00-23:00"/> <tag k="phone" v="0621 449872"/> <tag k="website" v="ristorante-augusta.com/"/> <tag k="wheelchair" v="no"/> </node> well you see that i have some questions the second one is regarding the variations in the mysql.txt - file - i.e. the different number of tags.; How to make the script robust so that it is able to work with this - and does not stopt to work....!? well i hope i was able to make clear what i want to achieve: can i use the code snippet to create the db table - we could use this to pick up any additional columns added to your pois table $sql = "SHOW COLUMNS FROM pois"; $fields = array(); $res = $db->query($sql); while ($row = $res->fetch_row()) { $fields[] = $row[0]; }note: i need to have a robust way - where i can cope with xmlfiles that are full with additionals tags /(that make it necessary to have more collumns added. I look forward to hear from you many many greetings Hi guys, I'm trying to sort an array. The array has information about listings. ID, name, info etc. An unrelated set of data also contains the listing ID's and I have made a function to sort this array and show an new order for the ID's. I now need to sort the original array by this new ID order... This snippet shows that the original listings array can be sorted by link_id: sort($this->links, $this->link->link_id); //This works. It sorts links by link ID! In a foeach loop I have created this: $sleeps_array[] = array("ID" => $link->link_id, "Sleeps" => $sleeps); // Makes an array of arrays of a custom field with listing ID. It makes this: array ( 0 => array ( 'ID' => '9', 'Sleeps' => '2', ), 1 => array ( 'ID' => '3', 'Sleeps' => '4', ), 2 => array ( 'ID' => '6', 'Sleeps' => '6', ), ) I can then sort this array of arrays with this function: function compare_sleeps($a, $b){ return strnatcmp($a['Sleeps'], $b['Sleeps']); } # sort alphabetically by name usort($sleeps_array, 'compare_sleeps'); It then gives me a sorted array according to "Sleeps" (as in, the number of people a property can cater for). It has the correct order of ID to then output but how do I organise the original array by ID with this new array? Sounds complicated, I hope you got that! Cheers, RJP1 I have a database of assorted. Each row contains defined QUANTITIES for each column item. Example: columns for shirt, tie, pants, socks. A row would indicate a purchase of 2 shirts, 1 tie, 0 pants, 3 socks for customer A. Followed by a row indicate a purchase of 1 shirts, 1 tie, 4 pants, 2 socks for customer B, etc. Now I want to sort EACH item, group them by quantity, and get an ordered list by quantity, that provides me with something like this: 1 shirt customer B 2 shirt customer C 3 shirt customer F 3 shirt customer H 4 shirt customer D, etc. I am using this code for my query: $query = "SELECT brisket, COUNT(brisket) FROM pass GROUP BY brisket ORDER BY brisket ASC"; but it is not organizing the info in a correlated manner. Help? Hi I can't get the ORDER BY to work correctly: Code: [Select] $getchallenges = safe_query("SELECT * FROM ".PREFIX."cup_challenges WHERE ladID='$laddID' AND challenger='$teamID' ORDER BY $order_date DESC"); while($gc=mysql_fetch_array($getchallenges)) { ... if($gc['finalized_date']) $order_date = "finalized_date"; elseif($gc['reply_date']) $order_date = "reply_date"; else $order_date = "new_date"; ... } Is it because of loop? echo "order = $order_date"; output: order = order = order = new_date What I'm trying to achieve is to order by the latest date, but I have 3 date columns: new_date reply_date finalized_date Is it possible to order by multiple columns where largest to smallest? Hi, I've been trying to re-order an array and I can't seem to even do it let alone neatly. I've ran out of time and would appreciate any help! $array = array( '0' => array( 'filepath' => 'files/image_site1.png', 'title' => 'Website', ), '1' => array( 'filepath' => 'files/image_id.png', 'title' => 'Identitity', ), '2' => array( 'filepath' => 'files/image_site2.png', 'title' => 'Website', ) ) I'm looking to re-order the arrays within the parent array depending on whether the 'filepath's contain a sub string of '_id' or '_site'. I've been using: $type = '_site'; foreach ($array as $item){ if (preg_match("/$type/i", $item['filename'])){ //add this $item to the top of array, somehow... } } So with $type set to '_site', I'd like to re-arrange the array so both arrays containing _site1.png and _site2.png appear at the top of the parent array. I.e: $array('0' = array(...), '2' => array(...), '1' => array(...)); I hope I've explained it well enough. Thanks, This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309973.0 I'm creating a tool for building project proposals for clients, with pricing. I have a database with two tables: services and clients. The services table looks like this: Code: [Select] | code | name | cost | +-------------+-------------+------+ | logo_design | Logo design | 10 | | web_design | Web design | 20 | The clients table looks like this: Code: [Select] | id | client | logo_design | web_design | +----+---------+-------------+------------+ | 1 | Walrus | yes | yes | | 2 | Narwhal | no | yes | How would I link the results from these two tables so that I only pull out the services each person wants from the database? Here is what I have so far: Code: [Select] <? $sql = "SELECT * FROM services"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo $row{'name'} . ': $' . $row{'cost'} . '<br />'; } ?> This, of course, displays all the services, with all the prices, like so: Logo design: $10 Web design: $20 I want to add something here so that based on the selected client, we see only the services/prices they selected (ol' Narwhal's page would not show the "Logo Design" line). I've got the data from "clients" pulled in to this page as well, but don't know how to relate it to "services." Thanks in advance! Let me know if I've left out any info that would help you to point me in the right direction. For example for my Skill Tree:
array (size=9) 0 => array (size=2) 'Skill_Id' => string '1' (length=1) 'Skill_Points' => string '0' (length=1) 1 => array (size=2) 'Skill_Id' => string '2' (length=1) 'Skill_Points' => string '0' (length=1) 2 => array (size=2) 'Skill_Id' => string '3' (length=1) 'Skill_Points' => string '0' (length=1) 3 => array (size=2) 'Skill_Id' => string '4' (length=1) 'Skill_Points' => string '1' (length=1) 4 => array (size=2) 'Skill_Id' => string '5' (length=1) 'Skill_Points' => string '1' (length=1) 5 => array (size=2) 'Skill_Id' => string '6' (length=1) 'Skill_Points' => string '1' (length=1) 6 => array (size=2) 'Skill_Id' => string '7' (length=1) 'Skill_Points' => string '0' (length=1) 7 => array (size=2) 'Skill_Id' => string '8' (length=1) 'Skill_Points' => string '1' (length=1) 8 => array (size=2) 'Skill_Id' => string '9' (length=1)For the Skill_Id, it must be in order when checking server side. 1 through 9. (or 9 can be changed by me whenever). So, I have: $skillrange = range(1,$amountofskills); Which will output: array (size=9) 0 => int 1 1 => int 2 2 => int 3 3 => int 4 4 => int 5 5 => int 6 6 => int 7 7 => int 8 8 => int 9But, how do I check this order from my original array? I need to check My Skill_ID values in order from my original array and make sure they are 1 through 9. (So a user cannot tamper the data) Edit: I've come up with this solution since making this thread: $array1 = $skillidarray; $array2 = $skillrange; if (!empty(array_diff_assoc($array1, $array2))){ echo "Your skill tree data is out of order, please report this to an administrator."; }Something like this would work right? Edited by Monkuar, 11 October 2014 - 03:59 PM. |