Page 3 of 6
Posted: Thu Jun 03, 2004 3:47 pm
by Kingo
i would lik eto display alternate colors for each row. Any help is really appreciated
Code: Select all
echo "<table border="1">";
echo "<tr><td>";
echo "<font size="2" face="Arial, Helvetica, sans-serif"><b>Name</b></font></td>";
echo "<td><font size="2" face="Arial, Helvetica, sans-serif"><b>Phone</b></font></td>";
echo "<td><font size="2" face="Arial, Helvetica, sans-serif"><b>Email</b></font></td></tr>";
while ($row = mysql_fetch_array($result))
{
$Name = $row['Name'] ;
$Phone = $row['Phone'];
$Email = $row['Email'];
//make a display block to display the results on a html table row at a time
echo "<tr><td width="25%"><font size="2" face="Arial, Helvetica, sans-serif">$Name</font></td>";
echo "<td width="25%"><font size="2" face="Arial, Helvetica, sans-serif">$Phone</font></td>" ;
echo "<td width="25%"><font size="2" face="Arial, Helvetica, sans-serif">$Email</font></td> </tr>";
}
echo "</font></table>";
Posted: Thu Jun 03, 2004 4:14 pm
by feyd
Code: Select all
$row_num = 0;
while($row = mysql_fetch_array($result))
{
$color = ($row_num % 2)?"white":"black";
$row_num++;
echo '<tr style="background-color:'.$color.'">';
// continue on with whatever other output...
}
Posted: Thu Jun 03, 2004 5:07 pm
by pickle
Or
Code: Select all
while($row = mysql_fetch_array($result))
{
$color = ($row_bool)?"white":"black";
$row_bool = !$row_bool;
echo "<tr style='background-color:$color;'>";
}
Posted: Thu Jun 03, 2004 6:53 pm
by lostboy
The below example can easily be switched to CSS by setting the class instead of color ie
echo "<tr class=\"$bgcolor\">...
Code: Select all
$clr1="grey";
$clr2="white";
$bgcolor = $clr1;
...
while ($rows =mysql_fetch_array($result)){
//get results
($bgcolor == $clr1)? $clr2 : $clr1;
echo "<tr bgcolor=$bgcolor><td>"; //can't quite remember the attribute for the backgroundcolor
Posted: Thu Jun 03, 2004 10:37 pm
by feyd
....except $bgcolor is never set..

Posted: Fri Jun 04, 2004 6:35 am
by lostboy
huh???
edit okay, figured that one out obviously a little tired last night
Posted: Fri Jun 04, 2004 7:40 am
by Kingo
I want to have a List Box with three Entries ( Name, Phone, Email). Once I select the Name the contents should sort accordingly.
This code will sort if I click the header in the table.
Code: Select all
echo "<a href="".$_SERVER['PHP_SELF']."?sort=name">Name</a></td></tr>";
echo "<a href="".$_SERVER['PHP_SELF']."?sort=phone">Phone</a></td></tr>";
echo "<a href="".$_SERVER['PHP_SELF']."?sort=email">Email</a></td></tr>";
Posted: Fri Jun 04, 2004 7:47 am
by Kingo
I'm using this code. I donot know if this is correct.
<select name="select" size="1" onChange="window.open(this.options[this.selectedIndex].value,'_top')" style="font-family: Arial, Helvetica, sans-serif; font-size:11px">
<option value="
http://localhost/PHP_RemoteFiles/view.php?sort=name" >Name</option>
<option value="
http://localhost/PHP_RemoteFiles/view.p ... ne</option>
<option value="
http://localhost/PHP_RemoteFiles/view.p ... il</option>
</select>
Posted: Fri Jun 04, 2004 8:28 am
by magicrobotmonkey
Nope, now your using a form so you are POST ing data not GET ing data. put form tags around that one posting to itself or whatever and name your select and set the option value="name" "phone" etc. Then use $_POST['selectname'] to get the selection.
Posted: Fri Jun 04, 2004 9:07 am
by Kingo
Hello,
I'm using the following code and it is working.
<select name="select" size="1" OnChange="location.href=this.options[this.selectedIndex].value" style="font-family: Arial, Helvetica, sans-serif; font-size:11px">
<option selected >---------</option>
<option value="view.php?sort=name">Name</option>
<option value="view.php?sort=phone">Phone</option>
<option value="view.php?sort=email">Email</option>
</select>
I'm not using any form. I'm not sure if this is correct.
I did not follow what you were trying to tell. Can you explain.
Really appreciate your help
Help
Posted: Fri Jun 04, 2004 1:56 pm
by Kingo
Can any one hwlp me on this issue
Posted: Fri Jun 04, 2004 2:09 pm
by magicrobotmonkey
I'm using the following code and it is working
What's the problem?
Posted: Fri Jun 04, 2004 2:16 pm
by Kingo
I wanted a code in such a manner that, if i dont have the
Code: Select all
"<a href="".$_SERVER['PHP_SELF']."?sort=name">Name</a
.
How can i achieve the sort functionality by selecting the items from the list
Posted: Fri Jun 04, 2004 2:20 pm
by lostboy
The answer was given in a
Code: Select all
$result = mysql_query("SELECT Name,Phone FROM contact LIMIT $start, $rows_per_page");
$rows = mysql_num_rows($result);
$sort = $_POST['sort']; <==== this used to be GET now changed to POST
$orderby = " order by $sort";
$result = $result.$orderby;
Posted: Fri Jun 04, 2004 2:20 pm
by magicrobotmonkey
I don't know what you mean. You don't have that now. Explain what you want to happen