mysql

Two sets of indentical tables with joins using indexes in MySQL; one requires full-table scan

Hi, Im getting very confused with indexes in MySQL. I have two tables: TableA1 and TableA2. I created indexes on these for the joins between them and queries run really fast. I have another 2 tables with an identical setup e.g. TableB1 and TableB2. The only difference is that these tables have a few null values. For some reason the...

Search MySQL with PHP and display results on the same page.

Hello people. This is definately a novice question, but if you could be of any help i would be very grateful. Basically, i'm building a database management page, and it of course includes a search function. So, the search form looks something like this <form name="name" function="search.php" method="get"> But, whenever i use it, i w...

Storing Images In Filesystem As Files Or In BLOB Database Field As Binaries

Possible Duplicate: Storing Images in DB - Yea or Nay? Which approach is better? What are the advantages and disadvantages? Advantages of storing images in database, in my opinion, are: database integrity (it's easier to keep all database entries valid with foreign keys than to keep an eye on filesystem and make required ch...

SQL query: get tags associated with post

I have three tables. posts | id | title | +---------+-----------+ | 1 | hello | | 2 | goodbye | +---------+-----------+ posts_tags | tag_id | post_id | +---------+-----------+ | 1 | 1 | | 2 | 1 | | 2 | 2 | +---------+-----------+ tags | id | name | +----...

mysqli_error() expects exactly 1 parameter, 0 given

Hi, I am trying to get my head around mysql. Can someone tell my why this mysql query is not working? I am getting the following error: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/freebet2/public_html/test.php on line 11 test.php <?php require_once($_SERVER['DOCUMENT_ROOT'].'/includes/db.ph...

how do i plus one in a table column?

i've got a mysql table column that acts as a counter (int). each time i update that column i want the field value to get plussed with 1. so if it was 45 i want it to be 46. how could i do that with sql? ...

Looping through $_POST variables

Hello! Sorry i could not find a proper title to this question. I have generated the following using a for loop and I have concatenated the names of the submits buttons using the pattern below: submit_edit_category_1 submit_edit_category_2 submit_edit_category_3 echo "<input type='submit' value = 'Edit' name='submit_edit_category_" . $o...

what is wrong with this sql query?

what is wrong with this sql query. i cant figure it out. $query = "SELECT * FROM tagPairs WHERE (tag1Id IN ($tag1Id, $tag2Id)) AND (tag2Id IN ($tag1Id, $tag2Id))"; error code: Couldn't execute query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syn...

PHP calendar for Room booking with Mysql checking

Hi, As a part of my Project I am supposed to develop a Room booking Website. As an advanced feature i need to have an Calendar for each room, showing on which dates the room has already been booked. I have the list of available rooms in my database. Can any1 suggest me a calendar script that could check with the database and show if the...

get the latest inserted id in a trigger?

i use a trigger to insert a row and want to use the last created id for using in the subsequent query. how could i do this? the code looks like: BEGIN IF (NEW.counter >= 100) THEN INSERT INTO tagCategories (name, counter) VALUES ('unnamed', NEW.counter); // here i want to have access to the above inserted id UPDATE tagCategories2tagPa...

how to check if a table row exist with a trigger?

i want to check if a table row exist with a trigger. if it does then it does nothing, but if it doesnt exist it inserts a row. here is my current code i want to modify. BEGIN IF (NEW.counter >= 100) THEN // check if a certain row exists in another table, if not, execute the beneath code INSERT INTO tagCategories (name, counter) VALUES ...

Doubt regarding a database design

I have a doubt regarding a database design, suppose a finance/stock software in the software, the user will be able to create orders, those orders may contain company products or third-party products typical product table: PRIMARY KEY INT productId KEY INT productcatId KEY INT supplierId VARCHAR(20) name TEXT description ... but...

Selecting against subsets of a list in MySQL

I'm quite a begginer and I have two tables: "product" and "product attributes". Here's some imaginary data (the actual stuff involves more tables ) Products Table: product_id | product_name 10 | aaa 11 | bbb 12 | ccc Product Attributes Table: attribute_i...

MySQL query running fine on v4.1.22 but not working on v5.x

I have an application that executes the following MySQL query: SELECT 402 AS user_id, p.id AS perm_id, p.name AS perm_name, lc.business_division_id, bd.name AS bd_name, bd.current_cycle, bd.current_moon, lc.name AS cycle_name, ...

fill textbox with mysql data

How do I fill an inputbox with mysql data. So that I can update the database? I have this code that will show the table corresponding to the users request. But I don't know the syntax on how I can fill an inputbox with mysql data. $result = mysql_query("SELECT * FROM t2 WHERE STAT='{$_POST["stat1"]}'"); echo "<table border='1'>...

MySQL insert multiple fixed length values manually

Hi there, I want to insert multiple values in a table where the value in one of the column increments sequentially. However, the sequence is a bit complex because of business requirements. The single insert would go something like this: INSERT INTO blah (col1, col2) VALUES ('SU0001', 'myemail'); Now, col1 is the value that needs to ...

search mysql database

Please help, Im trying to search for mysql records using an html form to display the corresponding record for the entered primary key. Here's my html form: <td><input type="submit" name="Submit" value="Search"></td> And here's the new.php form action:, mysql_select_db("Hospital", $con); $result = mysql_query("SELEC...

Using an index for a ranged where

im storing down ranks in one of my app, and i frequently do this: select count(*) from table where score > ? and ? = the current person's score. i intend to memcache this, and i use an index on this table, is there a good way to index it? ...

With Kohana 3, how can I get the last insert ID from the Database class?

I have been through a fair bit of the code in modules/database/classes/ but still have not found how to return the last insert Id. How do I get this? ...

Random MySQL row while avoiding holes

I have a big MySQL users table and need to get six random rows from it (I'm using PHP). The table has an index column that is auto incremented. The only problem is that some rows are marked as inactive, because some users have disabled their accounts or whatever. That means I can't just count the rows and then grab a random number from t...