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




How Many Rows In A Table


I am sure there must be an easy way to determine the number of
rows in a table, but I can't find it.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
New Table Rows
I retrieve 20 items from a MySQL database. I want to display the output in a table. How can I display 5 items on a table row and then begin an new row?

Eliminate Gap Between Table Rows?
I made my first PHP page that uses includes.
http://php.didah.com/main.php
But I can't get rid of a gap (about 5 pixels) between the table rows.

The content of each include file is one line like this:
<img src="images/nav.gif" width="100" height="600" hspace="0"
vspace="0" border="0">
No head or body tags. Just a 100 x 600 gif image.

Here's the code for the main.php page:

<html>
<head>
<title>First Include Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="600px" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td colspan="2"><?php include 'header.php' ?>
</td>
</tr>
<tr>
<td><?php include 'nav.php' ?></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>This is the content area.</td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"><?php include 'footer.php' ?></td>
</tr>
</table>
</body>
</html>

If you look at the main page in IE there is a vertical gap between the
header, nav, and footer image. Does anyone know how to get rid of this?

Selecting Rows From Db Table
In a project mentioned in another thread, I'm trying to get some
dynamic data to work. In this discography, you can click on an
album name, and the title of the album and its tracks will appear
on the left. I have the beginnings worked out, like so:

***

<h3><?php echo $row_rsindiv['Album']; ?></h3>
<ol>
<?php do { ?>
<li><?php echo $row_rsindiv['Song']; ?> (<?php echo $row_rsindiv
['Time']; ?>)</li>
<?php } while ($row_rsindiv = mysql_fetch_assoc($rsindiv)); ?>
</ol>

***

A sample of the database:

***

Electronic Meditation 3 Cold Smoke 10:48
Electronic Meditation 4 Ashes to Ashes 3:58
Electronic Meditation 5 Resurrection 3:21
Alpha Centauri 6 Sunrise in the Third System 4:20
Alpha Centauri 7 Fly and Collision of Comas Sola 13:23
Alpha Centauri 8 Alpha Centauri 22:04
Zeit 9 Birth of Liquid Plejades 19:52
Zeit 10 Nebulous Dawn 17:47

***

I want to tell PHP to write the album name and list the tracks in
an <li></li> based on whatever album title is clicked in the main
table.

The main table looks like:

***

<?php do { ?>
<?php
$class = ($class == 'odd') ? 'even' : 'odd'
?>
<tr class="<?php echo $class ?>">
<td><?php echo $row_rstdream['Album']; ?></td>
<td><?php echo $row_rstdream['Year']; ?></td>
<td><?php echo $row_rstdream['Era']; ?></td>
<td><?php echo $row_rstdream['Type']; ?></td>
</tr>
<?php } while ($row_rstdream = mysql_fetch_assoc($rstdream)); ?>

***

I thought maybe of changing the first <td></td> to:

<td><a href="#" onclick="<?php $album = $row_rstdream['Album'] ?>">
<?php echo $row_rstdream['Album']; ?></td>

But that's as far as I can get with my limited knowledge. Does
anyone have any ideas on how to display only the rows in the second
database that correspond to the name of the album clicked on? Sorry
the examples are so long,

Copying Rows To Another Table
After I select a row whose ID is 10 or some other number, I need to
copy the entire row into another table.

Is there a way to copy rows between tables using PHP? Could someone
please point me to an example..

How Do You Find Out How Many Rows Are In A Table?
How can you tell(using php) how many rows are in a database table.

Duplicating MySQL Table Rows
I'm not sure whether this should be posted here on in databases, but it's a question about inserting records in a MySQL table using PHP.

I have a large table with some 50+ fields with an auto-increment primary key field. When a record is edited by a user, we need to duplicate the original record, and update the fields changed by the user.

My question is, what is the easiest way to capture and duplicate the original table row? Yes, I could read the record in and then loop through the $row[] array using this as the source of all fields (except the primary key), but it strikes me that there must be a simpler method.

