Bazzaah Posted December 15, 2009 Share Posted December 15, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/185189-output-as-link-to-file/ Share on other sites More sharing options...
Adam Posted December 15, 2009 Share Posted December 15, 2009 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/185189-output-as-link-to-file/#findComment-977631 Share on other sites More sharing options...
Bazzaah Posted December 15, 2009 Author Share Posted December 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/185189-output-as-link-to-file/#findComment-977783 Share on other sites More sharing options...
Adam Posted December 15, 2009 Share Posted December 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/185189-output-as-link-to-file/#findComment-977796 Share on other sites More sharing options...
Bazzaah Posted December 15, 2009 Author Share Posted December 15, 2009 I actually thought it was a file that I need to put on the server but I opted to ask a stupid question instead! I think I can figure the rest out now but thanks for your help, I really appreciate it. How does one mark a thread as solved? Quote Link to comment https://forums.phpfreaks.com/topic/185189-output-as-link-to-file/#findComment-977811 Share on other sites More sharing options...
Adam Posted December 15, 2009 Share Posted December 15, 2009 No probd! bottom left some where around quick reply. Quote Link to comment https://forums.phpfreaks.com/topic/185189-output-as-link-to-file/#findComment-977815 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.