Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. You'll need to reset the row that your working on between the two loops with mysql_data_seek. When you use the mysq_fetch_xxxx functions, it reads the current row of the result set into an array and advances the internal pointer. This means that next time you use the function, you work with the following row in the result set. At the end of the first loop, you've reached the end of the result set. So at the next while loop, you're already at the end of the result set. That's why you need to reset the pointer.
  2. You've rather lost me there. I guess your trying to compare and see what information is in both tables? You can either do a left join, or you can read both result sets into an array and use array_intersect(). At present, you appear to be comparing outside of the loop. So unless you are using an array, that's not going to work. Perhaps if you told us exactly what you're trying to achieve, it would help some more.
  3. To be fair, I always thought being able to write something comprehensible was rather a prerequisite for being able to teach someone...
  4. Doesn't your slogan rather depend on what your company does? I mean, a slogan for a car company isn't going to work so well for, say, a bank is it?
  5. So you're just tring to find out if $word is in $string? Use strpos: <?php $word = "abcd.com"; $string = '<embed src="abcd.com" width="550" height="400"></embed>'; if(strpos($string,$word) !== FALSE){ echo $word.' occurs in the string'; }else{ echo $word.' does not occur in the string'; } ?>
  6. Indeed. The coding standards in the Zend Framework say that, for files containing only PHP, you should not use a closing tag. At the end of the day, unless you're coding to a particular standard, it's personal preference.
  7. 1.) Always validate server side. 2.) Add validation client side so that it is more user friendly. It is far nicer for the user to be told immediately that their username is not long enough than to fill out the rest of the form, wait a while, then be told. Not to mention lighter load on your server.
  8. Untested, but you'll want something like this: <?php $sql = "SELECT q.QuarterID, q.Quarter, m.QuarterID AS selected FROM tblquarters AS q LEFT JOIN tblMileStones AS m USING QuarterID"; $result = $connector->query($sql); if(mysql_num_rows($result)==0){ echo "There is no data in table.."; }else{ echo '<select name="Quarter>'; while($row = mysql_fetch_assoc($result)){ echo '<option value="'.$row['QuarterID'].'"'; if(!is_null($row['selected'])){ echo 'selected="selected"'; } echo '>'.$row['Quarter'].'</option>'; } echo '</select>'; } ?> Now, you were correct in thinking that you'll need to retrieve IDs from both tables. However, you need to be able to access these separately in your results set, so you need to give one an alias (i gave the one form your milestones table the alias selected). The whole point of a left join is that it allows you to find rows that don't match. In the results set, they are null. Therefore, for the rows which aren't null (that is, they are in both tables), we want to echo a selected tag. I also changed your for loop to a while; since there's less to write . Oh, and i thought i'd show you the USING clause too. When you're doing a join, if the two columns have the same name, you can just give that column name and use USING. Edit: @lemmin. If you can get all the info in more query, why would it make more sense to use two? Why double the number of queries if you dont have to?
  9. I guess the only way to explain is by analogy. You know (i would assume) that you may have to escape quotes when echoing something. For example, to echo harry's (when using single quotes around the string), you would have to do this: echo 'harry\'s'; The backslash effectively tells PHP to ignore any special meaning that the ' character has. In this case, it prevents the single qoute from terminating the string. The backslash is not echoed. In the same way, using mysql_real_escape_string() tells MySQL to ignore any special meaning that the characters have. It does not store them; just prevents them from having significance. Perhaps it would be helpful if you understood that mysql_real_escape_string() actually calls the MySQL function of the same name. Hence why a connection is required.
  10. Yes, that's correct. If you press enter to submit a form in IE, the submit button will not be set. It will in firefox. You should do something like this to check if a form has been submitted: if(count($_POST) > 0){ //form is submitted } Edit: Or, as CV suggested, you can do: if($_POST){ }
  11. Completely untested, but i'd do something like this: <?php $str = '|"Beans","Baked"| "Apple","Red","Green"| "Potato","Baked","Roast"|'; $str = str_replace('"','',$str); $foods = array(); $types = explode('|',$str); foreach ($types as $type){ if(!empty($type)){ $varieties = explode(',',$type); for($x=1;$x<count($varieties);$x++){ $foods[$varieties[0]][] = $varieties[$x]; } } } foreach($foods as $type => $varieties){ $sql = "INSERT INTO sometable ('food') VALUES('$type')"; mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $id = mysql_insert_id(); $sql = "INSERT INTO othertable ('foodid','variety') "; $inserts = array(); foreach ($varieties as $variety){ $inserts[] = "VALUES('$id','$variety')"; } $insert = join(',',$inserts); $sql .= $inserts; mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); } ?> Your first step has to be to organise the string into something more useful.
  12. There's a topic all about recommendations for books over in the miscellaneous board: http://www.phpfreaks.com/forums/index.php/topic,58799.0.html
  13. I also notice that in your second parameter for move_uploaded_file, you've only specified the directory and not the file name.
  14. That would be because the first time the page loads, there is nothing in the $_GET array, so each index is undefined. You should check to see if the variable is set before echoing it. You ought to be using htmlentities() too, otherwise you'll have problems if people include quotes. Like this: value="<?php echo (isset($_GET['Name'])) ? htmlentities($_GET['Name']) : '';?>" Edit: note that htmlentities() will not be required for the message. This is because it is not contained within double quotes as the value attribute.
  15. The problem (well, one of them at least) is that you've trying to move $_FILES['picMain']['name'] and not $_FILES['picMain']['tmp_name']; the first parameter of move_uploaded_file should be the temporary name that was automatically given to the file when it was uploaded. See here for the manual page describing a basic upload process.
  16. After 4 posts you still havn't twigged that we havn't got a clue what you're asking? While I commend the fact that you've posted your code and database structure (albeit, without the use of tags), actually describing the problem is rather essential for us to be able to help you.
  17. Yes. That's exactly how a cURL request works.
  18. No at the moment. See here for a bit of a discussion on it.
  19. Yup. You can do it with cURL.
  20. I epect if you take a look at the page which outputs the topics normally you will find that, prior to being echoed, the post is run through a function which will replace the text for the smiley with an image tag. You'll need to put your last post through that function too.
  21. $num = 3.67; $decimal = $num - floor($num);
  22. Erm, well what happens when you normally browse to ?cid=119. Are you sure the processing is not being done there before being forwarded to /register? It could be that something is being set in a session when you visit ?cid=119. In that case, you'll have to make two requests. The first will access ?cid=119 and save the session ID (you'll have to provide the CURLOPT_COOKIEJAR option. The second will be to /register.
  23. I'd use regex: $text = "kjbj321 knbljb354 jlknlkj4223 jnkjnlk123 kblkbn534 kjbkhb24 lhbk43 kjvbhbjv3212"; $searchfor = "kjbj"; preg_match("|$searchfor([0-9]+)|is",$text,$matches); echo $matches[1];
  24. I'd do it like this: <?php $array = range(0,999); shuffle($array); $rand = array_slice($array,0,4); print_r($rand); ?>
  25. That is exactly what a GROUP BY clause does. If your query is not returning the required information, this would be better off in the mysql section, along with more details about your table structure and what you are trying to achieve.
×
×
  • 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.