PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Jun 03, 2004 3:47 pm
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>";
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 03, 2004 4:14 pm
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...
}
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Jun 03, 2004 5:07 pm
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;'>";
}
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
lostboy
Forum Contributor
Posts: 329 Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada
Post
by lostboy » Thu Jun 03, 2004 6:53 pm
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
Last edited by
lostboy on Fri Jun 04, 2004 8:41 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 03, 2004 10:37 pm
....except $bgcolor is never set..
lostboy
Forum Contributor
Posts: 329 Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada
Post
by lostboy » Fri Jun 04, 2004 6:35 am
huh???
edit okay, figured that one out obviously a little tired last night
Last edited by
lostboy on Fri Jun 04, 2004 8:42 am, edited 1 time in total.
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Fri Jun 04, 2004 7:40 am
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>";
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Fri Jun 04, 2004 8:28 am
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.
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Fri Jun 04, 2004 9:07 am
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
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Fri Jun 04, 2004 1:56 pm
Can any one hwlp me on this issue
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Fri Jun 04, 2004 2:09 pm
I'm using the following code and it is working
What's the problem?
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Fri Jun 04, 2004 2:16 pm
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
lostboy
Forum Contributor
Posts: 329 Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada
Post
by lostboy » Fri Jun 04, 2004 2:20 pm
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;
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Fri Jun 04, 2004 2:20 pm
I don't know what you mean. You don't have that now. Explain what you want to happen