Jump to content

Link in a database!?


Snooble

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197082
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197085
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197094
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197095
Share on other sites

$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

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197102
Share on other sites

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! :D ComeON! :D

 

Snooble

 

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197117
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197144
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197149
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/40717-link-in-a-database/#findComment-197167
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.