Jump to content

Drongo_III

Members
  • Posts

    579
  • Joined

  • Last visited

Posts posted by Drongo_III

  1. Hi Guys

     

    I recently started a new job but as I'm a bit inexperienced I need a dose of confidence before I start suggesting large changes.

     

    Primarily this is because the company I work for is HUGE and has multiple brands. But the sites are all 90% static with over 500 pages per site.

     

    I've never really worked on a large static site before, which is the source of my apprehensiveness, so I'd welcome some advice on the following - really just to confirm or disprove what my initial feelings are:

     

    1) My gut feeling is that a site of this size should be database/cms driven because it all relies on the developer to implement all changes and I can't see why it should be the case. It just causes everything to bottleneck. So would you agree that when a static site gets beyond a certain size a decent database driven system is the way to go?

     

    2) The site is comprised of countless include files. But it's not that that's bothering me. It's the fact a page includes a head file, which includes two other files and they in turn include further files. This can lead to a six level path of includes in some instances. As I said, I've only ever worked on database driven sites that are template based so all includes are pretty much included in one go and this dizzying back trace of include files feels plain wrong. Am I just being too picky?

     

    I kind of want to get off on the right foot and make sure that I don't perpetuate bad practices - which is kind of what the current setup feels like. But before I take over and step on anyone's toes I want to be sure I'm on firm ground and i'm not afraid to admit when i dont have the experience to make that call...

     

     

     

     

     

     

  2. Thanks Salathe - well i've certainly learned a lot from this post :)

     

    haha think i will refrain from trying to give answers to posts when i only undestand  half the story from now on...

     

    You're getting there. And trying to answer questions is a great way of learning! Every day is a school day.

  3. Ok i can see what you're saying.  I think i need to go away and practice with simplexml a bit more because through being inexperienced with simpleXML I am clearly trying to revert back to what seems logical to me (i.e. creating an array out of the data), but as you've pointed out, its probably replicating and bypassing what simpleXML was designed to do  :(

     

    Thanks for your patience guys!

     

    haha think i will refrain from trying to give answers to posts when i only undestand  half the story from now on...

     

     

    SimpleXML allows you to deal with an XML file as if it were an array.

     

    What you're doing is redundant.

     

    $xml['node']['subnode'] = 'value' isn't much different than $xml->node->subnode = 'value'

  4. Yes I realise that hehe...

     

    But I only did it that way because i was told doing this was wrong:

     

    foreach($package->children() as $k=>$gauge) {
    
    
    $topLevel[$k] = array(
    
    		'FifteenMinute'		=>  get_object_vars($gauge->FifteenMinute), 
    		'ThirtyMinute'		=>get_object_vars($gauge->ThirtyMinute), 
    		'OneHour'				=>get_object_vars($gauge->OneHour), 
    		'TwoHour'				=>get_object_vars($gauge->TwoHour), 
    		'FourHour'			=>get_object_vars($gauge->FourHour), 
    		'SixHour'				=>get_object_vars($gauge->SixHour), 
    		'TwelveHour'			=>get_object_vars($gauge->TwelveHour), 
    		'TwentyfourHour'	=>get_object_vars($gauge->TwentyfourHour)
    
    	);
    
    }
    

     

    which gives an array like:

     

    [bntCrk] => Array
            (
                [FifteenMinute] => Array
                    (
                        [sampleDate] => 8-28-2012
                        [sampleTime] => 20:40:15
                        [GaugeName] => BntCrk
                        [sampleValue] => 0
                    )
    
                [ThirtyMinute] => Array
                    (
                        [sampleDateStart] => 8-28-2012
                        [sampleDateEnd] => 8-28-2012
                        [sampleTimeStart] => 20:25:15
                        [sampleTimeEnd] => 20:40:15
                        [GaugeName] => BntCrk
                        [sampleValueAccumulation] => 0
                    )
    

     

    Which does give me a plain old array of the values as opposed to an array that is a direct replica of the object. So i think my whole confusion is centering around the fact that the above was pointed out as being wrong.

     

    Sorry guys i don't mean to be an idiot about this I just find it easier to deal with a large xml file if it's put into a simple array. But maybe i have it all backwards??

     

     

     

     

    Your array contains the same data as your object. What was the point of turning it into an array?

     

    If you want to access individual values

    <?php
    
    $xml = new SimpleXMLElement('http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGaugesAllIntervals', 0, true);
    header('content-type: text/plain');
    
    echo $xml->BntCrk->FifteenMinute->SampleDate;
    
    echo "\n";
    
    if( isset($xml->BntCrk->TwoHour->SampleValueAccumulation) )
    echo $xml->BntCrk->TwoHour->SampleValueAccumulation;
    else
    echo 'value does not exist';
    
    
    ?>

     

    Turning that into an array will not make anything easier, you'll just have the same data in memory twice.

  5. Yeah I realise this has gone a little beyond the original solution but I really am just trying to understand what was wrong with extracting the values because I cant see a solution if you don't.

     

    Lets say I did this (without extracting the object values):

     

    <?php
    
    $data_url = 'http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGaugesAllIntervals';
    $package  = new SimpleXMLElement($data_url, NULL, TRUE);
    
    $topLevel = array();
    
    foreach($package->children() as $k=>$gauge) {
    
    $topLevel[$k]  = array(
    
    		'FifteenMinute'		=>  $gauge->FifteenMinute, 
    		'ThirtyMinute'		=> $gauge->ThirtyMinute, 
    		'OneHour'				=> $gauge->OneHour, 
    		'TwoHour'				=> $gauge->TwoHour, 
    		'FourHour'			=> $gauge->FourHour, 
    		'SixHour'				=> $gauge->SixHour, 
    		'TwelveHour'			=> $gauge->TwelveHour, 
    		'TwentyfourHour'	=> $gauge->TwentyfourHour
    
    	);
    
    }
    
    
    
    echo "<pre>";
    
    
    print_r($topLevel);
    
    
    
    ?>
    

     

     

    I then get an array as follows:

     

    Array
    (
        [bntCrk] => Array
            (
                [FifteenMinute] => SimpleXMLElement Object
                    (
                        [sampleDate] => 8-28-2012
                        [sampleTime] => 20:20:14
                        [GaugeName] => BntCrk
                        [sampleValue] => 0
                    )
    
                [ThirtyMinute] => SimpleXMLElement Object
                    (
                        [sampleDateStart] => 8-28-2012
                        [sampleDateEnd] => 8-28-2012
                        [sampleTimeStart] => 20:5:14
                        [sampleTimeEnd] => 20:20:14
                        [GaugeName] => BntCrk
                        [sampleValueAccumulation] => 0
                    )
    
                [OneHour] => SimpleXMLElement Object
                    (
                        [sampleDate] => 8 - 28 - 2012
                        [sampleTime] => 20:20:15
                        [GaugeName] => BntCrk
                        [sampleValue] => 0
                    )
    
                [TwoHour] => SimpleXMLElement Object
                    (
                        [sampleDateStart] => 8 - 28 - 2012
                        [sampleDateEnd] => 8 - 28 - 2012
                        [sampleTimeStart] => 19:20:15
                        [sampleTimeEnd] => 20:20:15
                        [GaugeName] => BntCrk
                        [sampleValueAccumulation] => 0
                    )
    
                [FourHour] => SimpleXMLElement Object
                    (
                        [sampleDateStart] => 8 - 28 - 2012
                        [sampleDateEnd] => 8 - 28 - 2012
                        [sampleTimeStart] => 17:20:15
                        [sampleTimeEnd] => 20:20:15
                        [GaugeName] => BntCrk
                        [sampleValueAccumulation] => 0
                    )
    
                [sixHour] => SimpleXMLElement Object
                    (
                        [sampleDateStart] => 8 - 28 - 2012
                        [sampleDateEnd] => 8 - 28 - 2012
                        [sampleTimeStart] => 15:20:15
                        [sampleTimeEnd] => 20:20:15
                        [GaugeName] => BntCrk
                        [sampleValueAccumulation] => 0
                    )
    
                [TwelveHour] => SimpleXMLElement Object
                    (
                        [sampleDateStart] => 8 - 28 - 2012
                        [sampleDateEnd] => 8 - 28 - 2012
                        [sampleTimeStart] => 4:20:15
                        [sampleTimeEnd] => 20:20:15
                        [GaugeName] => BntCrk
                        [sampleValueAccumulation] => 0
                    )
    
                [TwentyfourHour] => SimpleXMLElement Object
                    (
                        [sampleDateStart] => 8 - 27 - 2012
                        [sampleDateEnd] => 8 - 28 - 2012
                        [sampleTimeStart] => 16:20:15
                        [sampleTimeEnd] => 20:20:15
                        [GaugeName] => BntCrk
                        [sampleValueAccumulation] => 0
                    )
    
            )
    
       
          )
    
    )
    
    // Stripped out other values in array as it exceeds character limit on post
    
    

     

    Ok so now we have an array of xml objects that I haven't tampered with by extracting the oject values.

     

    Now because that's an array of xml objects how do you access them directly? So if i want to echo one of those values to the page or use it to insert into a database how do you do that?

     

     

     

    The issue is if you have a variable number of child elements under each time interval you can't access the values directly (because you may not know what they are). So what is the best method of extracting the values from the time interval child elements in a form that can be used as outlined above?

     

    Why not access them directly? The OP seemed to have no problem with knowing what (the element names) he wanted to get information from.  Anyway, you already know how to get values from the child elements whose names you don't know (like the gauges).

  6. You're using the wrong feed on your example. The second feed provided was a bit more complex:

     

    $xml = new SimpleXMLElement('http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGaugesAllIntervals', 0, true);
    

     

    Well the desire is to iterate over the entire xml document and for each place name pull out the child elements of the intervals in a form that can be:

     

    a) directly echoed to the page

    b) stored in a database

     

    The issue is if you have a variable number of child elements under each time interval you can't access the values directly (because you may not know what they are).

     

    So what is the best method of extracting the values from the time interval child elements in a form that can be used as outlined above?

     

    Sorry I don't mean to sound deliberately obtuse (or to be awkward), its just that using get_object_vars appears to do the above but you suggest it's incorrect. So I genuinely want to understand how it's possible to achieve the above without using get_object_vars or type casting if you don't know the end precise end element name.

     

    SimpleXML provides iteration through the class. There's no reason to convert it to an array only to iterate through it.

     

    Unknown values can be looped through.

     

    <?php
    
    $xml = new SimpleXMLElement('http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGauges15m', 0, true);
    
    header('content-type: text/plain');
    
    foreach( $xml as $location => $data ) {
    echo "$location\n";
    foreach( $data->clsRainGaugeReading as $subdata ) {
    	foreach( $subdata as $key => $value ) {
    		echo "\t$key -> $value\n";
    	}
    }
    }
    
    ?>

  7. Well the desire is to iterate over the entire xml document and for each place name pull out the child elements of the intervals in a form that can be:

     

    a) directly echoed to the page

    b) stored in a database

     

    The issue is if you have a variable number of child elements under each time interval you can't access the values directly (because you may not know what they are).

     

    So what is the best method of extracting the values from the time interval child elements in a form that can be used as outlined above?

     

    Sorry I don't mean to sound deliberately obtuse (or to be awkward), its just that using get_object_vars appears to do the above but you suggest it's incorrect. So I genuinely want to understand how it's possible to achieve the above without using get_object_vars or type casting if you don't know the end precise end element name.

  8. I see what you're saying there but lets say you want to get the children elements of FifteenMinutes, but each parent (e.g. FiftenMinutes, ThirtyMinutes etc.) has varying numbers of child elements.

     

    In that instance you can't precisely name the child elements as with:

     

    $start = (string) $gauge->FifteenMinute->SampleDateStart;
    

     

    So if you wanted to fill a miltidimensional array with the child elements of each time interval how would you cast the values then?

  9. Well I am keen to be enlightened.

     

    How would you suggest doing it?

     

    For instance if I remove the get_object_vars from one of the nested arrays in the foreach I get an array as follows (this is just a snippet because the array is huge)

     

    Array
    (
        [bntCrk] => Array
            (
                [FifteenMinute] => SimpleXMLElement Object
                    (
                        [sampleDate] => 8-28-2012
                        [sampleTime] => 17:0:17
                        [GaugeName] => BntCrk
                        [sampleValue] => 0
                    )
    
                [ThirtyMinute] => Array
                    (
                        [sampleDateStart] => 8-28-2012
                        [sampleDateEnd] => 8-28-2012
                        [sampleTimeStart] => 16:45:17
                        [sampleTimeEnd] => 17:0:17
                        [GaugeName] => BntCrk
                        [sampleValueAccumulation] => 0
                    )
    

     

    So the first nested array (FifteenMinute) is now an xml object. The second (ThirtyMinute) is a standard array because I've used get_object _vars to retrieve the values.

     

    You've suggested using get_object_vars in this scenario is incorrect but it's now simple to access the values, e.g.:

     

    echo $topLevel['BntCrk']['ThirtyMinute']['SampleDateStart'];
    

     

    So it would be quite easy to use this in an insert statement.

     

    But you've suggested this is wrong and it doesn't seem to be possible to do the following on the xml object nested array (probably because I can't seem to find out how you use the array when it's an xml object, so this is the bit i'm not getting):

     

    echo $topLevel['BntCrk']['FifteenMinute']['SampleDateStart'];
    

     

    So how do you access those values the proper way? Lets assume I want to insert that value into a database, or even simply echo it out.

     

    I am keen to learn

  10. That's quite an odd request and I am not sure what the implications will be for your seo. But...

     

    So as I understand it you want to load different content into a single div depending on the link pressed?

     

    You can achieve this by:

     

    a) Loading your content into the page and hiding it all by default with css (display:none). Then you can use jquery or javascript on your links to optionally display or hide the content.

     

    b) Use iframes.  So you place the links on your main page and place the various pieces of content in separate html files. You then use a target attribute on the link to target your iframe. Probably the worst practice for seo.

     

    c) Bit more complex but - use ajax to optionally swap the content in the div.

     

    d) Create each link so that it points back to the page only with a query string on each link - then using php you optionally incorporate content based on the query string

     

    Those are a few suggestions for doing it, if i understand your issue properly that is! What you choose to do depends on a lot of things but those suggestions may put you on the right track.

  11. Ok, to atone for providing such a long winded example, and as I've learned something from Salathe's super dooper example, here is a slimmed down version micahel that will produce a multidimensional array of all the time intervals:

     

    <?php
    
    $data_url = 'http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGaugesAllIntervals';
    $package  = new SimpleXMLElement($data_url, NULL, TRUE);
    
    $topLevel = array();
    
    foreach($package->children() as $k=>$gauge) {
    
    
    $topLevel[$k] = array(
    
    		'FifteenMinute'		=>get_object_vars($gauge->FifteenMinute), 
    		'ThirtyMinute'		=>get_object_vars($gauge->ThirtyMinute), 
    		'OneHour'				=>get_object_vars($gauge->OneHour), 
    		'TwoHour'				=>get_object_vars($gauge->TwoHour), 
    		'FourHour'			=>get_object_vars($gauge->FourHour), 
    		'SixHour'				=>get_object_vars($gauge->SixHour), 
    		'TwelveHour'			=>get_object_vars($gauge->TwelveHour), 
    		'TwentyfourHour'	=>get_object_vars($gauge->TwentyfourHour)
    
    	);
    
    }
    
    
    // topLevel should be an array of all your interval values
    echo "<pre>";
    print_r($topLevel);
    
    
    ?>
    
    

     

    Hope that helps and sorry my first attempt to help was a bit...well...crap :)

  12. Well that does look cleaner :/ I did say there was probably a better way...

     

    And if you didn't like my last offering then you'll positively hate what I did to get the results for each timeslot.  I will go brush up on my simplexml i think...  :-\

     

     

    Yeah three levels of foreach was probably never going to be a winner...

  13. Hey mate

     

    If that's your purpose then I've tweaked the code slightly so you end up with a conventional array and not an array of xmlobjects (that in my my opinion are harder to access).

     

    <?php
    
    
    //$xml = new SimpleXML
    
    
    $xml = SimpleXML_load_file('http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGauges15m');
    
    $firstChildrenArray = array(); // going to hold parent elements
    $secondChildArray = array(); // going to hold child elements of each clsRainGaugeReading
    
    foreach($xml->children() as $child)
      {
      	$firstChildrenArray[] = $child->getName();
       }  
       
      // cycle through parent elements array so we deal with each in turn
      foreach($firstChildrenArray as $v){
    
    // now for every parent element get the object vars for each child element
    foreach($xml->{$v}->clsRainGaugeReading  as $vv){
    	$secondChildArray[] =  get_object_vars($vv); // add object var value to array
    
    }
    
      }
      
      echo "<pre>";  // get rid of this line
      print_r($secondChildArray); // just to demonstrate end result
      
      echo "" . $secondChildArray[3]['SampleDate']  ;
    ?>
    
    

     

     

    So as you can see in the very last echo line you can then access each entry as a multi-dimensional array, which you can then simply use in your insert statement for your database.

  14. Oh wait I think i get you :)

     

    try this:

     

    <?php
    
    
    //$xml = new SimpleXML
    
    
    $xml = SimpleXML_load_file('http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGauges15m', 'SimpleXMLIterator');
    
    $firstChildrenArray = array(); // going to hold parent elements
    $secondChildArray = array(); // going to hold child elements of each clsRainGaugeReading
    
    foreach($xml->children() as $child)
      {
      	$firstChildrenArray[] = $child->getName();
       }  
      
      foreach($firstChildrenArray as $v){
      
    $secondChildArray[$v] =$xml->{$v}->clsRainGaugeReading->children();
    
      }
      echo "<pre>";
    print_r($firstChildrenArray);
    print_r($secondChildArray);
    
    
    
    

     

    That will give you an associative array that matches the parent element to the children.

     

    You might want some logic in the foreach to handle null values too. For instance, "Brentwood" has no child elements so throws a warning.

     

     

    So to break it out into two different arrays will work best?  Make sense.

     

    Ok...brain dump here.  I believe my brain is fried now.  To list the matching first array item with the first array data fields, I need to add?

     

    Thanks for your help!

    Mike

  15. Well as i said, there may well be a better way to do it.

     

    Not quite sure I follow your question. What do yo want to do?

     

     

    So to break it out into two different arrays will work best?  Make sense.

     

    Ok...brain dump here.  I believe my brain is fried now.  To list the matching first array item with the first array data fields, I need to add?

     

    Thanks for your help!

    Mike

  16. Hey mate

     

    Sorry I only suggested that because it's generally what I use.

     

    This will work to get the child elements for each clsRainGaugeReading element. I am sure there are lots of cleaner ways to get them but it might put you on the right track :)

     

    <?php
    
    
    //$xml = new SimpleXML
    
    
    $xml = SimpleXML_load_file('http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGauges15m', 'SimpleXMLIterator');
    
    $firstChildrenArray = array(); // going to hold parent elements
    $secondChildArray = array(); // going to hold child elements of each clsRainGaugeReading
    
    foreach($xml->children() as $child)
      {
      	$firstChildrenArray[] = $child->getName();
       }  
      
      foreach($firstChildrenArray as $v){
      
    $secondChildArray[] =$xml->{$v}->clsRainGaugeReading->children();
    
      }
      echo "<pre>";
    print_r($firstChildrenArray);
    print_r($secondChildArray);
    
    
    ?>
    

  17. Any suggestions on the below question?

     

    Ok getting to grips with it a bit more now.

     

    Ordinarily, when would you suggest using bind_result? Or is it how prepared select statements should be done? Sort of as a matter of course.

  18. Hi Guys

     

    Thanks for your replies to this post. Just have a couple of questions (humour me as i am still getting to grips with prepared mysqli statements).

     

    1) Generally speaking in what scenario would you want to use bind_result? I assumed from the examples that it was simply what was done - from following examples.

     

    2) Christian suggested above that instead of using bind result I should use mysqli_stmt::fetch. But in the context of a prepared statement, like the example below, how would I use that method?

     

    Example:

            $var = 34;	
    $query = $db->prepare("SELECT name, address, town FROM datastuff WHERE id=?");
    $query->bind_param('i', $var);
            $query->execute();
    
    

     

    Where would I go from here to use mysqli_stmt_fetch? My confusion is really around the fact that with a prepared statement you're not using somehting like:

     

    $result = $mysqli->query($query);
    

     

     

    Sorry if these questions seem a little vacuous...just trying to get to grips with it.

     

    Drongo

     

     

  19. Well if you want to find specific strings within your contents then you could use preg_match with a regular expression. e.g.:

     

    $tester = file_get_contents('http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html'); //$tester contains contents to search
    
    
    $pat = '/TORNADO WARNING/';  // literal pattern to find
    
    if(preg_match($pat, $tester, $matches)){
    
    echo "Yup, tornado heading your way kid...get out of there you crazy fool!";
    print_r($matches);
    }
    
    else {
    
    echo "Nothing Found!";
    }
    

     

     

    You can pass it an array of matches too so you'll be able to find everything you want in one go.

     

    Hope that helps a bit...

     

    You will probably want to get more sophisticated with the match - i.e. only match place name if it's preceded by a specific bit of text. Otherwise the actualy page might say "tornado warning has been stepped down in WINDSOR" and you're preg match will see the warning text and windsor and start scaring people on your site :(

     

     

     

    I have the map part done...now I need some help with the text part...where I'm completely lost.  Heres the link of the text I need to grab http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html

    Now, I need to have it so that if TORNADO WARNINGS ISSUED FOR ....or TORNADO WARNING CONTINUED FOR....and then have the specific area...in this case it would be looking for WINDSOR-LEAMINGTON-ESSEX COUNTY....I need it so that if tornado warning issued for/continued for windsor...then get the text...else dont get text. Anyone have any ideas?

     

    Thanks, Dave

  20. You could use array_unique to simplify your array - http://php.net/manual/en/function.array-unique.php

     

    Then your loop would only have unique values.

     

     

     

    that's what I'm after. I just need a correct 'if' loop with some kind of trigger so it only displays each iteration of all the numbers equalling once.

     

     

    Something along the lines of:

     

    if (($bus_id == $row_get_Business['business_id']) && ($value == $row_get_Business['business_id'])) {

  21. Hi Guys!

     

    Quick question on mysqli and bind_result (been using pdo a lot and mysqli seems a wee bit different which is throwing me).

     

    When you bind the results of a query, what is the best way to get a multidimensional array from the result?

     

    I have played about and got the below to work - but i just know there has to be a better way than that!

     

    I woudl appreciate some enlightenment if you please :)

     

    <?php
    
    $db = new mysqli("localhost", "root", "", "testingcsv");
    
    // check errors
    if(mysqli_connect_errno()){
    
    	echo mysqli_connect_error();
    	exit();
    
    }
    
    
    $var = 34;
    
    $query = $db->prepare("SELECT name, address, town FROM datastuff WHERE id=?");
    $query->bind_param('i', $var);
    
    $query->execute();
    
    $query->bind_result($name, $address, $town);
    
    $myarray = array(); // to store results
    $i = 0; 
    
    while($query->fetch()){
    
    	$myarray[$i][] = $name;
    	$myarray[$i][]= $address;
    	$myarray[$i][] = $town;
    	$i++;
    }
    echo "<pre>";
    print_r($myarray);
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.