Jump to content

Recommended Posts

Hi,

 

I'm having trouble with my table. I want to make the first row in my table be able to have links such as this

 

<a href="Test.php?id=<?php echo $row['title']; ?>"><?php echo $row_['title']; ?> </a>

 

Though I don't know where to put it in this code:

 

<?php
$sql  = $query_ps3_list;
$qry = mysql_query($sql) or die(mysql_error());

// Cell colors for odd rows
$c1  = array('#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e');

// Cell Colors for even rows
$c2  = array('#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d');

// Row Counter
$cnt  = 0;

$ret = '<table>';
while($row = mysql_fetch_assoc($qry))
{
  // Cell counter
  $cnt2 = 0;
  $ret  .= '<tr>';
  foreach($row as $key=>$val)
   {
    $ret .= '<td bgcolor="';

    if($cnt % 2)
      {
        $ret .= $c1[$cnt2];
      }
    else
      {
        $ret .= $c2[$cnt2];
      }

    $ret .= '">'.$val.'</td>';
    ++$cnt2;
   }
  ++$cnt;
  $ret .= '</tr>'."\n";
}
$ret .= '</table>';

echo $ret;
?> 

 

If you could help me out that would be awesome! Thanks!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/
Share on other sites

<?php
$sql  = $query_ps3_list;
$qry = mysql_query($sql) or die(mysql_error());

// Cell colors for odd rows
$c1  = array('#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e');

// Cell Colors for even rows
$c2  = array('#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d');

// Row Counter
$cnt  = 0;

$ret = '<table>';
$i=0;
while($row = mysql_fetch_assoc($qry))
{
    if ($i == 0) {
       $ret .= '<a href="Test.php?id=' . $row['title'] . '">' . $row_['title'] . '</a>';
       $i++;
   }
  // Cell counter
  $cnt2 = 0;
  $ret  .= '<tr>';
  foreach($row as $key=>$val)
   {
    $ret .= '<td bgcolor="';

    if($cnt % 2)
      {
        $ret .= $c1[$cnt2];
      }
    else
      {
        $ret .= $c2[$cnt2];
      }

    $ret .= '">'.$val.'</td>';
    ++$cnt2;
   }
  ++$cnt;
  $ret .= '</tr>'."\n";
}
$ret .= '</table>';

echo $ret;
?> 

 

EDIT:

Added an if inside the loop with $i to increment, if $i is 0 then it adds that code to the list, else it skips it.

I'm trying to use:

 

<a href="Test.php?id=<?php $row['title'] ?>"></a>

 

And make the title that shows up in the first column be part of the URL for the next page that loads. Though When I type in the link its like its not being read because its in PHP even though I have will put "'" and ";" around the HTML.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.