Navigation Through Mysql Table Rows.
I am running a query on a master detail page which results in a number of records. I call this page the master detail page. The master detail page has a number of records listed as thumbnails. Each thumbnail has a link identifier which is linked to a detail page. On the detail page I have no problem querying the specific recordset through $HTTP_GET_VARS['id'] and the additional info below. PHP Code:

Help With Randoming Pulling Out Rows Of A Table
Suppose I'm connected to a database and I do the following:

$query = "Select q_id, question From questions Order by q_id";

$result = mysql_query($query);

Now, what is the best way to pull out 20 random rows from my questions
table?

I'm trying to set up on an online trivia page where different
questions are posted each time a person visits the page and I'm
pulling my list of questions out of a database.

I know mysql_fetch_array fetches one row at a time and array_rand can
pull elements out of an array at random, but I'm at a loss at how to
coordinate these two functions together to do what I want to do.

Selecting Random Rows In A Table.
How can i randomly select rows? say for example i have 50 users, 3 of them were online. I only want the 3 online, BUT i want then to be randomly choose. So that everytime i go to the page, it is a different person. Im assuming MySQL numrows has something to do with it but im not quite sure.

How Do I Delete Selected Rows From MySQL Table?
I am trying to figure out how to delete selected rows from a MySQL database table. The web site that I am working on has a page that will extract rows, using the "SELECT * FROM .. etc." statement from a database and output them in a table - like the one below (bottom part). I've got that part figured out.

What I am trying to figure out is if the user puts a checkmark in one of the checkboxes (below) how would I write the PHP code to delete one or two of the rows from the MySQL table? PHP Code:

Looped Rows In Table Add & Remember Values
I'm trying to get this app to work. It's supossed to:

1. create rows dynamically through a loop (done)
2. remember the user-entered-values while the form posts to itself
3. provide a total (addition) of all 4 rows. (kinda tricky since the rows are looped).
PHP Code:

Parse HTML Table Rows Into Array
I have a script that extracts an HTML table from a page into a text string. I would like to parse each row of the table into an array named "$rows". I would like to keep the html intact so that I could re-create the same table like: Code:

Adding Multiple Rows To Table Using Checkboxes
I'm looking to select using checkboxes certain rows from the results of 'table a' and add the selected rows to another table using checkboxes. I Have had limited success adapting some code for deleting multiple records using checkboxes. Code:

Dynamically Create Table Rows As Needed
I have a form with a table. Each table row has a ID= "some number". I have 4 rows and might need to create more. how can i do this in php? To go along with this, When I hit the submit buton, I then need all the table row data saved to a db i have. I can insert 1 line with out a issue. I also made sure the table row name="" fields are unique. ex. Code:

Updating Multiple Rows In A Table In Mysql
ok so im making this form that updates multiple rows in the mysql database but the thing is that the number of rows is a variable so once it may be one row once it may be 31 rows. is there anyway i can do this using a while loop? or even is there a way to do this period?

Displaying Multiple Queries To Same Table Excluding Different Rows!
i've got a table with 224 town listings and their ID's in it from 6 counties, and I want it to displayin a 6 columned table, each county getting their own column. Anyway, here's what I've got and what's happening: PHP Code:

Using Php To Move Rows From Text File Into Mysql Table
Can anyone point me in the right direction for the way to read a text file a
line at a time and separate the fields on that line and use them as data in
an INSERT to add a record to a mysql table. Then read the second line in
text file and repeat.

Divide Mysql Results Into Rows In An Html Table
I need to divide my mySQL results into rows with 4 results on each row. Its for a small image gallery script, I wanna show 4 thumbnails per row. I have all the code ready to get the info and show it, I just need an example of how I can take the data from the table and have it automatically go to a new row every 4 entries.

ECHO The Amount Of Rows In My Table According To A Specific Username
I am creating an infinite loop with this code. My goal is to just ECHO the amount of rows in my table according to a specific Username. How do I do this? my code:

<?php $query = "SELECT ID FROM products WHERE Username = '{$Username}'"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_num_rows($result) or die(mysql_error());
$num = 0;
while ($num <= $row) {
echo $row;}?>

