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




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..




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Alternating Row Colours
I am trying to get alternating row colours but cannot get this to work. Here is what I have, Code:

Alternating Colours For Every Other Record...
I was just looking at some site, and was wondering how they do it so its sort of like this:

Record 1 - Back colour = Red
Record 2 - Back colour = Blue
Record 3 - Back colour = Red

Im sure its not too difficult, just wondering how its done.

Background Alternating Colour Code
Im having problem making my background alternate between colors.  Following is my code, the result alternates 2 colors ok, but prints each entry from my database 30 times. Code:

Alternating Row Colors On Query Generated Table?
Is there some way to make a table have alternating colors for rows when
you're generating the table data with a WHILE statement?
You know, row 1 has a gray BG, row 2 is white, row 3 is gray, 4 is white,
etc, for as long as there's data.
Here's what I'm using right now:

$query_RSwho = "SELECT * FROM tbl_indv ORDER BY name ASC";
$RSwho = @mysql_query($query_RSwho, $connection) or die("Couldn't query: "
.. mysql_error());
while ($row_RSwho = mysql_fetch_array($RSwho)) {
if ($row_RSwho['name'] != "X") {
$names .= "<tr align=left><td
width=120>".$row_RSwho['name']."</td><td
align=left>&nbsp;--&nbsp;".$row_RSwho ['email']."</td></tr>";
}
}

So, in that WHILE section, is there a way to alternate bgcolor table cell
tags?

The Function To Switch Values Ie For Alternating Between 2 Colors In Table Display
What is the php function called which allows you to alternate between
two values? I've completely forgotten it and my searches in php.net
have not been fruitful!

Numbering Result Rows
I think I'm having a bit of a looping issue... I need to number a number on every row result, but what I am getting is the amount of result rows multiplied times how many results there are. Code:

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.

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.

Make Table Appear On Top
i made a php with just a table and included all the material with php include http://www.hbksite.com/index2.php but here is the problem when i got to it the menu appears in the middle is there any way to make it be always on top please help here is the code:

Dynamically Add And Remove Rows That Include PHP Code
I am creating a stock request form, which employees will fill out in order to remove products from inventory for various reasons. I am going to be saving these requests to a database and also displaying the completed form for employees to print.

The problem I am having is, I have the following table row for each product that the employee requests...

How To Make Image Code?
How can I make image code?

Format Table With PHP Result
I have to create some kind of dynamic page, logic is next: i have integer in variable and i need to create certain number of fields based on that int. example
$variable = 6 and I need to have table with 6 fields, 4 in one row and 2 in second....my problem is how to do that, how to get new <tr> when number in bigger than 4.

Saving A Result To Another Table
I have a script that will print out the results of a table and make a
calculation of a total of one of the columns. See example:

<?php

/* Database connection */
include(MYSQL_CONNECT_INCLUDE);

/* Select all pilots */
$query = "SELECT * FROM pilots ORDER BY pilot_num ASC";
$result = mysql_query($query);

/* Determine the number of pilots */
$number = mysql_numrows($result);

