Jump to content

phppup

Members
  • Posts

    683
  • Joined

  • Last visited

Everything posted by phppup

  1. It was: $query = "SELECT carrots, COUNT(carrots) FROM $mytable WHERE carrots>0 GROUP BY carrots ORDER BY carrots ASC"; $result = mysqli_query($link, $query) or die(mysqli_error()); Until I changed all the CARROTS to $item. The loss of values did not occur until I altered the while statement.
  2. I am UPGRADING some old files to MySQLi and while doing so have decided to complete some leftover projects. In this project, I was counting vegetables sold to customers that displayed a report displaying information like this: There were 3 orders for carrots for 1 lbs. each There were 2 orders for carrots for 2 lbs. each There were 1 orders for carrots for 3 lbs. each The code I used to generate the messages was: while($row = mysqli_fetch_array($result)){ echo "There were ". $row['COUNT(carrots)'] ." orders for carrots for ". $row['carrots'] ." lbs. each <br />"; } At the time, I was going to call a separate script for carrots, potatoes, and celery. Now, with my worldly advancement (or maybe not.. LOL) I realize I should be able to use the same single script and assign a variable to accommodate each vegetable item. After declaring the $item = 'carrots' I inserted it to test my theory. I tested the output in stages and all seemed okay until I did this: while($row = mysqli_fetch_array($result)){ echo "There were ". $row['COUNT($item)'] ." orders for carrots for ". $row['$item'] ." lbs. each <br />"; } Is there an issue with using a variable inside a $row? Is there a syntax error (no error messages)? Perhaps a MySQLi addition that is required?
  3. A silly question, since simply fixing the error would likely take less time, but my curiosity won't stop nagging me. I have several php pages that ALL use the INCLUDE file connection.php which has the following scripting $conn = mysqli_connect(...etc, etc,etc,); Everything works fine EXCEPT for a few pages which were written using $DBCONN instead of $conn Can I somehow alter the value of $DBCONN so it is equal to $conn And interpreted correctly without having to change the mistaken variable in the pages that use $DBCONN ? I tried a quick $DBCONN = $conn; but there was no effect, so I thought I'd ask.
  4. Now that I'm playing with ERROR messages, I see that or die(mysqli_error()) provides the line number that corresponds to the coding issue, but differs from or die(mysqli_error($conn)) which specifically gave me a reason for the unsuccessful effort. Is there a simple way to display BOTH pieces of information, or does an IF statement need to be created?
  5. It is rather unfair of you to force me to think so decisively. I was doubting my code, rather than simply verifying the easy (and stupid) mistakes. I got it now. Thank you, as always.
  6. I have many BLANK lines for easier reading in my coding. My first ERROR MESSAGE read: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/..... on line 368 So, I commented out line 368 $result = mysqli_query($conn, "SELECT * FROM $table WHERE id = $record_id "); //or die(mysqli_error()); This took me to the following: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/.... on line 378 $row = mysqli_fetch_array( $result, MYSQLI_BOTH ); which is required to fill fields with data from my table. I guess I need to fix the fetch and the mysqli_error for a fully acceptable coding result.
  7. I am updating some old code to the IMPROVED version of PHP and running into a problem in this section after connecting successfully to my database: // retrieve the record that was selected $record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : ''; //check for $record_id emptiness if(!empty($record_id)){ // Retrieve ALL the data from the "example" table $result = mysqli_query($conn, "SELECT * FROM $table WHERE id = $record_id ") or die(mysqli_error()); // store the record of the "example" table into $row $row = mysqli_fetch_array( $result, MYSQLI_BOTH ); } Not sure what I'm missing or what needs to be re-organized. Please advise.
  8. Can I simply change the MP4 extension to AVI just to confirm functionality?
  9. I opened the webpage in both Firefox and Chrome and got the same result. I'm going to conclude that since these are the same browsers that played the video from W3 (both while at their URL and after saving the file locally) that it is not a browser issue. How do I proceed regarding the codecs, or is their a simpler / more effective way to make a simple screen recording for use on a webpage?
  10. This is a first time effort to create a video of my local pc workstation screen. Attempt #1 utilized an application provided in Windows 10 to create the MP4 file. Attempt #2 was to convert a Powerpoint 2010 presentation into an MP4 file Both seemed to go well, and produced files then when clicked independently on the desktop, will play their clip. However, when called from a local webpage "No video with supported format" is the message displayed where the working video is expected. <video width="400" controls> <source src="mov_bbb.mp4" type="video/mp4"> <source src="mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video. </video> <video width="400" controls> <source src="Presentation2.mp4" type="video/mp4"> <source src="Presentation2.mp4" type="video/ogg"> Your browser does not support HTML5 video. </video> I borrowed a video clip from W3 and it seems to work fine, which leads me to believe that either I am creating a damaged file or the file is not truly MP4. The file PROPERTIES indicate it is MP4 in all instances. Where did I go wrong?
  11. You are correct. Located the problem and remedies it. So, if I make the EMAIL column unique, how would I trigger an error message to the user when a duplicate email is entered, without querying the table?
  12. More info..... Here is my original code that works well PRIOR to attempting to acquire the LAST INSERT ID: $query = "SELECT * FROM table WHERE email='$email' "; //checks that email is unique $result = mysqli_query($conn, $query); //RUNS the above query if (mysqli_num_rows($result) == 0) { //if no duplicates exist, then INSERT $sql="INSERT INTO $table..... etc etc } So the question remains, how do I retrieve the LAST INSERT ID without having duplicate entries into my table, and without restructuring my code too drastically (as to affect other portions that use the same CONN).
  13. Fought with code until I eventually put this after my INSERT statement: if (mysqli_query($conn, $sql)) { $last_id = mysqli_insert_id($conn); echo "New record is: " . $last_id; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } I finally got the ID value, except all entries into the table are being duplicated from each single form submission. It appears that this is because $sql is being called twice. I even tried to put this into a function (didn't execute at all). How do I get to a single table posting?
  14. I'll research this. Do the ID's then become 'attached'? Am I better off creating a single form that requests ALL the info and delegating it to post accordingly?
  15. I don't mean to bother you with silly questions, but I must be using the wrong search terms to find any viable answers to this. Hypothetical situation: I have a table [Customers] with with an auto-increment id, customer_name and email generated from a form. Now, I decide to expand my database to include customer-address and telephone number. I decide to create a second table named Contactinfo for this purpose (assuming this is a better database practice). As Customerinfo is generated, I want it to POST in association with the respective customer (assuming that 'id' is the best field for association). I need some examples and best practices to accomplish this. Examples, links, or preferred terminology would be great so I can attack this phase. Thanks.
  16. Okay, got it. Yes, dates are in table. I believe I used SQL previously and this will add to it. If I'm not mistaken, I also used a PHP adaptation to test outside of the table (so that I could get comfortable with it and see results more easily).
  17. Barand, will that work in PHP or is that SQL only? If only this were a leap year I could test it in real time. LOL
  18. On a related note, I now have the basics to send a message to people listed in a database on their birthdate. It has occurred to me: what is the best way to deal with people with February 29 as their birthday? While the most simple solution would be to just forget them, that seems unfair. LoL Would the more practical approach be coding along the lines of: if(today +1) = March 1, then also include 2/29 from birthdate column? Will something like that work? Is it practical? Is there a better way?
  19. I may implement it. But I thank you either way. Just fiddling around, so it's not a major component of anything I am working with. And I'm actually happy to see that my own thought process to develop my own script to overcome this was along similar lines. Although yours is much, much cleaner and concise.
  20. At this point I clearly have too much time on my hands, as I started to tinker with different DATE options. $originalDate = 2003-03-03; //March 3rd, 2003 is the day number 62 in that year $day_of_the_YEAR = date("z", strtotime($originalDate)); //provides the day of the year starting with ZERO on 01/01 echo "($day_of_the_YEAR + 1)"; //allows me to ADD the ONE to compensate for the ZERO that begins the counter This is all OK, but then I tried to incorporate the English ordinal suffix by using the date format mechanism S. Not only did it not work, but when I edited my code to: $day_of_the_YEAR = date("zS", strtotime($originalDate)); echo "($day_of_the_YEAR)"; //because it won't work at all with the PLUS 1 the result for echo $day_of_the_YEAR was 61rd [which is neither accurate for March 3 nor acceptable as the correct English ordinal suffix. Is there a remedy, or is this due to trying to combine a non-date with the S switch?
  21. Already worked around the issue with a simpler and more effective solution. Just wanted to see if I could pull off something fancy. More trouble than it was worth, but a good learning experience. Thanks again.
  22. Something else I learned now. I had a hunch, but i thought it was worth a try to see if I could use CLASS in similar fashion to getElementById. It seems the short answer is NO. Thanks.
  23. I have used an assortment of document.getElementBy.... to retrieve data If (document.getElementById('xyz').value >10) { do this... or that.. etc. I have a group of items with radio buttons and will assign a function if the element ID is A, perhaps a different function if the ID is B, or C etc. Now I want to assign an element by its CLASS. How can I incorporate the desire that if the element's CLASS is "bluebackground" then alert("This is of blue background class") I had tried if(document.getElementsByClassName("bluebackground") == true) { alert("message of choice"); } And other variations, but something is not connecting.
  24. Awesome. Thanks again for the education.
  25. In a related problem (which is more PHP) , I now have a SELECT statement to generate a list of people with the same birthdate. I also have a formula that will calculate age with a birthdate from a form. How and where (in relation to the SELECT) do I place the adapted formula so that it uses the birthdate (stored in my table) to calculate the ages of the listed people with the given birthday?
×
×
  • 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.