Ordering & Limiting Multiple Table Rows By Date
My goal is to select rows from two tables 'shoot' & 'video' and have mysql order those tables by date and limit the number of rows returned. I want to list the latest 10 rows but am uncertain how many rows from each table will be the latest. I may have more recent shoots than videos or the opposite. How can I use a single ORDER BY and LIMIT statement for both selections? Code:

Code To Make Table Rows Of A Result Appear In Alternating Colours...
How can I get it so that when I run a search, and the results come back in table format, the rows are alternating colours, like on Devshed's forums? I believe there was some code here some time ago saying how to do it..

Count Rows In Table By "category"
I have a table full of articles. One of the columns is "category". I want to count how many arcticles there are for each category. I have another table that lists all the categories. I see two ways to do this, but don't know which is best or easier.

One way I think would be to somehow count how many rows had the same category in just the articles table (they are entered by number). This way would be ok, but would only list categories that had articles (which in some cases I would want to do).

The other way would be to query the select * from categories, and somehow join it to the articles table while counting how many articles there were for each category (even if they were zero).

Multiple Table Rows In "While" Loop
I have the code below with two table rows, but the second row won't display any data. How can I make both table rows work? Code:

Creating Table Rows For Ever Other Loop In A WHILE Loop
I'm trying to create a table using a MySQL fetch array while loop that would look like this:

CONTENT1     CONTENT2
CONTENT3     CONTENT4
CONTENT5     CONTENT6

I need a <TR></TR> for every other piece of content. But I don't know how to do this with a loop that uses a MySQL fetch array

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{
PHP CODE THAT IS LOOPED;};

I'm trying to remember from my old college Java class that we did something with loops for whenever the counter variable was even the loop would do something special... I don't know if this is possible with a while+mysql_fetch_array loop though.

Count Amount Of Rows In Same Query Of Selecting Rows
I am selecting some rows from a table and i wonder if i can count
the amount of rows in that same table in the same query? I tried something like: PHP Code:

Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?

Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for.  Can anyone help me get the Agreed? table's background color to the colors above? Code:

Outputting A Table Or Form Using SHOW FIELDS FROM Table
In the code the MySQL database was queried using "SHOW FIELDS FROM table" which and the returned results of column names was then use to build an output for a form and a table with php using a series of if statements along the lines of if the returned field name matches something echo a text input field.

I have never seen this done this way before, so I want to get the opinion of the devshed user. Does it seem like an unsual long process to build up a form. Is there a security advantage doing it this way? Has anyone ever done it this way before?

Finding Matches In A Table And Then Moving That Match To Another Table?
Ok, I have a database that has a table called critiera in this table
is to fields on is ID and the other is critiera.

Now I want to filter out all the one that don't apple to the list and
move the one that match to a different database.

I know how to open a connection, close, select

but I don't know how I would inside of a database use another one as
the way to create the list of critieras....

Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias'
the mysql_fetch_field function returns a value $result=>table which
will contain the alias, not the actual table name.
Is there a way to get the actual table name ?

I am running mysql 4.1 and php 4.4

Grab Data From A Table, Echo, Then Insert It Into A New Table...
I'm trying to do is count the number of times usernames shows up in a table. I then want to reinsert that information into a different table with the Username in column1 & the occurrences in column2 for every user that is echoed on the page. Code:

Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'.

There is one of each item in products and each product has it's own unique 'prodno'

There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example:

id = 1
prodid = 7001
qty = 300
price = 12.5

id = 2
prodid = 7001
qty = 400
price = 15.5

I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table.

Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item..

This is all very confusing to me, and I'm the one writing it. Let's try one last time..

Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.

Update Table While Insert Data To Another Table
it seem like mine coding din work.
[php]<?

include("checkin.html");
$conn=mysql_connect('localhost','root','') or die ('Could not connect to server');
$today = date("Y.m.d");
mysql_select_db('hms', $conn);

$ok = mysql_query("INSERT INTO check_in(ID,room_no,datein)values ('$ID','$room','$today')", $conn);

