hi there, firstly i would like to thankz Aditya Singh who did the php code for me... secondly, here is the image attached about what is it... as you can see it there are rows in the table in gray color... they are called from mysql databse... now i want to change the color of every alternative row in the table like for example ID 1,3,5 would have dark grey and ID 2,4,6.. will have light gray.. so how can i do that i my php code.. here is the code: <BODY topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0"> <table width="100%" bgcolor="#FFFFFF" height="60"> <tr> <td background="shadow.jpg"></td> </table> <TABLE border="1" bgcolor="#CCCCCC" bordercolor="#FFFFFF" cellpadding="0" cellspacing="0" align="center" width="1685px"> <TR> <TD background="topbg.jpg" width="20px" align="center"><span class="style1">ID</span></TD> <TD background="topbg.jpg" width="75px" align="center" class="style1">Entry Date</TD> <TD background="topbg.jpg" width="90px" align="center" class="style1">Release Date</TD> <TD background="topbg.jpg" width="90px" align="center" class="style1">Issue Date</TD> <TD background="topbg.jpg" width="200px" align="center" bgcolor="#990000" class="style1">Product Advertised</TD> <TD background="topbg.jpg" width="250px" align="center" bgcolor="#990000" class="style1">Magazine Newspaper</TD> <TD background="topbg.jpg" width="70px" align="center" bgcolor="#990000" class="style1">Approved by</TD> <TD background="topbg.jpg" width="60px" align="center" bgcolor="#990000" class="style1">Changes</TD> <TD background="topbg.jpg" width="100px" align="center" bgcolor="#990000" class="style1">Ad Reach</TD> <TD background="topbg.jpg" width="200px" align="center" bgcolor="#990000" class="style1">Communication Type</TD> <TD background="topbg.jpg" width="50px" align="center" bgcolor="#990000" class="style1">Claims</TD> <TD background="topbg.jpg" width="80px" align="center" bgcolor="#990000" class="style1">Bill Recieved Date</TD> <TD background="topbg.jpg" width="80px" align="center" bgcolor="#990000" class="style1">Bill Date</TD> <TD background="topbg.jpg" width="100px" align="center" bgcolor="#990000" class="style1">Bill Forwarded Date</TD> <TD background="topbg.jpg" width="50px" align="center" bgcolor="#990000" class="style1">Bill No</TD> <TD background="topbg.jpg" width="80px" align="center" bgcolor="#990000" class="style1">Bill Details</TD> <TD background="topbg.jpg" width="90px" align="center" bgcolor="#990000" class="style1">Others</TD> </TR> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'vertrigo'; $dbname = 'ad'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); $query = "SELECT * FROM addetail"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<TR>"; echo "<TD align='center' height='30'>$row[0]</TD>"; echo "<TD align='center'>$row[1]</TD>"; echo "<TD align='center'>$row[2]</TD>"; echo "<TD align='center'>$row[3]</TD>"; echo "<TD align='center'>$row[4]</TD>"; echo "<TD align='center'>$row[5]</TD>"; echo "<TD align='center'>$row[6]</TD>"; echo "<TD align='center'>$row[7]</TD>"; echo "<TD align='center'>$row[8]</TD>"; echo "<TD align='center'>$row[9]</TD>"; echo "<TD align='center'>$row[10]</TD>"; echo "<TD align='center'>$row[11]</TD>"; echo "<TD align='center'>$row[12]</TD>"; echo "<TD align='center'>$row[13]</TD>"; echo "<TD align='center'>$row[14]</TD>"; echo "<TD align='center'>$row[15]</TD>"; echo "<TD align='center'>$row[16]</TD>"; echo "</TR>"; } mysql_close($conn); ?> </TABLE> </BODY> Code (markup): thanks in advance
Place this in your loop, and use $bgcolor wherever you need it. $bgcolor = ($bgcolor == '#CCCCCC' ? '#999999' : '#CCCCCC'); Code (markup): EDIT: Since you edited, I will as well. while($row = mysql_fetch_array($result, MYSQL_NUM)) { $bgcolor = ($bgcolor == #CCCCCC' ? '#999999' : '#CCCCCC'); echo "<TR style=\"background-color:". $bgcolor .";\">$row[0]</TR>"; ..... Code (markup): EDIT: Note that there should be a sinlg equote infront of #CCCCCC, but the forum takes it out.
thankz for the reply... i did this: while($row = mysql_fetch_array($result, MYSQL_NUM)) { $bgcolor = ($bgcolor == #CCCCCC' ? '#999999' : '#CCCCCC'); echo "<TR style=\"background-color:". $bgcolor .";\">$row[0]</TR>"; echo "<TD align='center' height='30'>$row[0]</TD>"; Code (markup): but still itz not wrkin.... error: Parse error: parse error, unexpected T_ECHO in C:\Program Files\VertrigoServ\www\ad\adphp.php on line 57
Ah yeah, my bad. This echo "<TR style=\"background-color:". $bgcolor .";\">$row[0]</TR>"; Code (markup): Should be this echo "<TR style=\"background-color:". $bgcolor .";\"> Code (markup):
give out an error " Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\Program Files\VertrigoServ\www\ad\adphp.php on line 58"
stuck with one more problem... can anyone help me as to how can i get the data arranged according to groups in the table i mean now when i insert the data in phpmyadmin.. it displays on my php page one after the another... what i want is that when i click on the word "ID" it should arrange in ascending order... and then when i click on Release Data is shd get arranged in the dates ascending order.... like this i have 16 fields....
change each of the headers to links with the id of each header as a parameter in the link - e.g. http://www.domain.com/page.php?sort=column_id Code (markup): then change your query based on the parameter: from: $query = "SELECT * FROM addetail"; Code (markup): to: $query = "SELECT * FROM addetail order by " . $_GET['column_id']; Code (markup):
hey thankz for the prompt reply... i got this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\VertrigoServ\www\ad\adphp.php on line 56 can u plz have a lok at my code above./..
well here is the code.... <HTML> <HEAD><TITLE>iBall Print ADs</TITLE> <link href="style.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- .style1 { color: #FFFFFF; font-weight: bold; } .style3 {color: #CC0000} --> </style> </HEAD> <BODY topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0"> <table width="1715px" bgcolor="#FFFFFF" height="60"> <tr> <td background="shadow.jpg"><strong> </strong><span class="style3"> iBall Print AD Details </span></td> </table> <TABLE border="1" bgcolor="#CCCCCC" bordercolor="#FFFFFF" cellpadding="0" cellspacing="0" align="center" width="1715px"> <TR> <TD background="topbg.jpg" width="20px" align="center"><span class="style1">ID</span></TD> <TD background="topbg.jpg" width="75px" align="center" class="style1">Entry Date</TD> <TD background="topbg.jpg" width="90px" align="center" class="style1"><a href="http://localhost/ad/adphp.php?sort=column_id">Release Date</a></TD> <TD background="topbg.jpg" width="90px" align="center" class="style1">Issue Date</TD> <TD background="topbg.jpg" width="200px" align="center" bgcolor="#990000" class="style1">Product Advertised</TD> <TD background="topbg.jpg" width="250px" align="center" bgcolor="#990000" class="style1">Magazine Newspaper</TD> <TD background="topbg.jpg" width="100px" align="center" bgcolor="#990000" class="style1">Approved by</TD> <TD background="topbg.jpg" width="60px" align="center" bgcolor="#990000" class="style1">Changes</TD> <TD background="topbg.jpg" width="100px" align="center" bgcolor="#990000" class="style1">Ad Reach</TD> <TD background="topbg.jpg" width="200px" align="center" bgcolor="#990000" class="style1">Communication Type</TD> <TD background="topbg.jpg" width="50px" align="center" bgcolor="#990000" class="style1">Claims</TD> <TD background="topbg.jpg" width="80px" align="center" bgcolor="#990000" class="style1">Bill Recieved Date</TD> <TD background="topbg.jpg" width="80px" align="center" bgcolor="#990000" class="style1">Bill Date</TD> <TD background="topbg.jpg" width="100px" align="center" bgcolor="#990000" class="style1">Bill Forwarded Date</TD> <TD background="topbg.jpg" width="50px" align="center" bgcolor="#990000" class="style1">Bill No</TD> <TD background="topbg.jpg" width="100px" align="center" bgcolor="#990000" class="style1">Bill Amount</TD> <TD background="topbg.jpg" width="80px" align="center" bgcolor="#990000" class="style1">Bill Details</TD> <TD background="topbg.jpg" width="90px" align="center" bgcolor="#990000" class="style1">Remarks</TD> </TR> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'vertrigo'; $dbname = 'ad'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); $query = "SELECT * FROM addetail order by " . $_GET['column_id']; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_NUM)) { $bgcolor = ($bgcolor == '#CCCCCC' ? '#999999' : '#CCCCCC'); echo "<TR style=\"background-color:". $bgcolor .";\">"; echo "<TD align='center' height='30'>$row[0]</TD>"; echo "<TD align='center'>$row[1]</TD>"; echo "<TD align='center'>$row[2]</TD>"; echo "<TD align='center'>$row[3]</TD>"; echo "<TD align='center'>$row[4]</TD>"; echo "<TD align='center'>$row[5]</TD>"; echo "<TD align='center'>$row[6]</TD>"; echo "<TD align='center'>$row[7]</TD>"; echo "<TD align='center'>$row[8]</TD>"; echo "<TD align='center'>$row[9]</TD>"; echo "<TD align='center'>$row[10]</TD>"; echo "<TD align='center'>$row[11]</TD>"; echo "<TD align='center'>$row[12]</TD>"; echo "<TD align='center'>$row[13]</TD>"; echo "<TD align='center'>$row[14]</TD>"; echo "<TD align='center'>$row[15]</TD>"; echo "<TD align='center'>$row[16]</TD>"; echo "<TD align='center'>$row[17]</TD>"; echo "</TR>"; } mysql_close($conn); ?> </TABLE> </BODY> </HTML> Code (markup):
2 things... i made a mistake in my post... header link => http://www.domain.com/page.php?sort=column_id query should be => $query = "SELECT * FROM addetail order by " . $_GET['sort']; now, when i mention column_id, i mean you got to put the real column in in place of column_id. e.g. if the release date column in the database is rel_date, you should use: http://www.domain.com/page.php?sort=rel_date
well thankz again... its workin... the only think which doesnt work in the main page that is http://www.domain.com/page.php...... the error" Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\VertrigoServ\www\ad\adphp.php on line 56 "... but when i click on the link.. it works fine....
Don't ever in your entire life use GPC variables directly in query strings without filtering the input. Specially at the end of queries. Do something like. $allowed_orders = array('column_id', 'another_one', 'whatever'); $order = in_array($_GET['order'], $allowed_orders) ? $_GET['order'] : 'default_order'; //.... "SELECT * FROM addetail order by ". $order; PHP:
totally confused i replaced my tags with what nico_swd gave me.... and in tht i replaced column_id with my first column id and the rest with others.... but still i get errors... ;(
it takes time for people to try to digest your request for help. if you want help, please provide more details and be specific. take the time to write out your questions properly. provide enough details for people to help you. i got no idea whatsoever what the problem is from your post.
okie here it goes.... i changed the file after you gave me the changes..... everything is working fine.. i mean when i click on "release date" the data gets arranged in the desired format.... its working for all the feilds.... but now the problem is there in the first page i mean the main php page(index.php)...;(