02-17-2010
My experience is that you should know the nature of the MySQL query, i.e. number and size of rows and columns before deciding on how to format the output.
Generally, we should read most queries into an array first, or an array of arrays and then print the output in loop where we can format the output properly.
Simply adding a newline to a row with large fields, blobs, and or many columns, will be messy.
There should be some structure to the query unless the query is trivial like getting only a few small fields.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
i need to grep date in the format year-month-day,,,,,,,
actually i need to grep those dates other than current date..........
can anyone help me in this...........i need a format of date which would grep previous date except current date (1 Reply)
Discussion started by: ali560045
1 Replies
2. Shell Programming and Scripting
Hi all, I'd like to capture the output from the 'top' command to monitor my CPU and Mem utilisation.Currently my command isecho date
`top -b -n1 | grep -e Cpu -e Mem` I get the output in 3 separate lines.Tue Feb 24 15:00:03
Cpu(s): 3.4% us, 8.5% sy .. ..
Mem: 1011480k total, 226928k used, ....... (4 Replies)
Discussion started by: new2ss
4 Replies
3. Shell Programming and Scripting
I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column.
I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this?
Sample input
02/27/09,23:52:31
02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies
4. UNIX for Dummies Questions & Answers
I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd.
The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4".
This is what I use to change the format:
sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies
5. Shell Programming and Scripting
Hi guys,
I'm doing a project now and extracting tables from a webpage to MySQL table format.
I dumped the webpage with lynx and it is like this
id
Spec
524543
Developed especially for seniors
Spec
No
Java
Spec
Yes
Java MIDP
Spec
... (4 Replies)
Discussion started by: Johanni
4 Replies
6. Shell Programming and Scripting
Good afternoon!
I have been lurking in this forum for awhile now. I have just recently started posting. I think this is a really good site. With that being said, I don't like to just run and get an answer before I try my best first.
I have poured some blood, sweat and tears into... (4 Replies)
Discussion started by: brianjb
4 Replies
7. UNIX and Linux Applications
On psql
select titolo,lingua from titolo where titolo ~* 'brivid';
titolo | lingua
------- + ------
Brivido | 1
On Sqlplus/gqsql
SQL> select titolo,genere,anno,lingua from titolo where titolo like '%rivid%';
TITOLO... (6 Replies)
Discussion started by: Linusolaradm1
6 Replies
8. UNIX for Dummies Questions & Answers
Hi Friends,
Am new to Unix world and this is my first post in this forum.
I was stuck in displaying the content.
while displaying the content the below points to be taken care
1 ) The header format is repeating
2) To display the value in table format... (2 Replies)
Discussion started by: rocky2013
2 Replies
9. Shell Programming and Scripting
Hi ,
i am generating some data by firing sql query with connecting to the database by my solaris box.
The below one should be the header line of my excel ,here its coming in separate row.
TO_CHAR(C. CURR_EMP_NO
---------- ---------------
LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies
10. UNIX for Advanced & Expert Users
I am stuck with values in existing program perl script...
my $format ="a40a9a*";
please help me to understand what is the value of "a40a9a*".
Thanks in advance! (3 Replies)
Discussion started by: Vijay_Data
3 Replies
LEARN ABOUT PHP
mysqli_fetch_assoc
MYSQLI_FETCH_ASSOC(3) 1 MYSQLI_FETCH_ASSOC(3)
mysqli_result::fetch_assoc - Fetch a result row as an associative array
Object oriented style
SYNOPSIS
array mysqli_result::fetch_assoc (void )
DESCRIPTION
Procedural style
array mysqli_fetch_assoc (mysqli_result $result)
Returns an associative array that corresponds to the fetched row or NULL if there are no more rows.
Note
Field names returned by this function are case-sensitive.
Note
This function sets NULL fields to the PHP NULL value.
PARAMETERS
o $
result -Procedural style only: A result set identifier returned by mysqli_query(3), mysqli_store_result(3) or
mysqli_use_result(3).
RETURN VALUES
Returns an associative array of strings representing the fetched row in the result set, where each key in the array represents the name of
one of the result set's columns or NULL if there are no more rows in resultset.
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the
same name, you either need to access the result with numeric indices by using mysqli_fetch_row(3) or add alias names.
EXAMPLES
Example #1
Object oriented style
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s
", $mysqli->connect_error);
exit();
}
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)
", $row["Name"], $row["CountryCode"]);
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();
?>
Example #2
Procedural style
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
printf ("%s (%s)
", $row["Name"], $row["CountryCode"]);
}
/* free result set */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
The above examples will output:
Pueblo (USA)
Arvada (USA)
Cape Coral (USA)
Green Bay (USA)
Santa Clara (USA)
Example #3
A mysqli_result example comparing iterator usage
<?php
$c = mysqli_connect('127.0.0.1','user', 'pass');
// Using iterators (support was added with PHP 5.4)
foreach ( $c->query('SELECT user,host FROM mysql.user') as $row ) {
printf("'%s'@'%s'
", $row['user'], $row['host']);
}
echo "
==================
";
// Not using iterators
$result = $c->query('SELECT user,host FROM mysql.user');
while ($row = $result->fetch_assoc()) {
printf("'%s'@'%s'
", $row['user'], $row['host']);
}
?>
The above example will output something similar to:
==================
SEE ALSO
mysqli_fetch_array(3), mysqli_fetch_row(3), mysqli_fetch_object(3), mysqli_query(3), mysqli_data_seek(3).
PHP Documentation Group MYSQLI_FETCH_ASSOC(3)