Jump to content

nuttycoder

Members
  • Posts

    233
  • Joined

  • Last visited

    Never

Everything 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. Thanks Guys I should have consulted the manual to see if there way a better way preg_replace_callback is the obvious choice now it's been pointed out to me Works a treat. I'm not using highlight_string as my code snippets are not limited to just php so I'm using google's prettify syntax highlight plugin. Thanks again guys much appreciated!!
  4. 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.
  5. 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
  6. yes you need to select the database to use like this; $conn = mysql_select_db ($database)or trigger_error(mysql_error(),E_USER_ERROR);
  7. one restriction is the time the script take it there's a lot of files or big files it can timeout you can increase the time limit but may be restricted depending on the server setup set_time_limit(200);
  8. thats why there's functions call the functions as many times as needed.
  9. hmm that's odd never got that myself, the else should only run if the folder was created, if you remove the error supressor @ you'll see what the server says when making folder can't remember off hand it's been awhile since I used the script.
  10. it's because your using mysql_fetch_object at the top but using array notation when calling the items such as $row['Name'] when using mysql_fetch_object use the -> notation so $row->name. or change mysql_fetch_object to mysql_fetch_array
  11. 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");
  12. had the wrong quotes <?php while ($row = mysql_fetch_array($queryasia)) { echo('<tr><td>' . '<a href="country.php?code='.$row['Code'].'> ' . $row['Name'] . '</a></td><td>' . $row['Population'] . '</td><td>' . $row['GNP'] . '</td><td>' . $row['GovernmentForm'] . '</td></tr>'); } ?>
  13. 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;?>
  14. try <input type="text" name="book" value="<?php echo $title; ?>" /> it was missing the ;
  15. oh sorry I misread your first post I thought you said define when you said declare, I've never used declare.
  16. 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>"; }?>
  17. you can increase the upload file size with htaccess here's a tutorial on that: http://www.phphelptutorials.com/ht-access/override-file-upload-sizes-an-htaccess-file your server may be setup to restrict upload sizes, if thats the case you'll need to contact your host.
  18. you could pass the vars as an array then loop through the array inside the function
  19. it can be, I din't use it at all until recently I use it a lot to store things like file paths. Instead if having to pass variables to a functions it's already available. I recommend giving it a try.
  20. no you could get the country code from the database and add that into a link, replace $countrycode with the country code variable and countryname with the country name variable. <a href="country.php?code=$countrycode">$r->countryname</a>
  21. 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; ?>
  22. It's used to make a date a constant meaning it never changes which is available throughout the script without a need to use the global. It's mainly used on config files for you database connection data for example.
  23. 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.
  24. 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; }?>
  25. try this: if ($img1) echo "<td width='33.3%' align='center'> <FORM> <INPUT type='button' value='New Window!' onClick=\"window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200')\"> </FORM> </td>";
×
×
  • 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.