Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. All of the information relating to the user will be stored in a database. The photos would be stored in a folder somewhere, with the links to a users photo also stored in a database. Take a look at this tutorial here: http://www.phpfreaks.com/tutorials/78/0.php This is about creating a membership system
  2. Im guessing its printing: :\"> You only need to escape quotes if they are the same type as used to open and close the string. So either use: <?php print ':">'; ?> or <?php print ":\">"; ?>
  3. You can always specify a height and a width of the image when you output it. Wouldn't reduce the file size of the image in the way that creating a thumbnail would, but if the images aren't too big anyway then its an option.
  4. Also, if you are going to be using the ID for any database work etc, then you will need to validate it.
  5. Well, if i run the following code: <?php include('test_db_connection.php'); $sql = "INSERT INTO `ranking` VALUES ('','200');INSERT INTO `ranking` VALUES ('','200')"; mysql_query($sql) or die(mysql_error()); ?> Then i get the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';INSERT INTO `ranking` VALUES ('','200')' at line 1 And the php manual does say that multiple queries are not supported with mysql_query()
  6. Output &nsbp; for each space you would like to have: <?php echo 'test test'; ?> Gives: test test
  7. Separated with a semi-colon. And i just tried it without the mysqli extension. Still manages to do multiple queries.
  8. Yeah, i figured that out. Still cant believe i did that I did wonder that. I guess phpMyAdmin breaks up any multiple queries then? It appears to execute those ok.
  9. Oh dear. Obviously not thinking clearly. Of course, the way i was outputting the results would only show the first row. Whoops! Thanks for your help.
  10. Are you sure? If i try this query in phpMyAdmin: SELECT `score` FROM `ranking` WHERE `id`='3' UNION SELECT `score` FROM `ranking` WHERE `id`='5' Then i get an output showing two scores: score 96 83 However, if i use the following php script: <?php include('test_db_connection.php'); $result = mysql_query("SELECT `score` FROM `ranking` WHERE `id`='3' UNION SELECT `score` FROM `ranking` WHERE `id`='5'")or die(mysql_error()); print_r(mysql_fetch_assoc($result)); ?> Then i only get the first score as an output: Array ( [score] => 96 ) I appreciate its a highly pointless query - this is just for testing purposes.
  11. Hopefully just a quick question. Would i be right in thinking that the UNION command does not work in a query made using the mysql_query() function? I see that multiple queries are unsupported, and i guess using UNION is like having a multiple query. If someone could just confirm, i'd be grateful. Ben
  12. <?php $mystring = 'foobar'; for($x=0;$x<strlen($mystring);$x++){ echo $mystring[$x].'<br />'; } ?> Produces: f o o b a r
  13. Im a little confused with the ordering of your output. I would have thought you would want to group by the parent number? <?php $tree= array( 0=>array('id'=>1, 'parent'=>0), 1=>array('id'=>2, 'parent'=>0), 2=>array('id'=>3, 'parent'=>2), 3=>array('id'=>4, 'parent'=>3), 4=>array('id'=>5, 'parent'=>2), 5=>array('id'=>6, 'parent'=>0), 6=>array('id'=>7, 'parent'=>3), 7=>array('id'=>8, 'parent'=>4), 8=>array('id'=>9, 'parent'=>1), 9=>array('id'=>10, 'parent'=>0), 10=>array('id'=>11, 'parent'=>10), ); $new_array = array(); foreach($tree as $value){ $new_array[$value['parent']][] = $value['id']; } ksort($new_array); echo '<pre>'; print_r($new_array); echo '</pre>' ?> Produces: Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 6 [3] => 10 ) [1] => Array ( [0] => 9 ) [2] => Array ( [0] => 3 [1] => 5 ) [3] => Array ( [0] => 4 [1] => 7 ) [4] => Array ( [0] => 8 ) [10] => Array ( [0] => 11 )
  14. You can reload parts of a page using ajax. Not sure if this is really a viable solution - depends on the content of your steps.php page. I'd probably go for the iframe.
  15. To answer your question foreach was introduced in php 4.
  16. Well it should just be a case of applying the techniques used in the link i showed you. <?php $i = 0; $max_columns = 2; foreach ($rss->items as $item ) { $description = $item[description]; $url = $item[link]; $title = $item[title]; if($i == 0) echo "<tr>"; echo "<td>$description</td>"; if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?>
  17. Ah right. I think i just worked out why yours is quicker. I was thinking that mine only loops through the data once. But i suppose that by using the function in_array() you are effectively looping through the array inside the loop just as you do in yours. Seems intersting that although the idea is similar in both codes, there is a (relatively) large differance in timing for the script.
  18. You really have to re-arrange your data before you can do anything with it. I came up with: <?php $myarray = Array( Array('apple','20'), Array('banana','15'), Array('orange','35'), Array('apple', '15'), Array('orange', '26'), Array('pear', '22'), Array('banana', '13'), Array('banana', '40') ); $items = array(); foreach($myarray as $key => $value){//rearrange array into a more useful form. We have an array containing an array of each of the prices for a given item $items["$value[0]"][] = $value[1]; } foreach($items as $key => $value){//cycle through each item. Sort the prices sort($value); echo "The cheapest $key costs $value[0]<br />"; } ?>
  19. That is exacty what that link shows you how to do. If you show us your existing code, we might be able to help you modify it.
  20. Frost100 - i really dont think its going to be that simple. If you take a look at the website, there is very little on it - im guessing the table that is wanted is a table you can only see once logged in. In which case, cURL will be needed.
  21. Barand - would i be right in thinking that if you didn't require the key of the first duplicate then my method would be more efficient?
  22. If you used the following code: <?php echo '<pre>'; print_r($_FILES); echo '</pre>'; ?> You would probably see your problem. Basically, there is another dimension in your multidimensional array between ['upload'] and ['size']. This is because you have made upload an array as well, as you are accepting multiple uploads from the same form. Im pretty sre your foreach should read something like: <?php foreach($_FILES['upload'] as $key => $value){ $size = $_FILES['upload'][$key]['size']; //etc } ?> Im finding it a little hard to explain. But hopefully you might follow.
  23. You'll need to put in a little validation. Use something like this in your while loop: <?php if($file != '.' && $file != '..'){ echo $file; } ?>
  24. Right. And do you need to be logged in to view that table?
  25. That does depend slightly on what you are trying to do. If ALL you are wanting is to return the first key that was a duplicate instead of the last, and nothing else, then just reverse the original array whilst preserving keys: <?php // $myarray = file ("12345.txt"); $myarray = array('0123456789first line','0123456789second line','0123456789first line');//just an example to test $myarray = array_reverse($myarray,true);//reverse array - second parameter as true keeps your original keys $new_array = array();//we're going to put new values into here $duplicates = array();//and we'll put the keys of any duplicate values here foreach($myarray as $key => $value){ $value = substr($value,10);//strip out first 10 characters if(!in_array($value,$new_array)){//check if the value is in our new array $new_array[] = $value; echo "value= ".$value."<br>"; }else{ $duplicates[] = $key ; echo "key= ".$key."<br>"; } } ?> If you are looking to get the keys of all of the lines which were duplicates(e.g return keys 0 and 2 in our example) then its going to be a little more complex.
×
×
  • 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.