Jump to content

All Activity

This stream auto-updates     

  1. Past hour
  2. No need to prepare/execute a query with no input parameters. Just use $find_entries = $db->query("SELECT entry_id, votes FROM entries WHERE votes = (SELECT MAX(votes) FROM entries)");
  3. benanamen

    Join or Union?

    The the left join would have worked if you switched the tables around.
  4. Today
  5. Perfect! That's exactly it. Here is my updated query with your fix. $find_entries = $db->prepare("SELECT entry_id, votes FROM entries WHERE votes = (SELECT MAX(votes) FROM entries)"); $find_entries->execute(); $result_entries = $find_entries->fetchAll(PDO::FETCH_ASSOC); if(count($result_entries) > 0) { foreach($result_entries as $row) { $entry_id = $row['entry_id']; $votes = $row['votes']; ?> <div> <?php echo $entry_id; ?> </div> <div> <?php echo $votes; ?> </div> <?php } }
  6. Basics: How does your script accept input? In your case, the code provided shows you are looking for $_GET parameters. If you want to change this to use POST then you would need to check for $_POST parameters. Are you clear on what runs where? PHP code is run on the server, and a response is generated and returned to the client. Javascript is run within the user's browser. This is why you need to use the developer console to look at what is happening with your ajax code when the app is run.
  7. michaelfurey

    ajax redirect doesn't work after php insert mysql query

    Uhm I tried changing the method (post) but nothing change. In the image what happened. The status is canceled. When I insert that line the status is canceled furthermore the alert and the redirect don't work, even if the insert works well with the DB MySQL.
  8. requinix

    Trouble with showing image in url

    It's not good to take some message in the URL and show it right on the page: anyone could repurpose that message to show whatever they wanted. You'd have to do some sort of validation, "is this message okay", and that's ~difficult~. How are people getting to this page.php? Can you use a form for it? You could POST a piece of data (not a message), like whatever this thing that they found is, then page.php can look for the form data and display the message (which it figures out in its own).
  9. Barand

    mySQL and rebuilding keys

    Primary keys do not require a name. Other indexes do. If you do not provide a name, MySql will generate one mysql> CREATE TABLE test_a ( -> aaa int NOT NULL PRIMARY KEY, -> bbb int, -> ccc int -> ); mysql> ALTER TABLE test_a ADD INDEX (bbb); -- no name specified mysql> ALTER TABLE test_a ADD INDEX my_index_name (ccc); -- name specified mysql> SHOW CREATE TABLE test_a; +--------+---------------------------------- | Table | Create Table +--------+---------------------------------- | test_a | CREATE TABLE `test_a` ( `aaa` int(11) NOT NULL, `bbb` int(11) DEFAULT NULL, `ccc` int(11) DEFAULT NULL, PRIMARY KEY (`aaa`), KEY `bbb` (`bbb`), -- name generated automatically KEY `my_index_name` (`ccc`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 +--------+----------------------------------
  10. cutielou22

    Trouble with showing image in url

    I want it show something like "You found this *item here*." and have it show a picture with it - without the page messing with my layout. Is that bad or something?
  11. Perhaps you want to do something like this SELECT entry_id , votes FROM entries WHERE votes = ( SELECT MAX(votes) FROM entries );
  12. If you ever need functions like MAX or SUM or COUNT and you don't want to count the entire table at once then you need a GROUP BY clause. If you want to select a column and then use those functions on others, you should probably be GROUPing BY that first column.
  13. I have a table where I would like to find the maximum value from a certain column and retrieve a single result. But it doesn't seem to work properly. I don't get any errors. The issue is that it's retrieving the entry_id from one row and the votes from another row. But I would like the row with max value to retrieve the same row's entry_id. Here is my code. Can you see what's wrong with it? $find_entries = $db->prepare("SELECT entry_id, MAX(votes) as vts FROM entries WHERE votes > :votes"); $find_entries->bindValue(':votes', 0); $find_entries->execute(); $result_entries = $find_entries->fetchAll(PDO::FETCH_ASSOC); if(count($result_entries) > 0) { foreach($result_entries as $row) { $entry_id = $row['entry_id']; $votes = $row['vts']; ?> <div> <?php echo $entry_id; ?> </div> <div> <?php echo $votes; ?> </div> <?php } }
  14. well - i need to have any means to do this - to take a capture or screenshot in youtube clips. i want to get these captures/ screenshots to a document - where i put them in.. i look for a way to capture picture from video on a linux machine. i want to be able to take picture from a video and then i want to create a new wallpaper or use the image in a project or a presentation. is this doable - What would you recommend!? btw: what about the youtube-dashboard: can this help here in any way!? probably it would be great to work with Jupyter Notebook The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and ...
  15. TapeGun007

    Join or Union?

    Ok never mind. I got it. I had to use an INNER JOIN. I had also made an error above, the Status column was set to "Won" not "Sold". Thanks for helping me get on the right path.
  16. TapeGun007

    Join or Union?

    ON Prospects.ProspectID = Deals.ProspectID AND Deals.PIGLead = 2 WHERE Deals.Status = 'Sold' So... the ON line works sort of, but it lists clients that nothing was sold to. So I tried the WHERE above and now nothing comes up. LOL.
  17. TapeGun007

    Join or Union?

    Ok, so I was on the right track. I wrote this code: SELECT Prospects.ProspectID, Prospects.FirstName, Prospects.LastName, Prospects.Address, Prospects.Address2, Prospects.City, Prospects.State, Prospects.Zip, Deals.ProspectID, Deals.Product, Deals.Price FROM Prospects LEFT JOIN Deals ON Prospects.ProspectID = Deals.ProspectID So this works. But how can I narrow it down to just like WHERE PIGLead = 2 ? I now see why Union does not work, there would not be an equal amount of rows returned (if I'm understanding this correctly).
  18. benanamen

    Join or Union?

    You would do a JOIN on ProspectID
  19. TapeGun007

    Join or Union?

    I've been reading so many websites about LEFT JOIN, and now UNION, so before I go off on a major rabbit trail please help me figure out which is best by telling you what I want to accomplish. I'm going attach two images of my tables: The first table is called Prospects, and the 2nd table is simply called Deals. I'm going to try to write what I want in a non working version of code, but I hope it will translate what I want better: Under Table Deals, the field Status must be equal to "Sold" Under Tables Deals and Prospects, the ProspectID must match Under Table Deals, the PIGLead must be equal to 2 I want the table to show the Prospect information (name, address, phone, etc), then under the Prospect information, I want to see the deals sold to them where Status = "Sold". I want to see the Product and Price. Best method?
  20. requinix

    mySQL and rebuilding keys

    For a regular index, that "col2" would be the name of it. For a primary key (which I forgot was different) that doesn't use a name, that "col2" would be the index type. Of course "col2" and "merchandise" are not valid index types so I would have expected at least a warning. And I don't have a MySQL lying around to test with. So I'm thinking it's (accidentally?) ignored for sake of compatibility with other types of indexes.
  21. StevenOliver

    mySQL and rebuilding keys

    No -- no warnings. I created the tables with both "primary key col2 (col2)" and "primary key (col2)" and there were no warnings. Then I tried the "alter table" syntax after dropping the primary keys: "alter table Table1 add primary key col2 (col2)" -and- "alter table Table1 add primary key (col2)" ... and neither of those gave any warnings. For all intents and purposes, they seem 100% identical. Perhaps in the olden days the "...primary key col2 (col2)" was how it used to be done, then it got deprecated and now "...primary key (col2)" is how it's done today, with both commands having the same effect. What are your thoughts?
  22. requinix

    mySQL and rebuilding keys

    Where there any warnings with the "ALTER TABLE mytable ADD PRIMARY KEY merchandise (merchandise)" statement?
  23. StevenOliver

    mySQL and rebuilding keys

    show index from Table1; +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table1 | 0 | PRIMARY | 1 | col2 | A | 0 | NULL | NULL | | BTREE | | | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.007 sec) show index from Table2; +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table2 | 0 | PRIMARY | 1 | col2 | A | 0 | NULL | NULL | | BTREE | | | +--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.007 sec)
  24. requinix

    mySQL and rebuilding keys

    Are you sure? What was the output?
  25. StevenOliver

    mySQL and rebuilding keys

    I did -- I did "show index from Table1" and the result was identical to "show index from Table2."
  26. requinix

    mySQL and rebuilding keys

    Okay, so I thought a SHOW CREATE TABLE would include the indexes. Do the other SHOW INDEX FROM.
  27. StevenOliver

    mySQL and rebuilding keys

    Hmm... I did that, the results are absolutely identical. I created the tables like this: Create table Table1( col1 varchar(3), col2 varchar(3), primary key col2 (col2) ); Create table Table2( col1 varchar(3), col2 varchar(3), primary key (col2) ); What would you think I should be seeing that I'm missing?
  1. Load more activity
  • Newsletter

    Want to keep up to date with all our latest news and information?

    Sign Up
×

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.