Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Displaying Records In Single Row.


I've written the following sql,but it is displaying the results in multiple rows,Could any body advise me on how to display the returned records in only one row.....




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Displaying Multipal Records
I have a table in MYSQL

publications(ID, Year, Publicationtitle, Publication .... )

The tables called ID, the seconday key is Year,

I want to display all records with the year 7 8 9 10 11 12 and 13.

The usual code I think is

<?php echo("$row['year']")

But am not sure how to do this, any help would be good.

What would the SQL be, WHERE year=7 but would it be where year=7,8,9,10,11,12,13 ???? no??

ps. Is it possible to connect to another table as well. The page Im creating all the font size, face, background colour information is stored in another table. I could use a query but that would mean making foreign key in publications which would take up space.

Multiple Records Single Value
I have been developing a realtor intranet system. I am currently writing a php script that deals with 2 tables "property" and "photos"

property table:
id | address | etc..
----------------------------
1 56 My Road
2 389 Your Street

photo table:
id | file_id | default | property_id
---------------------------------------
1 3434... 0 1
2 343c... 1 1
3 3udu... 0 1

I have added a field "default" in the "photos" table. The purpose of this is to set the default photo for the property listing. My problem is: I want to perform a single update query as I currently only know how to perform this operation with two. eg:

$sql1 = "UPDATE `photos` SET `default` = 0 WHERE `property_id` LIKE {$var}";
$sql2 = "UPDATE `photos` SET `default` = 1 WHERE `file_id` LIKE {$var}";

Any way of doing the above 2 queries in a single query?

Update A Set Of Records In One Single Query
My records contain a position, from 1 to n. This position is not the primary key.
In normal conditions, the position of this records should be as follows:
1, 2, 3, 4, 5, 6, 7, 8, 9 . etc...

One of my utitities is meant to check the consistency of the table -
one of the things it has to do is scan the table as follows:

SELECT position FROM employe_records WHERE employe_id = ? ORDER BY position

From the result of this query I verify each entry (JDBC) one by one, looking for inconsistancies. In a for() loop I look at the value of position and check that they start from 1 and are incremented by one for each record.

At the first inconsistency I come accross I want to run a query to update the records so it is consistant again - it is something like this:

UPDATE employe_records SET position = updatedValue FROM
employe_records WHERE employe_id = ? ORDER BY position

This is not valid query of course - my question is what should my query look like?! How can I make 'updatedValue' incremented by one automatically so each of the records are updated from 1 to n.

How Can I Update A Set Of Records In One Single Query
My records contain a position, from 1 to n. This position is not the primary key.
In normal conditions, the position of this records should be as follows:

1, 2, 3, 4, 5, 6, 7, 8, 9 .etc...

One of my utitities is meant to check the consistency of the table - one of the things it has to do is scan the table as follows:

SELECT position FROM employe_records WHERE employe_id = ? ORDER BY position

From the result of this query I verify each entry (JDBC) one by one, looking for inconsistancies. In a for() loop I look at the value of position and check that they start from 1 and are incremented by one for each record.

At the first inconsistency I come accross I want to run a query to update the records so it is consistant again - it is something like this:

UPDATE employe_records SET position = updatedValue FROM
employe_records WHERE employe_id = ? ORDER BY position

This is not valid query of course - my question is what should my query look like?! How can I make 'updatedValue' incremented by one automatically so each of the records are updated from 1 to n.

How Many Records Can A Single MySql Table Hold.
I have a mysql database running on Mysql version 3.23.53 on a Red Hat
Linux 7.2. In the database there is a single table with over 150,000
records. Unfortunately, the performance of that table is very poor,
comparing to other tables in the same database.

How Many Records Can A Single MySql Table Hold.
I have a mysql database running on Mysql version 3.23.53 on a Red Hat
Linux 7.2. In the database there is a single table with over 150,000
records. Unfortunately, the performance of that table is very poor,
comparing to other tables in the same database.

ASP Not Displaying Time Stored In Mysql Displaying Date Instead.
I seem to be having a problem displaying time stored in mysql. The
format stored in the database is 13:15:05. The database data type is
time. I'm using asp vbscript and sql to retrieve the time store in
the database.

However asp recognizes the data type as date and
displays the date instead of the time. If I change the data type in
mysql to varchar then asp will display the time correctly, but I
cannot do it this way. I want to be able to convert the data type in
asp to string from date.

