mysql

Weighing search results

Hey folks, PHP / MySQL backend. I've got a database full of movies YouTube-style. Each video has a name and category. Videos and categories have a m:n relationship. I'd like for my visitors to be able to search for videos and have them enter the search terms in one search field. I can't figure out how to return the best search results ...

mysql_fetch_assoc fetching only one record

Hi, I have an array with the result of a query: .....some code..... $result = mysql_query("SELECT * FROM vttest"); $row = mysql_fetch_assoc($result); print_r($row); But it only prints one record, I can't put $row in a loop because I will be working on sorting that variable later. Array ( [id] => 3 [rep] => Mike [name] => ...

Running mysqltuner on Mac OSX

I use Zend Server CE on my Mac running OSX Snow Leopard for my development environment. I need to tune up MySQL and have used mysqltuner.pl in the past on Linux servers to do pre- and post-testing. I downloaded the script and get the following errors when I run it: couldn't find diagnostic data in /System/Library/Perl/5.10.0/pods/pe...

How can I force Rails to synchronize transactions to a MySQL table across connections?

I have a high-traffic site that records web hits in a table, Hits. There's logic in place so that duplicate hits are discarded (where the definition of what defines a hit as duplicate is arbitrary for the purposes of this example). Problem: with multiple web servers running (against the same DB), two or more hits can arrive at the same ...

MySQL query to use data from 2 tables

I have a Users table and a Payments table. I need a query which lists the users who have a record in the payments table where PaymentStatus=1. It must also only list users with a certain GroupID. The GroupID will be passed by a variable, but we can just call it 5 for simplicity. The timestamp of the record (TimeCompleted) must also be ...

SQL query for nth most recent update

I have a revision table and I need to be able the nth most recent update. I have a query that gives me the most recent revision record of enitity, but I need one for the nth most recent revision record. revisions --+---------+--------+----------+------- id|entity_id|contents|revisor_fk|revised The query must take input 0 to n. If th...

How to get the correct number of columns from mysql_fetch_array()?

Hi Here is a line of my code while($row = mysql_fetch_array($result)) I want to get how many columns are in the row. I tried count($row) but this returned what I think is the number of cells for the whole $results. i.e there are actually 7 columns, and 2 rows and count($row) returned 14. I want a function that will return 7. Can yo...

Benefit to various "ID" fields in MySQL DB

In all of our current databases, we use a (null allowed) ID field which auto-increments at every new row insert as well as a particular member ID (unique to every person and every row). In essence, a person can be represented by ID=33 as well as MEMBERID=4839283789. I have debated completely wiping the ID field and only using the MEMB...

tagging words with # and @replies when submitting a form!! twitter style?

can you someone help or direct me to a good tutorial, on how to detect @replies and #tags when submitting a form like twitter? and also when retrieving the information from mysql and displaying them using php, they become links instaed of just plain texts. so basically it detects it and then makes it linkable!! i hope this makes sense!! ...

mysql simple aggregate of subquery results is slow

I'm trying to 'bin' all of my customers based on the number of items purchased, and display the counts of each bin. I'm trying to see how many people(account_id) purchased one item, how many purchased two items, all the way through nine items, and then ten or more. Here's the query I'm using - for what its worth, I'd expect the query t...

PEAR "DB.php" error using EasyPHP

Using EasyPHP I've discovered an annoying error I can't seem to fix. I searched the internet, got a few hits, but I gained nothing from these blog posts and pages. PHP and Apache works fine, but when I want to use MySQL with PEAR (which is included in EasyPHP) and when I require("DB.php") I get this error: Warning: require(DB.php) [fun...

How do I deal with an apostrophe in my MySQL database that is throwing off my queries?

I have an SQL file I created from a CSV file. It includes the names of all metropolitan areas in the United States, along with some statistics about their populations. I wrote a PHP script that takes the population data, turns it into a chart, and sticks it back in the city's row, in a different column. This script ran fine until it came...

PHP/MySQL - Geting a row from a DB

Can someone help me with my script? It's supposed to read the user's session's member_id, find the corresponding row and echo it out. But when it runs, it outputs nothing. <?php //Start session session_start(); //Make sure user is logged in require_once('auth.php'); //Include database connection details require_once('config.php'); /...

Do you know any PHP script or library to export/import dumps of MySQL databases?

I don't have shell access so can't use the mysqldump command Also the use of sentences like SELECT * INTO OUTFILE are restricted ...

PHP Mysql content sneak peek

Hi There, Just wondering if anyone has got any ideas regarding sneak-peaking the content of a mysql table? Ie. say there are 10 posts with 500 words each. I want to list all the posts with a content sneak peak... i.e display a couple of lines or 200 characters etc. for each post The thing i'm wondering is how to do that while keeping...

PHP mySQL connection problems

Ok, I am completely baffled. I am setting up an OO site. I have a class that defines all my database params, as follows: $db->host= "localhost"; $db->name= "mydatabase"; $db->user= "user"; $db->pw = "password"; The class is being instantiated correctly and the values show up in pages that appear after this class has been loaded. BUT...

How can I separate a list of SQL queries from a file?

If all queries end with ; I can explode by this char, but what should I do when a ; appears in a field? e.g. [...]Select * From my_data where idk=';';\nSelect [...] or [...]Select * From my_data where idk=';\n';Select [...] My file consists of all kinds of queries, including INSERTs and can have syntax variations like the ones s...

Django, database retrieval not working but deleting fields and adding new fields is working

I have been able to get my database queries to work properly for deleting existing entries and also adding new entries to the database but I am completely stumped as to why I am unable to retrieve anything from my database. I am trying a query such as: from web1.polls.models import Poll retquery = Poll.objects.all() print retquery --pri...

How can I alter a table to drop a column if it exists?

Before you flag this as a duplicate, I've read the other question, and it pertains to a different version of MySQL. I'm running the next up major version: MySQL version 5.0.91-community I need to drop a column if it exists, and I also need to add a column if not exists. How can I go about doing this in PHP? ...

Stumped on MySQL Query: How to select rows with a subset of values for a column?

There are two tables, a Contact Table and a RelationshipHistory Table. Contacts can have several types of relationships (Business, Individual, Volunteer, etc) which means they can have several references in the RelationshipHistory table over time. Each relationship row has a column indicating an event that the relationship is related to....