Jump to content

leehanken

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Everything posted by leehanken

  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
  15. In theory, you would need repeated polls from the page in question (Javascript) to a script on the server which would record in a database/file when the page is open (PHP), and a third script (PHP) run very frequently (by the cron daemon) to check the database to notice when a page has stopped polling, and then take the appropriate action. I think this is how the Google Analytics ajax figures out how long a user stays on each page.
  16. One way of doing things, would be to get find_by_sql() to return an array if there are multiple rows, but return an object if there is just one row. public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)) { $object_array[] = static::instantiate($row); } if (count($object_array)==1) return $object_array[0]; else return $object_array; } I don't know if this solution is aesthetically perfect, but I have seen it done in other people's code and it is the best I can think of.
  17. Nightslyr is right that the function returns an array. I think the following will give what you want, limiting the query to 1 record, and returning just the first (and only) element in the array - your object. class Schedule extends DatabaseObject { protected static $id_name = "schedule_id"; protected static $table_name="scheduled_studies"; protected static $db_fields = array('schedule_id', 'student_id', 'teacher_id', 'lesson', 'date' , 'time'); public $schedule_id; public $student_id; public $teacher_id; public $date; public $time; public $lesson; public static function find_last_study($student_id) { $sql = "SELECT * FROM " . self::$table_name . " WHERE stuent_id= {$stuent_id} ORDER BY date, time DESC LIMIT 1"; $last_study = parent::find_by_sql($sql); return $last_study[0]; } ... Also you will need to declare __toString in the Schedule class definition so you can print the object with echo. public function __toString() { return $this->schedule_id . " " . $this->student_id . " " . $this->teacher_id . " " . $this->date . " " . $this->time . " " . $this->lesson; }
  18. I am not sure what you mean about an object turning into an array. Have you tried using print_r, for example: <?php class x { public $p; public $q; function __construct() { $this->p=10; $this->q=20; } }; $a = new x(); print_r($a); ?> produces x Object ( [p] => 10 [q] => 20 )
  19. The syntax for switch-case statements in php requires a colon rather than a semicolon case "shec-dept": echo "do some query"; break;
  20. mysql_fetch_array only reads one row at a time, rather than all the rows at once also the result is an array rather than an object so [ ] are used rather than -> I think you mean... $datagib = mysql_query("SELECT * FROM sotw ORDER BY id DESC") or die(mysql_error()); echo "<table>"; while($infogib = mysql_fetch_array( $datagib )) { echo "<tr> <td>".$infogib[id]."</td> <td>".$infogib[username]."</td> <td>".$infogib[profile_link]."</td> <td>".$infogib[category]."</td> <td>".$infogib[week]."</td> <td>".$infogib[link]."</td> <td>edit</td> <td>delete</td> </tr>"; } echo "</table>"; ?>
  21. can you access the urls okay by typing them in?, i.e. http://www.mysite.com/blah?u=0, http://www.mysite.com/blah?u=1, etc. could it be timing out? try a low value of $x do curl functions in php work at all on your server - try a simple script to test them $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.google.com"); curl_exec($ch); curl_close($ch); don't see how cookies are relevant
  22. Depends if you want to show the results in the browser, or just run the script without output. If the former, you could use javascript and an iframe. If the latter then something like this: <?php $time=1; $y=0; $x=10; for ($i=$y;$i<=$x;$i++) { $ch = curl_init(); $url = "http://www.mysite.com/blah?u=".$i; curl_setopt($ch, CURLOPT_URL, $url); curl_exec($ch); curl_close($ch); sleep($time); } ?> But beware, while this is running, the browser will appear to be loading nothing, and may timeout.
  23. leehanken

    Hello

    Hi I found this forum on google, seems like a pretty good forum. I have written stuff and supported in php before. Hope joining in will keep my brain working! Regards Lee
×
×
  • 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.