Lock Wait Timeout Exceeded; Try Restarting Transaction Even In Single Db Single User
I am updating few databases all which I keep as one transaction using .net connector. The best part is that I can still run into this error of "Lock wait timeout exceeded; try restarting transaction" even though I am the only single soul using my database at that time. Any idea how to over come this problem.

Displaying
I have a field value ClientNo. This will auto-increment every time a client added to the system. The auto-increment works fine. The problem that I have, is that instead of displaying the a ClientNo as 2, I would like it to display as 000002. With the extra zeros as padding. Is it possible to assign the zero value with all those added zeros from the beginning?

Displaying A Certain Value
say I have a table with two columns and the values:
4 3
7 2
12 4

how do I get the table to take max(col1-col2) and display it in every row.

as in:

4 3 8
7 2 8
12 4 8

Count Related Records, But Show Records With NO Related Records Also
cl_items
========
it_id (pk)
it_ownerid
it_name

cl_offers
========
off_id (pk)
off_itid (fk) -> to it_id
off_whoid

My query needs to output ALL of the records in cl_items AND still show how many offers are on each item (from cl_offers)

I can't get what I want through the GROUP BY because I want to show the records in cl_items which DO NOT have any offers on them yet also.

Is there any way to do this with mysql only?

All Records From Table A - All Records From Table B - Join Alike Records
I am by no means a SQl Jedi as will be apparent by my question, but I
can usually figure out a select statement on my own. I have one today
though that really has me stumped. I am working in MySQlL 5.

In My first select statement I get all my records from Table B
SELECT
`table_A`.`ITEM`,
`table_A`.`DECSCRIPTION`,
`table_A`.`UM`,
`table_A`.`PHASE`,
`table_B`.`Qty`,
`table_B`.`Calc` as calculated
FROM
`table_A`
Inner Join `table_B` ON `req_itemlist`.`ITEM` = `table_B`.`ItemID`

In my second statement I get my records that match in this case phase
401 in Table B and all my Table A records for phase 401.

SELECT
`table_A`.`ITEM`,
`table_A`.`DECSCRIPTION`,
`table_A`.`UM`,
`table_A`.`PHASE`,
`table_B`.`Qty`,
`table_B`.`Calc` as calculated
FROM
`table_A`

Left Outer Join `table_B` ON `req_itemlist`.`ITEM` = `table_B`.`ItemID`
Where
table_A.PHASE In ('401' )

Now I need to combine the Data of both recordsets. I need EVERYTHING in
Table B, but I also need All Table A records that match the phase
selection....

Can I write this one query or do I need to use a Temp table?

Displaying My Query
I have a table that has data in it that people have submitted via a form. Now I want to review that same data in the form that it was originally completed in. Is it possible to display this data, in the format by using one of the columns as an identifier..

Basically, these are work orders and if I key in a work order #, I want the work order to come up in the form, where I can review it, and then update it, after i have added comments and a purchase order #.

Displaying Information
I have inserted all of my information into my data base. Now I want to print it onto my website. I know how to get it to print onto my website, but I don't know how to organize it. I want to print the information into an table, and I want the table rows to alternate colors. Also I want to adjust font, how would I do this?

Displaying Data
I have a database with about 20 names in it. I need to be able to create a php query that will show the data one at a time so the user will have to click a button to show the next record. Any ideas on how this is done?

Displaying Dates
I need to be able to perform 12 queries (one for each month) so that the first month it displays is the month that it is, ie. if i visit the site in June then June will be the first month displayed and May will be the last month.

I know that I can DATE_FORMAT NOW() and get the actual month right now, how do I get the other months using this kind of method?

Displaying N Images In A Row
I am getting problem in displaying images after fetching from the database. I want to display 4 images in one row .But i didnt know the idea.. Could anyone help me to display the N no of images in a row..

Displaying Queries..
Currently, I have a MYSQL database, and a table within it called "links". Now, this table has a unique ID for each tutorial I add, a link to the tutorial, and a 'type' ie a photoshop/php/html related tutorial.

I primarily used this database to a) count the rows and display "we have XX tutorials in our databse", and b) to have a random tutorial display.

This code works perfectly. Now my problem.

As the list of tuts grows, it will be hard to for the user to navigate all of the tuts to find one they want. So I want to at the top of my tutorial page, include several links:

Please select a catergory:

Photoshop | PHP | CSS etc

and when photoshop is clicked, it displays all of the tutorials that have a 'type' of photoshop. How do I accomplish this?

Problem Displaying ONLY
I am trying to display records from last one min onward using the following query:

