Jump to content

justsomeguy

Moderator
  • Posts

    31,575
  • Joined

  • Last visited

  • Days Won

    77

Posts posted by justsomeguy

  1. Well if $q . =$id works for that code then it should be okay for the task I need it for.

    What?  If any arbitrary line of code works on a page that displays shopping cart information, then the same line of code belongs in any other page that uses the database?  OK, if you say so.  You're the programmer.

    This is fine with no syntax problems, but would this work.

    Of course not, look at the SQL query you're trying to build.  It's not a valid SQL query.

  2. That's right, you have a syntax error in that PHP code, and I also questioned why you were treating $_SESSION['user_id'] as an array when that doesn't seem like it would be an array.  And, whether or not that foreach loop runs at all, the SQL query is also going to have a syntax error in it.  If that IS an array, and let's say it has 2 values, then you've built a SQL query that looks like this:

    SELECT * FROM forum WHERE user_id IN (0, 1

    That's not right.  If it's not an array, or an empty array, then this is your SQL query:

    SELECT * FROM forum WHERE user_id IN (

    That's not right either.

    So, yeah, I'm wondering why you're using that code to build a basic select query to select the data you want from the database.  You shouldn't have to copy and paste code to do this, if you understand how select queries work then it should be pretty apparent how to write the query you need to get the data you're looking for.

  3. I just thought it may be required.

    It's required if you need it, as the programmer.  That's your job to figure out, you're the programmer.

    I have never displayed anything from the db that is related to a user.

    It doesn't matter that it's a "user", the database does not distinguish between the different "objects" that you try to store in the database.  What the records mean to you does not matter, it does not change how to retrieve them.  Every table in the database holds records, and getting records from a database table is the exact same regardless of what you've decided to name the table or the fields.  You still use a select query.  There's not a particular unique query for "getting users" versus "getting videos" or "getting comments" or whatever else.  They all use the exact same kind of select query.  You're the one that is making the distinction here, not the database.  The database doesn't care what the records mean to you, it does not store things or retrieve things differently just because they have a different meaning to you.  That's why you're not finding specific instructions about "how to add a comment" or "how to add a profile" or whatever else - the actual data does not matter, it does not change the programming.  You're supposed to learn the generic principles about this and then apply it to your own situation, but you've skipped the part about generic principles and instead are trying to find tutorials or videos or whatever that relate directly to your specific situation.

    So having viewed the code from the shop/ cart files, I am comparing and seeing what there is there, that is displayed from a db, to get the idea on how to display a comment posted by the logged in user onto their profile index, which is public, but linked from within the home.php once logged in, so profile link goes to index of profile and displays posted comment.

    It's simple, and is the exact same way you display any data from the database on any other page.  You use a select query to tell it what data to get, and then you display it.  Do you really think the database cares that the page where you're trying to display the data is linked from "home.php?"  Do you think that matters at all?  Or that it's "public" (whatever that means)?  Or that you're also going to be checking the session to see if someone is logged in?  None of that matters.

  4. I took it from the shop/cart file.

    Yeah, I see that.  Why did you do that?  What does adding an item to a shopping cart have to do with displaying a forum?  You've added a PHP syntax error and there's also going to be a SQL syntax error in that code, so none of that is going to run.  Displaying records from a single database table is pretty easy, that's not something complex enough that you need to copy some other piece of unrelated code and try to change it.  The changes don't make sense, you're trying to loop through $_SESSION['user_id'] like it's an array.  Why would that be an array?  That doesn't make sense.  None of this code makes much sense, you're trying to take an unrelated piece of code and change it into something that should be easy to do by itself.

    I took this from that file, not sure if that has any use for it. But need a get iD?

    I don't know, do you?  You're the programmer, do you need to pass an ID of something in the URL?  Does that accomplish some goal that this page needs?

  5. It sounds like you have something that is confused about your code and thinks that the string inside your Javascript code is actually HTML code instead of a Javascript string.  The bug is in whatever is giving you that message, assuming the rest of your HTML code is structured correctly (e.g., that Javascript code is inside a script element).

  6. If not even that first console.log works then it sounds like it's not running at all.  If the first alert works but not console.log and not the second alert, maybe the browser that you're using does not have console.log defined.

  7. That O'Reilly book seems pretty good, 400-odd pages is about what I expect for an intro to PHP, and the reviews are generally positive.  There are higher-ranked O'Reilly PHP books, but many of them deal with additional technologies like MySQL and Javascript, not just PHP.  I would stay away from Amazon's #1 book in PHP programming though, which is the Kindle edition of "The Super Easy Sous Vide Cookbook: 575 Best Sous Vide Recipes of All Time".

  8. That code is from a book?  Yeah, that's kind of crap, they don't bother to check the error code for the uploaded file and they're trying to use the try/catch block that is pointless.

    Which book did I suggest?  I normally only suggest recent O'Reilly books, which I expect to contain decent code given their reputation.

  9. Quote

    I already put the braces in, then it didn't change anything.

    Then you 1) didn't do it correctly, or 2) didn't notice a different basic syntax error.  I pointed out multiple syntax errors, and the presence of any one of them, again, will cause the entire thing to break.  So, did you fix all of them?  Did you fix the braces correctly?  I don't know, and if you don't know either then that's a problem.  Because in the most recent code you posted, you definitely did not, and for some reason you're still trying to use a try/catch block.  Which I have no idea why.  And I've told you this.

    This whole thing is like someone who refuses to learn the basics about the Russian language but still thinks they can call someone who only speaks Russian and ask them what time it is.  I don't know why you think programming is as easy as you think it is, but it's not.  You can't just skip over all of the basics and expect to be able to do anything, I don't know what other skill set is like that and why you think programming is one of them.  What you're trying to do is very easy for someone who knows PHP, but you don't know PHP.  Just like asking a Russian speaker for the time is very easy for someone who knows Russian.

  10. Yeah, there's nothing more that I can add.  You have several books about PHP but you've never started at the beginning, you always try to jump ahead to something that you're trying to do.  Maybe after a couple years of trying and failing you'll realize that doing that was not a good idea.  There's nothing else to add, if you don't understand the basics you won't be able to do anything, and I don't understand your reluctance to just read from the beginning and make sure you understand everything.  I really hope it's not an issue of you not wanting to spend the time to do that, because you have wasted a tremendous amount of time already trying to do things that you never bothered to learn how to do.  If I point out basic errors five times and you still don't understand, then I'm not helping, and I can't help if you don't know what I'm talking about in the first place.

×
×
  • Create New...