MySQL Query Without Repeating Same Data

Jun 28, 2007

Each piece of data in my table has a category field associated with it, making multiple items with the same categories. I want to create a MySQL query that will only grab the different categories associated with the data in the table. Code:

View 1 Replies


Keep Repeating The Same Select Query?

I didn't want to keep repeating the same select query, so I wrote this function. But it doesn't work:

function select($what, $table) {
$query = mysql_query("SELECT $what FROM $table");
select(*, products);

View 5 Replies

Strange Inconsistences When Repeating A Query More Than Twice In A Row

Here is a small sample program I wrote in PHP (running off Apache
1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data
base is using DB2 V5R3M0. The client is WinXP machine using the iSeries
Client Access Driver ver to connect to the database.

The problem is that executing the exact same SQL select statement more
than twice int a row stops produces results. The first two instances
will always produce the correct results but after that it will simply
return with no results found. I've also wrote the exact same test case
with other various ODBC APIs with the same results.

I've examining the ODBC driver trace log and I am unable to find any
noticable differences between a SQL statement producing the correct
results and one that produces a no results found message. I've tried
three different ODBC driver versions and have the same results.

NOTE: This doesn't occur for EVERY select statement but it does occur
for different files with various WHERE clauses but I've been unable to
determine any relationship between working and non working repeating
select statements.


View 13 Replies

Display SQL Query Results In A Repeating Table?

This is my first post here, but i've lurked for a while. I'm working on a website but have come across a major stumbling block in the code: I've managed to structure the search query but have 2 problems: I dont know how to code the results into the table, and make the table repeat itself 5 times per page (and recognise it needs a new page) And I cant test the search query because i cant get the results to display.

If any one could answer 1 or more of these problems and/or correct any error's i've made I'd jump for joy, as i feel i've been fumbling in the dark for the last week or so. Here's my code so far:

$connection = mysql_connect($hostname, $username, $password);
if (!$connection) {
die("A connection to the server could not be established");
//remember to select the database!
mysql_select_db($database) or die("Database could not be selected!");

View 3 Replies

Session Data Is Random - View Own User Profile Shows Users Data From Session But Is Repeating The Data

I have a folder called sessions outside the public_html folder so it cannot be accessed in a browser and not accessed by anyone else as i am on a shared host. With my previous host everytime i logged in to my own website i could edit the session file and see all the users data in there. For some reason on my new webhost when i login and try and view the session data in the session file all i see is one very long random string.

Problem is i don't know why this is happening, i see no user data in there just a long random string. It is causing my website problems as for example, when i login the main control panel page shows my name which is stored in the session which is good but when i go to edit profile page no data is being shown in the form boxes from the session, just blank jet on my old host it shows data like it should. another problem is the view profile webpage is also repeating the user data, again strange as it is coming from session yet for example instead of showing the username once it is showing it multiple times (repeating iteself). As i say my site has never gave me problems on old webhost.

1) Confused why session file has a random string and not users data in there, i can only think of there is some feature on there server that serializes the data in the session files, althou i have never heard of this.

2) It displays my name fine on main control panel page but on edit profile no data is shown from session in the form boxes.

3) view own user profile shows users data from session but is repeating the data.

View 2 Replies

Repeating Data In A Column

I am having problems repeating in the "Availability" column. The result which goes in the column is done in the math below the query so its not in the recordset. How would I get this information to repeat? Currently, it lists the same value as the first record called "Test Program". I have attached a photo to make it a little clearer.

<?php # /programs/index.php

// Connect to the MySQL server and database.

// Query the database for user information.
$query_programs = "SELECT program_id, program_name, DATE_FORMAT(program_date, '%M %e, %Y at %l:%i %p') as convdate, program_coordinator, program_seats, program_registered FROM programs";
$programs = mysql_query($query_programs) OR die ('Cannot retrieve program information.');
$row_programs = mysql_fetch_array($programs);

$number1 = $row_programs['program_seats'];
$number2 = $row_programs['program_registered'];....

View 3 Replies

Transfer Mysql Query Data Into Json Data And Write Into A File?

I use some code here, transfer mysql query data into json data and write into a file. where is the problem? why the file is zero kb?

