PHP - Moved: Querying Events From Mysql Db, In 2 Tables
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=334481.0 Similar TutorialsHi, I'm very new to PHP and have managed to get through most of the problems I've encountered so far, but I have got to one point that I can't seem to solve. I have two mysql tables (Categories & Products), I have a page that shows the categories (generated from the categories table) and when a category is selected it lists the products in that category. Due to stock etc. not all categories always have products associated to them. The Category & Product Tables are automatically updated, so what I need to do is only show categories that have products associated to them, both tables have a column category_no, and nothing I've tried so far seems to work. The code I have so far is:- Code: [Select] Require_once('config.php'); Mysql_connect(db_host, db_user, db_password); @mysql_select_db(db_database) or die( "unable to select database"); $query="select * from categories"; $result=mysql_query($query); $num=mysql_numrows($result); Mysql_close(); Thanks Pete This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305750.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=322398.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=332033.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308347.0 I have a table in a mysql database with 5 columns, id, Name, Wifi, Bluetooth, GPS, with rows that are for example 1, Galaxy S2, yes, yes, yes. So basically i want to build a form that has check boxes (3 checkboxes for wifi bluetooth and GPS respectively) that once selected will query the database depending on which check boxes are selected. I have made the form but need to know what to put in the filter.php to make the results be displayed accordingly. Ideally if anyone knows how i would want it so the results were shown on the same page which i believe u need to use ajax to happen but any help on how to show the results will be greatful. the code for the form i have made is as follows: Code: [Select] <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test</title> </head> <body> <form action="filter.php" method="post"> <INPUT TYPE=CHECKBOX NAME="option[]" VALUE="Wifi" id="r1">Wifi <INPUT TYPE=CHECKBOX NAME="option[]" VALUE="Bluetooth" id="b1">Bluetooth <INPUT TYPE=CHECKBOX NAME="option[]" VALUE="GPS" id="g1">GPS <input type="submit" name="formSubmit" value="Submit" /> </form> </body> </html> im not sure on how to make the filter.php page but i do have this code for displaying the all the data but i want to kno how to make it only display the data from the choices on the checkboxes Code: [Select] <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>pls work</title> </head> <body> <?php function h($s) { echo htmlspecialchars($s); } mysql_connect("localhost", "root", "") or die (mysql_error()); mysql_select_db("project") or die (mysql_error()); $result= mysql_query('SELECT * FROM test') or die('Error, query failed'); ?> <?php if (mysql_num_rows($result)==0) { ?> Database is empty <br/> <?php } else { ?> <table> <tr> <th></th> <th>Name</th> <th>Wifi</th> <th>Bluetooth</th> <th>GPS</th> </tr> <?php while ($row= mysql_fetch_assoc($result)) { ?> <tr> <td> <a href="uploaded-images/<?php h($row['Name']); ?>.jpg"> <img src="uploaded-images/<?php h($row['Name']); ?>.jpg" alt="test"/> </a> </td> <td><a href="textonly.html"><?php h($row['Name']); ?></a></td> <td><?php h($row['Wifi']); ?></td> <td><?php h($row['Bluetooth']); ?></td> <td><?php h($row['GPS']); ?></td> </tr> <?php } ?> </table> <?php } ?> </body> </html> Hey there... I'm so stuck on this problem I was hoping someone could help... I need to query a MySQL Database using array values... Here is my array ... $query_keywords = Array ( [7] => business [10] => home [11] => depo ) Here is my php ...$query = "SELECT * FROM product WHERE product_name, product_comment IN ($query_keywords)"; $result=mysql_query($query); if(mysql_num_rows($result) > 0) { echo "results"; } else { echo "no results"; } Unfortunately, I get this ... Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in blah\blah\results.php on line 99 Please help me All comments greatly appreciated... I created a simple search box which will query my table and match the input value to one of my columns. two of these columns store comma separated values. if i query a column other than a column which stores my csv i can see my search results. if i query a column which stores my csv i will not see results unless the search value matches the first value within the column. how would i be able to get say the second or third or forth value. here is the code i am using to query the table any help would be appreciated thanks. Code: [Select] $q = $this->db->query("SELECT * FROM table WHERE col1 LIKE 'searchvalue'". " OR col2 LIKE 'searchvalue'". " OR col3 LIKE 'searchvalue'". " OR col4 LIKE 'searchvalue'". " OR FIND_IN_SET('searchvalue', col5) > 0 ". " OR FIND_IN_SET('searchvalue', col6) > 0"); Hi guys, Im having problem on how to achieved this one.. I would like to get the all event of this month (April ) Starting todays date.. Code: (php) [Select] $now = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+8, gmdate("Y"))); $week = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+30, gmdate("Y"))); if ($result = mysql_query("SELECT * FROM fiesta WHERE sta_date BETWEEN '$now' AND '$week' ORDER BY sta_date LIMIT 10")){ if (mysql_num_rows($result)) { $return = ''; while ($row = mysql_fetch_array( $result )) { $date = date("D",strtotime($row["sta_date"])); $return .= "<a href='sta.php' style='font-size:11px;' title='" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "'>" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "</a> ($date), "; } echo rtrim($return, ', '); } } The result of this query will include the events on May.. How can i display only the event on this month(April)? starting todays date. Thank you I created a "statistics of site" page, stats.php. Currently stats.php updates every visit, that's over 25 queries for every visit, with over 9,000 visits a day, I wish to cut down. What is the best way to make it so all queries are done every hour, therefore requiring less queries to the database? I assume the best way to go at this would be either to run a time() based script every 60 minutes and: - update this to a new field, then stats.php will require 1 query every visit, plus the 1 every hour. or - update a text file and read that each stats.php visit, meaning just the 1 query every hour. Now, I understand the second option will run much less queries overall, but is it the best way to go? Is there a better way to go about doing this? This portion is kind of stumping me. Basically, I have a two tables in this DB: users and users_access_level (Separated for DB normalization) users: id / username / password / realname / access_level users_access_level: access_level / access_name What I'm trying to do, is echo the data onto an HTML table that displays users.username in one table data and then uses the users.access_level to find users_access_level.access_name and echo into the following table data, I would prefer not to use multiple queries if possible or nested queries. Example row for users: 1234 / tmac / password / tmac / 99 Example row for users_access_level: 99 / Admin Using the examples above, I would want the output to appear as such: Username: Access Name: Tmac Admin I am not 100% sure where to start with this, but I pick up quickly, I just need a nudge in the right direction. The code I attempted to create just shows my lack of knowledge of joining tables, but I'll post it if you want to see that I did at least make an effort to code this myself. Thanks for reading! I am a little confused with the difference between Symfony Events and Event Listners and Doctrine Events. The Doctrine events look pretty straight forward and are primary used for entity persistence, and I have outlined my understanding below: Doctrine Lifecycle Callbacks. Single entity and single Doctrine event. Method in class. Good performance. Don't have access to Symfony services (all others do) Doctrine Lifecycle Listeners. All entities and single Doctrine event. Separate class and configured in config.service.yaml. Doctrine Entity Listeners. Single entities and single Doctrine event. Separate class and configured in config.service.yaml. Doctrine Lifecycle Subscribers. All entities and multiple Doctrine event. Must implement EventSubscriber (or probably EventSubscriberInterface) Separate class and configured in config.service.yaml.I am more confused with the Symfony events and my interpretation as listed below is likely incorrect. Symfony Event Listeners. Single Symfony event. Separate class and configured in config.service.yaml. More flexible because bundles can enable or disable each of them conditionally depending on some configuration value. Symfony Event Subscribers. All specified Symfony events. Must implement EventSubscriberInterface Separate class but NOT configured in config.service.yaml but in class. Easier to reuse because the knowledge of the events is kept in the class rather than in the service definition.Are they used for totally different purposes or can one use Symfony events to also deal with entities? Where would one want to use these Symfony events? Is there a reason why Doctrine Lifecycle Subscribers are located in src/EventListener and not src/EventSubscriber Are Doctrine Lifecycle and Entity Listeners really only for a single event as I interpret the documentation states, or is it one method per Doctrine event such as the following? App\EventListener\SearchIndexer: tags: - name: 'doctrine.event_listener' event: 'postPersist' - name: 'doctrine.event_listener' event: 'postUpdate'
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308889.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356714.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=352310.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330205.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=342956.0 This topic is now in MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=357554.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312429.0 just trying to see if i have this right in my head here.. if i have a page that has a topic on it and many replies, the tables would look like this.. would this be the right code to pull out the topic AND all responses for say. www.mysite.com/view?id=1 $topic = 'SELECT * from topics where id = $id' $replies = 'SELECT * from replies where replies.topic_id = $id' |