if( $ok ){

$up = mysql_query("UPDATE studtable SET checked = 'checkin' where [ID] = '%ID');

if(mysql_affected_rows( $up ) == 1)
{
echo'Checked IN!'
}else { echo'No such student to check in' }}
else { echo'Check In FAILED, please check again'}?>[php]

How To Transfer A Data With An Id To Another Table From A Table?
how am i going to transfer let say a name identified using the suer id and copy the name to the other table having the same user id>?

How Can I Find A Name From One Table In A Text From Another Table?
I have one table with a description field and other info, and I also have another table with a list of names and picture url:s. When I display the text description on my site I'd like to know if there are a match with a name from the 'names' table in the text. Code:

Returning Table Name As Well As Fields From That Table
I am returning all fields from news and from regional, however I want to determine where the fields have come from when I ouput the data, therefore I need to return the table name with the fields. Is this possible? Code:

Moving Data From One Table To Another Table
Does anyone know how to move one row from a table in a mysql database to another table using php?

Counting Rows
I need to get the number of rows in a table.

This is the query I'm using at the moment:

$query = "SELECT COUNT(*) from mytable";
$result = mysql_query($query) or die ...;

What php function may I use to get the number and in which way?

I tried with

$num = mysql_num_rows($result);

but nothing.

Grouping Rows
I've gotten a few rows, that I want to sort based on the date that it's scheduled.

This means that I've gotten different rows, and I want to create something like this:

Monday 99 Januari:
Row1
Row3

Tuesday 99 Februari:
Row2
Row4

This way the system sorts the rows by date and groups them.
Only I still haven't found any way how to do this.
Any ideas?

Get Number Of Rows?
Is there a way to get the number of rows returned from a query? (database used: MySQL)

Missing Rows
I've been trying to retrive a limited numbers of rows ordered by a date and it keeps on returning 1 row less than I've wanted. code:

Counting Rows
I have an admin system (Add/Modify/Delete) for two types of records in the
database. They have a Parent - Child relationship

My problem is that I want to display on the "parent" record whether the
child exists or not .

The records are found in two different tables, but have the same Primary
Key.

Say I Have 48 Rows, How Would I Seperate Every 12?
I have to create an html page that will be printed and it has to be THE SAME as the old page made in Excel. I'm right now because for each query (could have 1 to 65 or any number of rows) I have to seperate the results into groups of 12. PHP Code:

Getting SQL Rows For A Week
I have a database that uses two date fields for tracking information. The first field is for the addition of the record and the second is for the expiration.

I have a small section that I want to list records that will expire in the current week (or for that matter in the next 7 or 14 days). What is the syntax that I would use to call mySQL with to get that info.

How Do You Add Values In Rows Together
I am using the following code to take records out of a Mysql database and display them on an HTML form. $myrow[8] is a number. At the bottom of the table, I want to display the sum of all the $myrow[8] values added together. Code:

Autentication Rows
when i try and log in, the script bellow keep throwing an error back on the last 2 lines i have commented over $numrows and $rows. can anyone point me in the right direction. I am not looking for someone to fix the code, but I need guidence. Code:

Returning All Rows Instead Of Row By ID
When I try to call data for only one person using the below code, it displays everyone in the database. What am I forgeting to do? Im refering them to this from options.php?id=<? echo $row->id; ?> PHP Code:

Rows Affected?
I am executing an update-query. Is there a way I would get a result if there
is a row affected, because if the row isn't affected (product may not exist)
I have to execute a insert-query. This way I could use 1 query (in the
update-case). Else I would always have to execute 2 query's (1 count-query
and 1 insert or update query).

Trying To Delete Rows.
I am trying to use php to delete rows for a mysql database table, i am using the following code with $journeyIDToUse being a number that represents a automaticly incrementing primary key.

$toDelete = "DELETE FROM journeyData WHERE journeyID='$journeyIDToUse'";
mysql_query($toDelete);

This fails to delete the row. I have tried changing $journeyIDToUse to a number and that worked so i thought that the variable might be at fault but the following query works so that rules that out

$searchString = "SELECT * FROM journeyData WHERE journeyID='$journeyIDToUse'";
$result = mysql_query($searchString);
$row = mysql_fetch_array($result);


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