while($row = mysql_fetch_array($Query)){
$arr = array ('name'=>$row['name']);
$jsondata = json_encode($arr);


View 4 Replies

Echo The Data Without Repeating The Heading 'Shareholdings'?

I'm having trouble displaying certain data in a table. For example, where a person has shares in more than one company - I'm not sure how to echo the data without repeating the heading 'Shareholdings'.

$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
echo "<table CELLPADDING=5 border=1>";
echo "<td>Shareholdings</td>";
echo "<td>".$row['ShareOrg']. "</td>";
echo "</table>";

View 13 Replies

Perform A Query Where List All Of Records While Repeating One Records?

Say I have a list of names each with an id number ranging from 1 to 10. Is it possible to perform a query where you list all of these records while repeating one records. For example could I do a query that lists record number 6 then 10, 9, 8, 7, 6 etc. Or another example would be listing record number 10, then 10, 9, 8, 7, 6 etc?

View 6 Replies

PHP MySQL Query Not Displaying Data

I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.

Now, the problem that I am running into is that when I don't update the
primary key field (keyid) the page is running into the section where it
displays a message that the keyid already exists. This only happens
when the keyid on the previous page is not changed.

Upon troubleshooting the problem I found that the very first SELECT
statement does not seem to be returning any rows despite the fact that
the statement, when run on the SQL server, returns exactly one row. If
any could provide some assistance with this matter, I would be most

header("Cache-control: private"); //IE 6 Fix

//continue if authenticated
if ($_SESSION['auth'] == 1)

//get variables from post
$keyid = $_POST['keyid'];
$username = $_POST['username'];
$corpid = $_POST['corpid'];
$usergroupname = $_POST['usergroupname'];
$oldkeyid = $_POST['oldkeyid'];
$oldcorpid = $_POST['oldcorpid'];
echo("Keyid: $keyid");

// Connect to MySQL
mysql_connect ("", "user", "pass")
or die ('I cannot connect to the database because: ' .
//select database on server
mysql_select_db ("seniorproject");

//SQL Statement
$sql = "SELECT keyid, corpid FROM users
WHERE keyid='".$keyid"'";

// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
echo mysql_result($result,0);

// Count number of matches and print to screen
$numrows = mysql_numrows( $result );
if ($numrows == 1)
{echo(" SQL Query: $sql");
$result_ar = mysql_fetch_row($result);
$result_ar = mysql_fetch_row($result);
$dbkeyid = $result_ar['keyid'];
$dbcorpid = $result_ar['corpid'];
echo("<br> CorpID: $corpid <br>");
echo(" DBCorpid: $dbcorpid <br>");
echo(" DBKeyID: $dbkeyid <br>");
if($dbcorpid == $oldcorpid)
//If this condition is true, then KEYID has not changed. Execute

// Formulate the query

$sql = "UPDATE users
SET corpid = '".$corpid."', username = '".$username."',
usergroup = '".$usergroupname."', keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."'";........

View 2 Replies

MySQL Query Not Printing Out Data?

I'm trying to retrieve some data from my table only for some reason I cant get it to return anything.

$curr_uemail = mysql_query("select * from produgg_users where = ".$usersClass->userID().") or die(mysql_error())");
$arr_uemail = mysql_fetch_array($data);
while($arr_uemail = mysql_fetch_array($data))


View 2 Replies

Selecting Data From Mysql Query?

I am currently creating a website, and I want a MySql query to take some information from the database and show it onscreen. I want it to match the username that is in the session to the one in the database then select a field. This means that the usernames information comes up and not anyones else. Is this the right approach and secondly could anyone give me any hinters to how to do this.

View 9 Replies

Displaying Data From A MySQL Query?

Displaying data from a mySQL query.Here is the run down-the mySQL pulls out something like this:

Cat Name 1 Product Name1
Cat Name 1 Product Name2
Cat Name 2 Product Name3


In Dreamweaver where I constructed the query, if I test it, all rows return as you would expect.If I output results through a normal repeat region and dynamic text, also no problem.

Here is the mySQL query:
$colname_rsProductRange = "-1";
if (isset($_GET['productRange'])) {


This displays a category name, then lists the items in that category without repeating the category name.The only hiccup is that first row return that disappears.

View 3 Replies

Query Mysql To Find 'missing' Data

Every week users are required to enter data about a specific store/shop into the mysql database. I want to query the database to find out who hasn't done it, and output it in a csv file. Code:

View 4 Replies

Manually Add Data To MySQL Query Array?

I've just started using Codeigniter, and am loving MVC. I have a simple mysql query in a model that returns an array of rows to my controller.

$query = $this->db->get('shows');
return $query->result();

Date information is stored in the database as mysql date (yyyy-mm-dd) and I explode to get month mm and day dd. What I'm wondering is, is there any way to manually add the variables for month and day of each row to the query result using a simple foreach? I know I could manually add each database field's value to an array, and include the month and day variables, but I'm hoping there's a simpler way of inserting them into the already existing array created by the query.

View 2 Replies

Run Mysql Query With Data From All 3 Select Options?

Does anyone have a php select option that will pull data from mysql DB and populate next select option with data. I need to have 3 select option. I also want to run mysql query with data from all 3 select options.

View 1 Replies

Transferring Data From One Table To Another Using Mysql Query

I am having two tables and I want to move the data from one table to another using mysql query. All the fields of first table(from which I want to move data) are in second table and two extra fields are there. I want to move the data of first table to second table when certain condition is satisfied. So, I have written query like,

insert into table2('field1','field2','field3','field4','field5') select 'field1','field2','field3' from table1 where 'field1'<1,'field4 value','field5 value';

But it gave me error when I ran it.. What exactly I want to do is to insert all the values of first table into second one and two extra fields that are present in the second table. But I am not able to insert.

View 10 Replies

MySQL Query With INTERVAL - Data Provided

i have the following statement:


rs.timestamp is a unix timestamp Output would be like for each row / month a numeric like '28'It Works fine, but if i have inconsistent data, like only for the past three month (not for all six month), i get no return from my Database. I would like to have every time there is not data for this month, 0 returned.

View 2 Replies

Storing Data In Array From Mysql Query?

I am working on an page that will print scheduled classes and appointments after querying a databse for them. Right now I'm trying to store the names of people with appointments in an array so I can print it after adding the classes as well. I've gotten stuck on this part and was hoping someone knew where the problem is in my code.


View 2 Replies

MySQL Query Selecting Data From 2 Tables?

I have the following MySQL query selecting data from 2 tables:

$P1itemWq = Database::query("SELECT * FROM `ca_items`, `ca_shop` WHERE `ca_items`.`itemid` = `ca_shop`.`id` && `ca_items`.`ownerid`='".$P1['id']."' && `ca_shop`.`type`='weapon' ");
$P1itemW = Database::fetch_array($P1itemWq);

However when I try to display the query data after fetch'ing it into an array, I appear to get 2 arrays displayed which have the same values?

// test
$P1wepCount = Database::num_rows($P1itemWq);
if($P1wepCount > 0)


View 4 Replies

Php Mysql Query Inserts My Data Multiple Times

I've been trying to execute a php script that inserts data into my MySQL database. The script works fine and inserts the data, but the problem is it inserts the data 3 times (and I've had it insert up to 5).

The query is correct as I have had it 'echo' out and it shows the query properly and when I copy it directly into my phpmyadmin SQL section, it executes only one time, so I'm not sure why it enters multiple times when executed through php.

The other weird thing is that I have an Apache server running on my computer for testing and sometimes the same script will insert multiple times on my computer, and only one time on my host server and vice versa.

Has anyone else ever experienced this problem? Any help would be appreciated. If you'd like to see a snippet of the code, let me know and I can paste it because it is a bit lengthy.

View 1 Replies

MySQL Query Not Calling Data Based On Variable?

Im trying to call all users from a database with the same interests as the current, logged in user on my website.

I have the following

// Get Session USER interest
$interestsquery = "SELECT `interest` FROM `user_interests` WHERE `user_id` = " . $usersClass->userID();
$result = mysql_query($interestsquery);[code]....

the interests_query seems to work, can anybody see where im going wrong?

My problem seems to lie here...

$interest1 = $interests['1'];
$interest2 = $interests['2'];
$interest3 = $interests['0'];

//USers with Same Interests
$interest1 = 'footy';

If I manually assign a value to $interest variable it works, but i need to get use the value from the array above,

View 3 Replies

MySQL Checking Data Between Tables With Long Query?

This is a more detailed question as my previous attempt wasn't clear enough. I'm new to MySQL and have no idea about the best way to do certain things. I'm building a voting application for images and am having trouble with some of the finer points of MySQL

My db



This query was working fine before I tried to add in the 'hasvoted' boolean:

SELECT id, file_name, total_votes FROM _images WHERE approved = 1 ORDER BY total_votes DESC LIMIT ".($page*5).", 5

At the moment I'm also storing the vote count in the _images table and I know this is wrong, but I have no idea about how to tally the votes by image_id and then order them.

View 1 Replies

Read Onthefly Data Form And Use It In A MySQL Query?

this is my first post here and hope that someone could help me with my PHP/MySQL problem.I need to create a form that could grad on the fly some variables like name, surname, a checkbox and list choices and use one of them as a search string in the MySQL database table.I wrote this for the PHP Form:

PHP Code:
<form action="DUNNO-WHAT-TO-WRITE" method="get">
Which is your favorite color:<br/>
<select name="id_color">

View 3 Replies

Show MySQL Query Data Table And Export It?

I have two check boxes for query input and then the query result table. I would like my users to be able to download or save the resulting table to a csv file. I failed to do these two thing the same time.

View 2 Replies

Inserting Data From Array Into MySQL Query Generated By While Loop

Without a doubt this issue is dead simple so please excuse the ignorance. Also not sure what I should search for to find a solution, which must already exist on the forum.

Here is my code without any repetition and it works fine. The id is retrieved from the database and is successfully passed to the query, which I have verified updates the categoryID for the correct row. Code:

View 3 Replies

Copyrights 2005-15, All rights reserved