CODEres = mysql_query('SELECT * FROM album where date > "$timeout"') or die('<error>'.mysql_error().'</error>');

Displaying Results By Day
How can I display results by highest count for each day? For instance, top ten searches by day sorted by count().

Here is the code I've come up with so far, it manages to understand the current date and display some of the searches for that day, yet, does not display from highest to lowest, though the count() output works just fine.

$sql = "SELECT keyword, count(keyword) AS keywordcount,curdate() as date FROM queries GROUP BY keyword ORDER BY date DESC LIMIT 0, 10";

Here is what the db table looks like
id (auto_increment)
ip
keyword
time (datetime)

I know you might suggest using DATE_FORMAT(time,%Y,%m,%d) but i just could not figure out how to get that work correctly, maybe a BETWEEN? I think maybe the datetime format is messing it up and I need to separate days and compare.

Displaying Text
What I have are articles written by our customers that I want to put into a database table and then display them with the original formatting intact. I am using phpMyAdmin to administer the db.

I have been reading here for a while tonight and it appears that the recommended method is to store the full text article in the db table and NOT as a text file with a link in the db (e.g. /article/article1.txt).

So far - so good. However, when I extract the information back out of the table, no formatting is maintained. All of the headings and paragraphs run together to become one large paragraph - which is not very fun to read.

Displaying Coupons
I am writing a coupons system that works on the same principle as a dynamic ad system.

My table has two DATETIME columns coupon_date_start, coupons_date_end

I want to display only the coupons where NOW() falls inbetween the coupon_start_date and the coupon_end_date.

Displaying Categories
I have one table which holds all categories and subcategories. Basically, there is a parent field - if the parent field is 0, then the category is a top level category, but if it is other than zero, then it is a child category to the category with the id that is in the parent field.Hopefully you get what I mean
Basically, I'm looking for a way to make a drop down box (using php), which displays a category, then has all subcategories listed directly below it, but tabbed out a bit. Like the list of forums on the search page.

Displaying Output
i'm displaying output from table using a perl script.
i have a problem displaying the output of my table cause the content of the fields are in russian language.
in the table itself, for the fields i'm using:
Collation:utf8_bin
Type: Varchar(22)
it works normal when i look at it using PHPmyAdmin.
when i run a perl script to display the table output i see ?instead of the russian characters..How do i display it?

Displaying Info
I'm working on my picture section, i was wondering if there is a way to order how things are layed out using mysql. I want something like this


PIC 1 PIC 2 PIC 3
PIC 4 PIC 5 PIC 6
Ect ect.

Is there a way to do this and what would it be called?

