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
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
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
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
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
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
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
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
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
Share on other sites

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.