if ($number > 0) {
/* Print roster header
Change this HTML to fit your webpage layout */
print "<table>";
print "<tr>";
print "<td bgcolor=#000080 width=85 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>NUMBER</b></font></td>";
print "<td bgcolor=#000080 width=120 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>NAME /
EMAIL</b></font></td>";
print "<td bgcolor=#000080 width=130 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>CITY</b></font></td>";
print "<td bgcolor=#000080 width=93 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>COUNTRY</b></font></td>";
print "<td bgcolor=#000080 width=93 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>FLIGHT
TIME</b></font></td>";
print "<td bgcolor=#000080 width=75 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b><center>STATUS</center></b></font></td>";
print "<td bgcolor=#000080 width=75 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b><center>LOG
BOOK</b></center></font></td>";
print "</tr>";


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?

Make A Table In MySQL
How do I make a PHP script that is able to make tables with fields? I want to be able to have a HTML form submit the fields. I just want to know the PHP scriptlet that will make a table.

Create Html Table With Php Result?
I'm looking to display 5 records in one rows, from the database. What i mean is, basically, let's take the "emails" as an example. I have a table with 100s of email
addresses. Now i want to display these email addresses on a html table, but i want to display only 5 email adresses per table row, then the next 5 in the next table row and so
on.

Select Result On Empty Table?
can't remember how to do this, doing a select on a db like so.

$query = "SELECT user_id FROM tool_user WHERE user_name = '$user_name'";
$query = mysql_query($query) or die("eek");

which will work if there is at least one entry in the database table, however how do i return a result id the table is empty? do i need to use @mysql_query($query) and then something after that?

Display Of Mysql Table Result...
I have a mysql table of articles with fields:

- recordID
- department
- articleTitle
- articleText

Using PHP, I'm attempting to get the results of the table to display as follows:

Department 1
- articleTitle 1
- articleTitle 2
- etc....

Department 2
- articleTitle 1
- articleTitle 2
- etc..

I figure I should use a while loop but can't figure out how to exit/reset the loop when a new 'department' is encountered in the $result.

Strange Result From Table Query
I have a simple query that I am restricting to the first 4 character, however instead of the first 4 characters I am getting only the characters from the end of the field.

The information in the field resembles: 4285-002

My result should be: 4285

What I am getting is: -002

The following is the code to pull the dat from field 'Dest':
    $dest=odbc_result($rs1, 'Destination');
        $deststrcount=1;
        $deststr = $dest;
        $deststr = str_split($deststr,4);
        foreach($deststr as $destv){
          if ($deststrcount<="1"){
            $desttext=$destv;
            $destnew = "DEST[1,$deststrcount] $desttext";
 
            $strcount=$strcount+1;
            }

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:

Using Foreach To Make A Table From Db Info
what im trying to do is make a table of all the info from a database that i have im trying to use the foreach function, im not sure if this will work or the most efficent way.

Code Returning False Mysql Result
I'm working on code which will allow users to "rate" something, for instance, on a scale of 1-5. When they click on a star (1-5), it sends them to the following PHP script, with ?rid=&rating=

rid is the id of the item they are rating, and rating is the integer 1, 2, 3, 4, or 5. Problem is... even with an empty db table, it returns "Rating added successfully." - but doesn't add anything. If I add a row with uid=1 rid=2 and rating=3, and am logged in as uid=1, it still says "Rating added successfully.", and does nothing. It SHOULD HAVE updated the existing row and told me so. Code:

How To Make Text Wrap In Table Cells?
I don't understand this at all. I have a table with fixed width and height in pixels. Yet when I place a long text string in a cell, the cell expands as far as needed to the right or left to fit the string on one line. This is driving me quite mad. How do I ensure that a long string is displayed in a neat, orderly fashion? My question has nothing to go with wrapping text around images. I just simply need to have text wrapped!

Store Result Of SELECT Stament To Be Used To UPDATE Another Table
im trying to update a field of a table which is done through the results of a select statement. I need to be able to a store the results of the select statement which can then be used to determine if an update another table is initiated. This is where i have got so far: Code:

Using Echo To Print Out Different Colours
I have one page with a form (text area box) on it. When the user clicks update, whatever is put into the form is saved to the database and then displayed on another page.
What I would like is this: There are 3 users:

When each of them type into the form, I want it to print out in their colour on the second page.

Is there a way that if, for example, they were to put a 'keyword' into the form, such as their name, php could check for this word and print out the text in their colour?

Editing Colours In Existing Image- How?.
I'm having a little trouble finding out how to edit the colours of an existing image and output it through php. For example, if I tell it to read an image in a folder but change X colour, how would that be done? The only ways I've discovered so far involve images made there and then, on-the-fly, not existing files.

Convert IRC Based Colored Topic Into Colours In Html
i have a script and everything that moves what the channel topic is onto irc, into a sql database, and from there into a variable called $topic, the question is how can i make $topic show the mirc topic with all the colours and layout.

Displaying Table In Php Code
I have a PHP script that has a drop down to select a record, then it should display some text from a database and then display a table of information below it. But, the table is displaying at the top instead. Code:

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:

Run PHP Code Grabbed From A MySql Table
I have a quick query (no MySql pun intended!),

I've set up a beta-tester section on my website that requires persons to register and log in to be able to access my beta software. Each of the pages that make up my beta tester section (pages that you can only view when logged in) are stored in a table on a MySQL database behind a firewall (so nobody can access them directly). Some of these pages contain PHP code and I was just wondering if there is any elegant way to include that in the page being sent out so that the PHP code is executed. Sort of like an include() function but instead of a filename of a PHP script as the argument, a string with the code to include in it. At the moment I've implemented a rather ugly an inelegant system whereby the code in question is bunged out to a unique file on the server, that file included and then that file wiped. Horrible, error prone and completely and utterly butt-ugly hack I know!

Checking Whole Table With Strpos Code
I have a problem now to check the whole table with this code... can someone please help me?

$q6=mysql_query('SELECT * FROM banlinktable');
$o6=mysql_fetch_object($q6);
$banurl=$o6->url;

if (strpos($newsubmitrul, $banurl) != FALSE)
{
exit;
}

With this code it will only check the last inserted row, how can I check the whole banlinktable for the url?


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