Snooble Posted March 1, 2007 Share Posted March 1, 2007 Code: $count = 0; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } $count++; echo "\t</tr>\n"; } echo "</table>\n"; if ($count < 1) { echo "<br><br>No rows were found in this table.<br><br>"; } else { echo "<br><br>".$count; echo " rows were found in this table.<br><br>"; } Under the Download column and Mirror column i want all the values to be links. So Song Title | Size | Download | Mirror --------------------------------------------------- Blah | 2mb | Download | Download 2 The Blah and the 2mb values are taken straight from the database but i want the Download value to be placed as a link. <a href="content from database>Download</a> Savvy? Thanks you Snooble Quote Link to comment Share on other sites More sharing options...
willpower Posted March 1, 2007 Share Posted March 1, 2007 you have it <a href " <? echo link from db;?> "><? echo link name from DB ; ?></a> You clearly will have to store the link location in the database OR have a logical process so that all links are 'worked out' ie $link="http://this_path_always/".<? echo $this_name; ?>.$this_file_extension; Quote Link to comment Share on other sites More sharing options...
Snooble Posted March 1, 2007 Author Share Posted March 1, 2007 if you look at my script though it's a loop. how can i implement it into that loop? I havn't used mysql loops much if at all. So i need it to be placed into the loop. Can someone tell me some rough code and the place to put it because i'm lost here. I'm echoing rows so i need to edit parts of them rows dont i? Snooble Quote Link to comment Share on other sites More sharing options...
willpower Posted March 1, 2007 Share Posted March 1, 2007 sorry you are right the code you have (i blieve) is problematic as it spits all the row from the DB as 1 string. You will need to rework this before you can have a link where you want it. you will need to seperate out all fields so that your downlaod field can be treated differently Quote Link to comment Share on other sites More sharing options...
Snooble Posted March 1, 2007 Author Share Posted March 1, 2007 ok, this would involve placing the values in an array and spitting them out? like $list = mysql_fetch_assoc($result); .$list['Download']; I dont have an ID assigned. I haven't learn about ID's yet. (Probably a bad idea to leave them out) Any help? i can always add a column etc. Thanks Snooble Quote Link to comment Share on other sites More sharing options...
willpower Posted March 1, 2007 Share Posted March 1, 2007 $query="SELECT.............my statement.........."; $result=mysql_result($query); $row_result=mysql_fetch_assoc($result); $total_rows=mysql_num_rows($result); do { ?> <tr> <td><? echo $row_result['Song Title'];?></td> <td><a href "<? echo $row_result['Link'];?>"> Link Title </a> </tr> <? } while ($row_result = mysql_fetch_assoc ($result)) Now this is only part of the code...but it should give you an idea Quote Link to comment Share on other sites More sharing options...
simcoweb Posted March 1, 2007 Share Posted March 1, 2007 To display it as a link just change your while loop output: <?php while ($line = mysql_fetch_array($result){ echo "<a href='ifyouhaveascript.php?link=" . $line['Download'] . "'>Download File</a>"; } ?> Quote Link to comment Share on other sites More sharing options...
Snooble Posted March 1, 2007 Author Share Posted March 1, 2007 Just had a bath and a think... The easiest way would be to take the row split it into the columns. | SONG | SIZE | DOWNLOAD | MIRROR | -------------------------------------- Then create a loop that prints the first two cells from the row and then places the next cell within <a href="cellfromrow">Download</a> and the same with Mirror. How could i do that? It seems easy? Thank you for help so far! Should be last post! ComeON! Snooble Quote Link to comment Share on other sites More sharing options...
simcoweb Posted March 1, 2007 Share Posted March 1, 2007 Like this: <?php $sql= "SELECT * FROM Downloads"; $results = mysql_query($sql) or die(mysql_error()); echo "<table border='0' width='500'> <tr><th>| Song |</th><th>Size |</th><th>Download |</th><th>Mirror |</th></tr>"; while ($row = mysql_fetch_array($results) { echo "<tr><td>" . $row['song'] . "</td><td>" . $row['size'] . "</td><td><a href='download.php?song=" . $row['download'] . "'>Download</a></td><td>" . $row['mirror'] . "</td></tr>"; } echo "</table>\n"; ?> This won't be 100% pretty but you can take it from there to clean up the HTML to make it prettier with some style tags. Quote Link to comment Share on other sites More sharing options...
Snooble Posted March 1, 2007 Author Share Posted March 1, 2007 Brilliant!!! It's so much easier when i see it with a little function. I will implement it when i get back tomorrow. Thanks alot!!!! I'll clean up the headers and table as i have a layout that's fine at the moment. But it's the "$row['size']" part thats going to come in handy! As i didn't know how to split the results. Just a quick question. When you put "size" in the parenthesis. Is that where i place the Fieldname according to the Table? lol I assume so. Just don't want to mess things around too much! Snooble (Thanks again) Quote Link to comment Share on other sites More sharing options...
simcoweb Posted March 1, 2007 Share Posted March 1, 2007 Just keep in mind that the mysql query gets all the info from the database as per instructions then the mysql_fetch_array splits each field into a separate item based on the field name which you can then echo or manipulate individually like I outlined there. So, each item in the array can have its own HTML parameters surrounding it. For example: <b>" . $row['song'] . "</b> would bold face the results for that field. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.