Jump to content

output as link to file


Bazzaah

Recommended Posts

I'd appreciate some help please.

 

I am building an audio dictionary and have written a working search function.

 

I would like the search to return a link to the relevant audio file, so that if someone searches for a word in the database they can click on the link to stream that file via their browser.

 

I have set the database to link to files stored in the site's main folder.

 

So far drawn a blank with my various efforts.

 

This is what I have  currently;

 

 

<?php

$result = mysql_query("SELECT word,sentence1 FROM pro_words WHERE word LIKE '%$search%'");
					        
//get the db content that is specified above

if (mysql_num_rows($result) < 1) {

echo "<h2>Sorry, but your search did not yield any results.</h2>";

}else {
         
echo '<table align="center" cellspacing="8" cellpadding="8" width="85%"><tr>
<td align="left"><b>Word</b></td><td align="left"><b>Example of usage</b></td></tr>
';

echo "<h3>This is what we found:</h3><br>";

while ($r=mysql_fetch_array($result, MYSQLI_ASSOC))

echo '<tr><td align="left">' . $r['word'] . '</td><td align="left">' . $r['sentence1'] . '</td></tr>';

}

echo '</table>'; // Close the table.

   }

?>

 

It works fine as a search function and I have tried adding various iterations around <a href> where the code echoes the search output but without success.

 

Any help would be very much appreciated.

 

Thanks in advance

Link to comment
Share on other sites

Do you mean that you want to echo out the 'word' returned by the search results into a link? Kind of like 'word.php?w=word_here'?

 

echo '<tr><td align="left"><a href="word.php?w=' . $r['word'] . '">' . $r['word'] . '</a></td><td align="left">' . $r['sentence1'] . '</td></tr>';

Link to comment
Share on other sites

that's exactly what I meant, thanks!

 

I'll need to sort out the links as I get a 404 when I click on the search results, but it looks exactly right!

 

I have a question on the syntax - <a href="word.php?w=..." - I take it word.php is produced dynamically as a result of the query?.

 

Thanks for your help.

 

 

Link to comment
Share on other sites

that's exactly what I meant, thanks!

 

I'll need to sort out the links as I get a 404 when I click on the search results, but it looks exactly right!

 

I have a question on the syntax - <a href="word.php?w=..." - I take it word.php is produced dynamically as a result of the query?.

 

Thanks for your help.

 

Mmm, not sure what you mean.. produced dynamically? "word.php" was just a file I made up, passing the actual word returned from the query through the GET parameter "w". You'd need to create word.php on your server in order to remove the 404 error; then within word.php you can return and process / do whatever you want with the "w" parameter value.

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.