Jump to content

nuttycoder

Members
  • Posts

    233
  • Joined

  • Last visited

    Never

Posts posted by nuttycoder

  1. that's brilliant works great

     

    I agree with your points, I didn't think having more then one name as key would work either I got to the point where anything was worth a try. I don't tend to use array beyond doing basic things.

     

    here's the output now:

     

    Array

    (

        [Richard Whiting] => 65

        [Ewan Dowes] => 43,2

        [Reece Lyne] => 34

        [Kirk Yeaman] => 32,27

        [Willie Manu] => 16

        [Mark Calderwood] => 13

    )

     

    what would your recommend is the best way to print out this data so it's like:

     

      Richard Whiting  65

      Ewan Dowes 43,2

      Reece Lyne 34

      Kirk Yeaman 32,27

      Willie Manu 16

      Mark Calderwood 13

     

    thanks very much

     

     

  2. Hi guys,

     

    I've been trying to get values from some arrays and group them it's kinda hard to explain let me give you an example I have this output:

     

    Richard Whiting - 65

    Ewan Dowes - 43

    Reece Lyne - 34

    Kirk Yeaman - 32

    Kirk Yeaman - 27

    Willie Manu - 16

    Mark Calderwood - 13

    Ewan Dowes - 2

     

    there are duplicates in the names I need to remove the duplicate name and keep the number but group them so they end up like this:

     

    Richard Whiting - 65

    Ewan Dowes - 2,43

    Reece Lyne - 34

    Kirk Yeaman - 27,32

    Willie Manu - 16

    Mark Calderwood - 13

     

    this is the code I've used to get this far:

     

    inside a loop I add the data to an array:

     

    $tsname[] = array($r['Team2TeamSheetPersonName'] => $timeLine->Time);

     

    $key is the name and $value is the number

     

    foreach ($tsname as $key => $value) {
    foreach ($value as $key => $value) {
    echo "<p>$key - $value</p>";
    }
    }
    

     

    I've tried everything I can think of and am stuck not sure how to do this, if anyone can provide any help on this I would be very greatful.

     

    thanks in advance.

  3. Hi Guys,

     

    I'm trying to print some code snippets to the screen that's mixed with normal html what I'm trying to do is use htmlentities to convert the snippets. This would only convert text inside [ code ] [ /code ] tags.

     

    Using preg_replace I've managed to isolate the snippets but I cannot use htmlentities without causing an error.

     

    As I need to add the snippets back into the string it came from before bring printed.

     

    Here's what I've been using replacing all code tags with <pre class="codeprint">snippets here</pre>

     

    $pr->postDesc = preg_replace("/\[code\](.+?)\[\/code\]/is","<pre class=\"codeprint\">$1</pre>", $pr->postDesc);

     

    An example of what $pr->postDesc contains:

     

    <p>testing</p>

     

    [ code ]

    <?php echo $test;?>

    [ /code ]

     

    Hope you can understand what I mean.

  4. you can get the data from a session by using the session name and adding it to a variable like this:

     

    $data = $_SESSION['item'];

     

    Then you can save that information into a text file

     

    $file = "session.txt";//set a name for a text file will be created if it does not exist
    $fo = fopen($file, 'w');//open the file
    fwrite($fo, $data);//write data there 
    fclose($fo);//close file

  5. thats all the files I made for it, it's a very basic there is no html files/interface as when I made it, it was just to copy files from one server to another so I din't need any sort of visuals for it.

     

    The functions are there to make is easier to reuse the code, to say copy a file from one server to another, you use the ftp connect function and supply the ftp login to the remote server you want to copy to then use the copyfile function and pass the folder to where you want to copy the file to then the path to where the file is on the current server.

     

    ftpconnect("ftp.server.com","username","password");

    copyFile($conn,"path/to/file/filename.ext","filename.ext");

  6. try <input type="text" name="book" value="<?php echo $title; ?>" /> it was missing the ;

     

    The semi-colon is not required when the PHP closing tag appears on the same line. But I would use it anyway.

     

    I din't know that :) learn something new everyday still woulden't do it that way, same as I never use <?=$title;?>

  7. if you have the country code in your database then use that in the link or just the country name :<a href="country.php?code=".$row['Name'].">

     

    then next page is where you query the database based on the country

     

     

    <?php
    $code = $_GET['code'];
    $code = mysql_real_escape_string($code);
    
    $queryasia = mysql_query("SELECT * FROM Country WHERE Continent ='$code' ORDER BY Name")or die(mysql_error());
    echo "<table>";
    while ($row = mysql_fetch_array($queryasia)) {
          echo('<tr><td>' . '<a href="country.php?code=$code">' . $row['Name'] . '</a></td><td>' . $row['Population'] . '</td><td>' . $row['GNP'] . '</td><td>' . $row['GovernmentForm'] . '</td></tr>');
       }
    echo "</table>";
    }?>

  8. put another query inside the loop:

     

    <?php
    
    header("Content-Type: text/xml; charset=UTF-8");
    include("includes/conn.php");
    
        $rssfeed = <?xml version="1.0" encoding="UTF-8"?>';
        $rssfeed .= '<root>';
    
        $query = "SELECT * FROM my_property WHERE status ='Y' AND cat_id='4'";
    
        $result = mysql_query($query) or die ("Could not execute query");
    
        while($row = mysql_fetch_array($result)) {
    
            extract($row);
    
    	$s = mysql_query("SELECT * FROM property_pics WHERE id='$id'");
    	$r = mysql_fetch_object($s);
    
            $rssfeed .= '<property>';
            $rssfeed .= '<id>'.$id.'</id>';
            $rssfeed .= '<date>'.$date.'</date>';
            $rssfeed .= '<ref>'.$propertyref.'</ref>';
            $rssfeed .= '<price>'.$price.'</price>';
            $rssfeed .= '<currency>EUR</currency>';
            $rssfeed .= '<type>';
            $rssfeed .= '<en>'.$property_type.'</en>';
            $rssfeed .= '</type>';
            $rssfeed .= '<town>'.$location.'</town>';
            $rssfeed .= '<province>'.$city.'</province>';
            $rssfeed .= '<location_detail>'.$address.'</location_detail>';
            $rssfeed .= '<beds>'.$bedrooms.'</beds>';
            $rssfeed .= '<baths>'.$bathrooms.'</baths>';
            $rssfeed .= '<desc>';
            $rssfeed .= '<en>'. htmlspecialchars($description) .'</en>';
            $rssfeed .= '</desc>';   
            $rssfeed .= '<images>';
            $rssfeed .= '<image id="1">';
            $rssfeed .= '<url>http://www.mywebsite.com/pics/'.$r->file.'</url>'
            $rssfeed .= '</image>';
            $rssfeed .= '</images>';
            $rssfeed .= '</property>';
    
              }
    
            $rssfeed .= '</root>';
    
            echo $rssfeed;
    ?>
    
    
    

  9. you could create a link like <a href="ref.php?code=google">www.google.co.uk</a>

     

    then on ref.php it gets the url requested

     

    $code = $_GET['code'];

    //$code contains google

    then you could do a switch statement to check for various links you may have then do what ever your going to do then either direct the page to the link using a header or a text link,button.

  10. okay where ever you pass anything in the url such as country.php?code=asia anything after the ? becomes a variable to use it you need to add it to a variable

     

    $code = $_GET['code'];

     

    now $code contains 'asia'

     

    so on the first script change the country name into a link like this:

     

    <a href="country.php?code=asia">Asia</a>

     

    then in country.php

     

    first connect to your database then get the variables from the url and make them safe from sql injection using mysql_real_escape_string

     

    $code = $_GET['code'];

    $code = mysql_real_escape_string($code);

     

    then your ready to do a query based on the country like this:

     

    $s = mysql_query("SELECT * FROM Country WHERE Continent ='$code' ORDER BY Name")or die(mysql_error());

     

    so the full page may look like this:

     

    <?php
    //connect to db first
    
    $code = $_GET['code'];
    $code = mysql_real_escape_string($code);
    
    $s = mysql_query("SELECT * FROM Country WHERE Continent ='$code' ORDER BY Name")or die(mysql_error());
    while($r=mysql_fetch_object($s)){
    //echo your data
    echo $r->Name;
    }?>

     

×
×
  • 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.