Jump to content

leehanken

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling
  • Location
    London, UK

leehanken's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I don't know if it has to be 'Content-Length' rather than 'Content-length'?
  2. Load into an array then use a nested loop. while($row = mysql_fetch_array($Result)) { $sections[$row[section]][] = $row[subsection]; } foreach ($sections as $section => $subsections) { echo "<ul><li>$section</li><ul>"; foreach ($subsections as $subsection) { echo "<li>$subsection</li>"; } echo "</ul></ul>"; }
  3. Php doesn't allow the asynchronous socket callback functions of the same type used in other languages, so you need to write a loop that checks all the multiple connections and responds as and when they need attention. Sockets can be told to act asynchronously with socket_set_nonblock. This will stop them pausing the code when a read or write is performed, if it can't then the read/write function just fails and moves on instead of waiting. There is also a function socket_select which simultaneously monitors whole arrays of sockets for read/write/exceptions.
  4. This could be done with html and javascript and no php as the behaviour is on the client side. For example: <script language='javascript'> function list1change() { div1 = document.getElementById('div1'); list1 = document.getElementById('list1'); if (list1.selectedIndex==0 || list1.selectedIndex==2 || list1.selectedIndex==5) div1.style.display = 'block'; else div1.style.display = 'none'; } </script> <form name=form1 method=get action=''> <select name=list1 id=list1 onchange="list1change()"> <option value="item1">item1</option> <option value="item2">item2</option> <option value="item3">item3</option> <option value="item4">item4</option> <option value="item5">item5</option> <option value="item6">item6</option> </select> <div name=div1 id=div1 style='display: block;'> <select name=list2> <option value="item1">item1</option> <option value="item2">item2</option> <option value="item3">item3</option> </select> </div> </form> As Karl points out, there is lots of information available on doing this, and general purpose libraries that handle the combination of html, javascript and php to simplify things.
  5. Just that it takes whatever parameter the browser sends to it, and calls a function of that name if the function exists. This would be insecure if a hacker wanted to call some function in your code they could pass anything. This should really not be a problem for educational use.
  6. I think the simplest way is to load the rows of data into an array, then sort this with usort (using a user-defined comparison function that does the logic you describe), then finally output the sorted array.
  7. I think something to bear in mind is that there could be both post AND get parameters at the same time, so it might be worth checking each. One feature of php is the $_REQUEST array which is discussed here: http://php.net/manual/en/reserved.variables.request.php with some useful code examples in the comments. The approach you describe is perfectly valid. A switch statement might make it clearer: ... switch($key) { case 'product': Product(); break; case 'category': Category(); break; case 'quality': Quality(); break; case 'featured': Featured(); break; } ... or even, this (very unsecure) code: ... $key = ucfirst(strtolower($key)); if function_exists($key) call_user_function($key,$value); ...
  8. Okay, I was not familiar with that, sorry for the question. I noticed you set the same variable twice. Is this what you meant to do?
  9. What are the brackets for after the word 'category'?
  10. Code looks okay. Does it work if you say header("Content-type: text/html") so you can see the output?, or using a different browser?
  11. I think you would use Curl functions to retrieve the web page, and a regular expression to search for links.
  12. Just a hint, which may or may not be of use. When there is an if () { } statement, anything between the braces goes unprocessed if the condition is false, so for example if a function is declared in the braces it may or may not be available, or html code between the braces, it may be left out.
  13. Don't know what an AI is. See http://php.net/manual/en/function.uniqid.php
  14. Also check out 'while', and 'do-while' http://www.php.net/manual/en/language.control-structures.php
×
×
  • 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.