Scruffy Posted December 8, 2009 Share Posted December 8, 2009 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 More sharing options...
premiso Posted December 8, 2009 Share Posted December 8, 2009 <?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. Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973650 Share on other sites More sharing options...
Scruffy Posted December 8, 2009 Author Share Posted December 8, 2009 Sorry premiso, I explained myself wrong. I want the entire first column to be linkable not first row. Sorry for the mistake. Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973659 Share on other sites More sharing options...
Philip Posted December 8, 2009 Share Posted December 8, 2009 Just do a separate mysql_fetch_assoc above your loop... // grab a row $row = mysql_fetch_assoc($qry); // do whatever with row, simple example below $ret .= '<tr><td>'.$row['title'].'</td></tr>'; while($row = mysql_fetch_assoc()) Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973694 Share on other sites More sharing options...
Scruffy Posted December 8, 2009 Author Share Posted December 8, 2009 Neither of those seem to be working for some reason. The HTML is not being read for the <a href= code. Is there another way to do it? Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973734 Share on other sites More sharing options...
Philip Posted December 8, 2009 Share Posted December 8, 2009 What do you mean by: The HTML is not being read for the <a href= code. Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973742 Share on other sites More sharing options...
Scruffy Posted December 8, 2009 Author Share Posted December 8, 2009 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. Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973758 Share on other sites More sharing options...
Scruffy Posted December 8, 2009 Author Share Posted December 8, 2009 Actually is there a better way by adding a URL argument that might work? Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973777 Share on other sites More sharing options...
Philip Posted December 8, 2009 Share Posted December 8, 2009 You need an echo in there <a href="Test.php?id=<?php echo $row['title']; ?>"></a> Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973778 Share on other sites More sharing options...
Scruffy Posted December 9, 2009 Author Share Posted December 9, 2009 Thank you KingPhilip! Link to comment https://forums.phpfreaks.com/topic/184444-alternating-color-table-with-url-links/#findComment-973871 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.