Displaying All Items When Order Has Not Been Placed.
I have this SQL (I'm using MySQL)

SELECT
tbl_cottages.id,
tbl_cottages.cottage_name,
tbl_calendar.calendar_date,
tbl_bookings.id as booking_id,
tbl_bookings.book_date,
tbl_bookings.book_cottage,
tbl_bookings.book_status

FROM tbl_cottages, tbl_calendar, tbl_bookings

WHERE
tbl_bookings.book_cottage = tbl_cottages.cottage_name(+)
AND tbl_bookings.book_date = '#URL.calendar_date#'
tbl_cottages - includes all Cottage Name
tbl_calendar - has dates
tbl_bookings - this table contains any books that have been placed. So if I book 'Rose Cottage' on 'January 1' it goes into this database.

What I am trying to do is, list all the cottages in tbl_cottages, but if an order has been placed and an entry has been entered into tbl_bookings for 'January 1' I would like to display the text in 'tbl_bookings.book_status' next to the cottage on the page.

Obviously if we move on to a different date for eg 'January 2' the 'tbl_bookings.book_status' would show nothing unless an order has been placed.




Displaying Certain Dates For Certain Pages?
I am wanting to display certain dates on certain pages. For example:
newsletters.php
January 2007
Monday 15th January 2007 // link to another page to display the newsletter
Tuesday 16th January 2007 // link to another page to display the newsletter

February 2007
Saturday 10th February 2007 // link to another page to display the newsletter
Sunday 11th February 2007 // link to another page to display the newsletter

Displaying Images From Database
I am in the process of redisgning my site with PHP MySql and Smarty and I am having trouble getting the images to display when called from the database.

echo "<img src="./pages/viewimage.php?file=7">";

This is the code for viewimage.php is

<?php
include 'config.inc.php';
include 'open_db.inc.php';

$file = clean($file, 4);

if (empty($file))
exit;

if (!($connection = @ mysql_pconnect($hostName,
$username,
$password,
$dbname)))
showerror();

if (!mysql_select_db("czone", $connection))
showerror();

$query = "SELECT mimeType, img_File FROM tbl_Images
WHERE id = $file";

if (!($result = @ mysql_query ($query,$connection)))
showerror();

$data = @ mysql_fetch_array($result);

if (!empty($data["img_File"]))
{
// Output the MIME header
header("Content-Type: {$data["mimeType"]}");
// Output the image
echo $data["img_File"];
}

include 'close.inc.php';
?>

Displaying MySQL Dates In PHP
I have several fields in my database that are of type 'date'. I want to display this in a browser, but the display seems to ignore the data in each field and uses the following dates only.

Jan 19 2038
jan 1 1970

I have been using PHP's date() function to display the data.

MYSQL Displaying Images
well at the moment i am making a site and what is happening is this there is a form that you fill out and submit to a database. Now with the form there is a thing to upload images, a headline form and a message form. The headline is first hten the image uploader then the message. This is the tricky part. Should i on the page with the form put an image uploader in the form page and make the image upload and reload the page with the img tags which submit to the database (Do Img tags allow you to show images in mysql?) Or does anyone know any better ways i can show the article with the image used. That way the image is still uploading to the server but the link of the image is stored in the database and can be pulled out in [img] tags (if they can be used)



Displaying Data From A Row With SELECT
When someone clicks on a thumbnail image in my gallery.php page it takes them to my view.php page which is where this code is. The large image displays properly and the "im_name" is printed in bold.

But from the database I have comments "im_comments" about this image that I would like to also to print and that part of the code is not working. Can someone see the mistake? Code:

Selecting And Displaying Specific Row
I wonder if there is a way to select a specific row in a table and than displaying that row. For example i would like to dispaly results starting from the second oldest entry in the table ... thus omiting the latest entry. Can anyone point me in the right direction?

Displaying Only Part Of A Field
I have a field in my table that contains an ip address and text. I would like to query that field and only display the ip address. Can anyone help me out?

MySQL_queries Not Displaying On Browser
I have a problem with a Fedora Core 3 server build running Apache 2.0.52-3, PHP 4.3.9-3, MySQL-server 3.23.58-13.  It also has the php-mysql-4.3.9-3 installed.

The problem - bringing up Mozilla browser on localhost (for testiing purposes) the index.php page displayes fine, except the mysql_query results do not show up.  Nothing within the PHP tags show up, not even errors.

I've substituted the phpinfo (); within the php tags and it displayed the php info page with no problems.  So, I can only think that it has to do with mysql or Mozilla. Code:

Displaying Table Constraints
Does anyone know the syntax used to display the constraints in a table?

I am using MySQL v.3.23.58

I've looked in several forums and the MySQL manual, but haven't been able to find out.

Displaying Data From Db Onto Webpage
I have jus created my test database with one table and 5 rows of data using phpMyAdmin. Now I want to display this data on a webpage using php. Any ideas on how I can do this?

database name is "test"
table is called "users"

Displaying Chinese Characters
I install MySQL v4.1.14 in WindowXP as a service. I store all the data in the plain text file and load it into the database. All the data are stored in the database successfully but all the chinese characters become '????'

Every time I need to set the character set to big5 before I can see the chinese characters in the command line interface. How can I set the big5 as the default character set?

Although I can see most of the chinese characters after setting to big5, some of the characters are still in '????' Why this happens?

Thirdly, even if I can see the chinese characters in the command line interface, all the chinese characters change back to the '????' again when I use the web browser to see the data. How to fix up this problem?

Displaying Sorted Averages
Given a table with columns LotID, ItemName, CostPerUnit and UnitsSold, how would I produce a sorted list of the average of ( CostPerUnit * UnitsSold ) for all items with the same ItemName.

Example

LotID ItemName CostPerUnit UnitsSold
0 Ford 100 15
1 Chevy 75 10
2 Toyota 70 20
3 Ford 95 25
4 Ford 110 10
5 Chevy 80 20
6 Toyota 65 15

I'm looking for an output of
Ford 1658
Toyota 1187
Chevy 1175

Which is created by
Ford -> (100*15+95*25+110*10)/3
Toyota -> (70*20+65*15)/2
Chevy -> (75*10+80*20)/2

Displaying Certain Amount Of Data
I have created a script. This script of mine takes data off of a table and displays it on a web page. What I want is for the script to display only data that matches the id of another section of the web page.

For example, the script would first point to another factor in the database, perhaps the value of a row in another table. Let's call that value 025. In a second table, I have a few rows of data. Their ids were 025, 026, 027 and 028.

The web page would only display rows with the ids of 025. However, if that value in the other table was 026, then in the second table, the rows with id 026 would only be displayed.

Only Displaying So Many Characters Of A Result
have qry and list - bring back the last 10 titles in a DB and display the within the list/while... I need to only show .. say .. 25 characters of the title tho.. Ive tried substr stuff but as its inside a while and also inside a list ive got nowhere. There any query shortcuts?

Displaying Time Values
When I link a MySQL table containing a TIME column to Microsoft Access the
value does not display. If I edit the value it updates correctly in mysql
but if I refresh the Access datasheet view the value disappears and the
column shows as blank.

Can anyone tell me how to display time values in Access.
I am using MySQL ODBC driver 3.51, MySQL 4, Access 2002

Displaying Chinese Characters
I am designing a website that needs to be bilingal English/Chinese. I decided to create a MySQL table to hold page contents with a field called language with values en or cn.

I have two PHP pages, one queries on all records with en and has a character set "iso-8859-1" the other queries on all records with cn and has a character set "gb2312".

I have decided to enter the data using an Access database linked to the MySQL database using MyODBC. When I enter english characters all works fine. when I enter chinese charcters, they initially display fine on my PC as chinese characters, but once the record has been entered these are replaced with ?? symbols.

The question marks appear to originate from the MySQL database because they show up in the Access database, the online chinese page and using PHP MyAdmin.

Displaying SUM Results On Web Page
I'm trying to run a query using the SUM command and display the results on a web page but the SUM results keep coming back as 0 when I try to use the SUM command. They're multiple donations from the same contributors.

I'm running MySQL 4.1.14 and PHP 5.0.4

Here's the code I've come up with:

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT idNumber, contributorName, SUM(amount) AS total_amount FROM ca_late_trans GROUP BY contributorName";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {

$contributorName=mysql_result($result,$i,"contributorName");
$total_amount=mysql_result($result,$i,"total_amount");
$idNumber=mysql_result($result,$i,"idNumber");


echo "$idNumber&nbsp;<b>$contributorName</b><br>$total_amount<p>";

ASP Not Displaying Time Stored
I seem to be having a problem displaying time stored in mysql. The
format stored in the database is 13:15:05. The database data type is
time.

I'm using asp vbscript and sql to retrieve the time store in
the database. However asp recognizes the data type as date and
displays the date instead of the time. If I change the data type in
mysql to varchar then asp will display the time correctly, but I
cannot do it this way. I want to be able to convert the data type in
asp to string from date.

Displaying Table As Grid
From the following table showing which countries people have been to

Name....Country

Fred....France
Fred....UK
Bill.......Germany
Jack....USA
Bill.......UK
Tim.....USA
Tim.....France
Tim.....Italy

what SQL statement can I use to format it into a table with Name down one side and countries across the top with YES in the parts where they have visited. I would draw an example but the forum kills all the formating .

Displaying Designated Record
HelI'm trying to select a large amount of records from a database and display a single record as the first one. Is it possible to do this w/out 2 select statements

Displaying Multiple Fields
I am sure amongst this community that this question is rather straight forward.
I have a database where a table is added that contains the user login, password and other user information.
What I wish to do now is for each user I want to be able to add a product description, old price and new price.
So when this particular user logs in, they will see a list of products on one column and then the old price in another column and new price in the third column.
The prices obviously have to be matched to the same product.
Eg:
productA new_price1 old_price2
productB new_priceX old_priceY

How would one do this?

Displaying Context Text
I am doing a fulltext match() against() search over multiple fields and I was wondering how I might go about displaying a short blurb of the text around where the search term was found.Alot of search engins do this but I am unsure how I could go about it for a less sofisticated php & MySQL site

Displaying My Mysql Data
$query2 = $DB->query( "SELECT post FROM mkp_blog_post WHERE id_blog='2485' ORDER BY 'id'");

I simply want the results of this query to show up on my page. I know the query works, because I tried it in PHP Myadmin, and it gave two results. However, when I go the page, it doesn't work.Yes, I have more lines of code after that, but nothing I have tried has worked. Does anyone know what I would need to write afterwards as so this would appear on my page? Thanks!


Copyright © 2005-08 www.BigResource.com, All rights reserved