Jump to content

mikesta707

Staff Alumni
  • Posts

    2,965
  • Joined

  • Last visited

Everything posted by mikesta707

  1. I believe it sufficiently addresses the issue, since it is explicitly declared to be an empty array from the start. $tagArray is empty simply because he declared it so, and it was not meant to contain anything, but to store the count of the occurrence of each tag. The only reason why he has to check for an existing key (admittedly a less-orthodox method) before initialization is because he is using an associative array with an unknown set of keys, and thus cannot declare them prior to the loop. Pardon me if I'm wrong, but I don't see how there is any further "root" to the problem, apart from redesigning the entire block of code, which I think is already rather lean. Yes, I understand that it is meant to be a counter of some sort, but the root of the problem is why he would set it to an empty array. To me at least, this suggests OP is unsure of what he means to do with this variable. For example, you use array_key_exists, but there is really no point since in the context it will be used, it will always be true. He could simply just set $tagArray[$tag] to 1. OP could also accomplish the same task by simply using array_count_values() which would eliminate the foreach loop all together. But perhaps there is a reason he has the foreach loop that we cannot see because we don't know what else is going on in OPs script. My point is that OP fixed the problem with somewhat pointless code (in the context, I can't say definitely because I don't know what this snippet fits into) And while he won't have any errors or notices, perhaps there is a better way to do what he wants if he examines what exactly it is he is trying to do.
  2. You can use a combination of $_GET variables (for which I will not provide a link as I assume you know how to use it) and glob(). THe get variable will be what you use to select the folder, and glob to get all the images. Glob will give you an array of the filenames, and you can use this array combined with a foreach loop to output the images. for example $id = $_GET['id'];//we should probably sanitize this just in case. $images = glob("path/to/folder/$id/*.jpg");//this will grab all the jpgs in the folder using pattern matching. //for more information on what the wildcard charactr * means go to the manual page, linked above. //if i wanted to get all the files in the folders (meaning there is a chance we can get non image files //we can do this $images = glob("path/to/folder/$id/*.*"); //if we want to limit it to 2 or more types of extensions, we can use the brace operator $images = glob("/path/to/folder/$id/{*.jpg,*.png}", GLOB_BRACE); //the above would get all .jpgs and .pngs //now we just loop through and do what we want foreach($images as $image){ //in this case ill just echo it echo $image; //this will just echo the image name though. //you probably want to echo it inside the src attribute of an img tag }
  3. tizag.com is a website I used when trying to learn the basics of php/mysql/javascript. I don't know how reliable the data is now, but a few years ago it was good. Also, googling for certain topics (like nested select statements) usually works well. The problem lies in figuring out what the topic is known by on the internet. All in all, practice is really the best way to learn.
  4. While this will fix your problem, it doesn't really address the issue of why your $tagArray is empty, and what it is meant to contain originally. If this script has been like this since its creation (you mention it running on previous versions of PHP without problem. This is probably because you had error reporting turned off, or set up in such a way to not report Notices), I guess it would be ok to leave it as is, but you may want to consider getting to the root of the problem. However, if your script works, and your happy with the result, then by all means leave it as is, and work on something else that requires your attention.
  5. after doing some research on nested SELECT queries, it appears that you should be using the command IN. For example $sql = "select * from hotels where city_id IN (select id from cities where name = '$where') or country_id IN (select id from countries where name = '$where')";
  6. I asked for the single query that is causing the error you mentioned. not all of your code
  7. you never give your variable $tarArray any other value but an empty array. You haven't given enough information to give any insight into what $tarArray should contain.
  8. please use code tags. and instead of using strlen($msgContent) why dont you try using strlen($_POST['msgContent']) the reason being you set $msgContent to a value that will almost always have a length larger than 5 in case you dont know, you can use code tags like so [code] php and html code here [/code] OR [code=php:0] just php code here [/code]
  9. WHERE Admin_Level ='Admi'"; should this be WHERE Admin_Level ='Admin'"; I don't know much about PDO but that was the first thing I noticed
  10. Did you just paste your query a bunch of times, or is your actual query that mass of text if the former, would it be safe to say that your query is this and where does this query fit in that last query is missing a closing parenthesis after "like 'france'" as for your usage of like, since you don't use any wildcard, in most instances using LIKE and = (equal to) would produce the same thing. Now just to clarify, so I understand where you are in the process of fixing this, when you do this query you get a bunch of different hotels not relating to the $where variable, but the count of them is correct (IE if they input france. you get back 50 hotels (the number in france) but they are not french hotels?) Also, as for the line in your objects method that overwrites the $where parameter, that is bad practice. One of the main concepts in Object oriented programming (OOP) is encapsulation, which is basically the practice of keeping object data contained within objects, and non-object data outside of objects. By using the $_POST super global in your object, you kind of break this rule. It works because $_POST is a super global, but now you object isn't very general. What if you want to change the name of that $_POST variable, or want to use that object in another script. Now you can't because it depends on a $_POST variable from outside the class that may or may not be available. The kicker is, your method is set up to use a passed on argument, and you actually do the same checking before you call the object method (where you SHOULD be doing the check of the $_POST variable, and assigning it a useful value). Checking the variable for a useful value is good to do in a method, but using non-object data is kind of defeating the purpose of an object. EDIT: as for your latest reply I don't see you erroneously using your $where variable as a column. could you post (or repost) the query that is causing this error?
  11. How many items are in your database? What is the code that sets/changes those session variables. What is the structure of the table you are using? IS there a reason you use the x,y variables as strings in the queries? have you tried removing the quotes around the x,y coordinates and seen if that gave you better results? You could make your script more efficient if you used a for loop to build 1 large query, and query the database once. However, this should be considered after you fix your script.
  12. You may have more luck in the Other Libraries and Frameworks section of the PHP Coding forum with this topic
  13. yeah this is what confused me. I was hoping he would post the code that actually sends the post data, but instead he decided to PM the link to the page.. which didn't help at all
  14. well you seem to be nesting while loops for some strange reason. I never indicated you should do this. Based on the code you posted, perhaps you meant to do $result = mysql_query( "SELECT category_id,category_name FROM gallery_category" ); echo "<select name='photo_category' size='1'>"; while( $row = mysql_fetch_array( $result ) ){ echo "<option value=\"".$row['category_id']."\">".$row['category_name']."</option>"; } echo "</select>";
  15. It seems like your upload form is an array. Thus the structure of the files array is different from what you expect. Requinix details the structure on his first post in this thread. See that thread for more information. But you are going to have to take this information in mind, and rewrite how you access the details of the uploaded image in your script
  16. use implode() for example $str = implode(", ", $match[1]); echo $str;//echos actor#1, actor #2, actor #3 hope this helps
  17. Hmm, well can you post the page that is posting the information to the code you posted in your OP
  18. well clearly what I wrote was just an example. You could (and should) use a variable in your query, not the string necklace. I just wrote necklace because that was what you mentioned in your OP.
  19. What exactly does it say. Can you copy paste it...
  20. You can use a query to select all categories whose parent categories is equal to Necklaces. If there are 0 rows returned (which their should be) Then that means that Necklaces is a category without any sub categories.
  21. use the REMOVE_ADDR index of the $_SERVER super global array. For example $ip=$_SERVER['REMOTE_ADDR'];
  22. Hmm interesting, so it is an array? If you do a print_r on $event_items what do you get?
  23. $event_items is a single value, and foreach expects an array. Do you expect $_POST['event_items'] to be an array? If so why do you expect this?
  24. There are many things wrong with what you wrote. Firstly, your error. When you use a loop to get all the rows from your result set, at the end of the while loop, the variable you used is set to false. For example $sql = mysql_query("some query"); while ($row = mysql_fetch_array($sql)){ //do some processing here } echo $sql; this would echo false, or null, or something along those lines depending on your system and version of PHP. This is because your result resource is kind of like a pointer to the current row in the result set, and when you loop through all the rows, the result set has nothing to point at any more. To fix this, you either need to do the query again or, more optimally, just do the select echoing in your first query fetch array loop. For example echo "<select name='photo_category' size='1'>"; while($result=mysql_fetch_array($query)) { $photo_title=$result['photo_title']; $photo_price=$result['photo_price']; $photo_caption=$result['photo_caption']; $photo_category=$result['photo_category']; //also do select stuff //im assuming you want to use photo_category as the value of the option //explanation for why $row is wrong is below echo "<option value=\"$photo_category\">$photo_category</option>"; } ?> Now, conceptually, you don't seem to understand what mysql_fetch_array() returns to you. It returns an array, but you are using it like a string in the following snippet you posted <? echo "<select name='photo_category' size='1'>"; while( $row = mysql_fetch_array( $result ) ) { echo "<option value=\"$row\">$row</option>"; } echo "</select>"; ?> You need to supply an index, rather than trying to echo out the whole array. If you were to leave this snippet like it was (assuming you fixed your other problem) You would have a select box all with values equal to "Array" and the text for the options would be "Array". To fix this, you need to determine which column you want to populate the options with from your result set, and use those options as keys to the array $row. For example, if the column you wanted was called 'photo_category' (and it seems like it might be in your case) you would do <? echo "<select name='photo_category' size='1'>"; while( $row = mysql_fetch_array( $result ) ) { echo "<option value=\"".$row['photo_category']."\">".$row['photo_category']."</option>"; } echo "</select>"; ?>
  25. there are many ways to do this, but one of the most common way is to create an MD5 or Sha1 hash of something unique to each user in the database (like perhaps their username, or email address, assuming that these two things are unique to each user (and they should be))
×
×
  • 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.