I'm trying to create a "genius" like search so that a user can enter a song name and it gives you a list of songs of the same genre that should "match". So far I have a search where it can return the song title and artist but what I need is for it to take the genre of the song (saved in a variable) and do a second search that will reurn a list of songs of the same genre. Here's the code i have so far... -
// Build SQL Query
-
$query = "select * from songs where song_name like \"%$trimmed%\"
-
order by song_name";
-
----------------- -
// now you can display the results returned
-
while ($row= mysql_fetch_array($result)) {
-
$title = $row["song_name"];
-
$artist = $row["artist"];
-
$genre = $row["genre"];
-
$SongID = $row["SongID"];
-
$Buy = $row["purchase_link"];
-
-
echo "$count.) $title" ;
-
echo " - " ;
-
echo "$artist" ;
-
$count++ ;
-
}
-
10 1913
Please use code tags. So we know what you want to do. You haven't said what problem you're having in implementing it.
Okay, that's done. Sorry, I'm new at this. basically, the code I've left is the query, the variables where the results are saved and the echo onto the screen. What I want to do is use what's in the $genre variable and use that in a second query that uses the genre of the song title searched (it's in the same row of the database) to give a list of songs of the same genre and to echo said songs onto the page of my website.
Oh, and the problem I am having in implementing it is that I don't know how to do it.
Well, from the code, I can see that you already know how to build a query string. And you have access to the genre variable. So you should have no problem building a new query string using that variable and then executing it.
And from the code I can see that you know how to iterate through a recordset and output the values. So you just do the same thing for the new recordset.
So I don't see what trouble you're having. You just have to do what you did except with a different sql string.
Ah okay, so would I have to simply do another query where I replace song_name with genre and \"%$trimmed%\" with $genre ?
That's pretty much it. Unless you want to return songs from all genres in the original recordset. In which case you just need to keep appending the genres to a comma-delimited string.
okay, so i have written -
// Build SQL Query
-
$query = "select * from songs where song_name like \"%$trimmed%\"
-
order by song_name"; // EDIT HERE and specify your table and field names for the SQL query
-
-
$query = "select * from songs where genre like \"%$genre%\"
-
order by song_name";
-
but the variable $genre isn't saved until later. how would i save it before hand as a variable so taht it can be used in the search?
If it's not saved till later, then run it after it's saved.
okay, so I have put the query in after it is saved:
but it isn't running the query or isn't displaying the results of said query.
You built the sql string but you never execute it and you don't output the results.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Frank |
last post by:
Can I store this PHP code in another page, then refernece it on
multiple pages using Require or Include ???
//results from sql query
for ($i=0; $i<$number; $i++) {
$ID =...
|
by: Frank Maestas |
last post by:
Hello,
I have been trying to figure this out but no luck.
Lets say I have a query that searches for people living in Colorado.
That results in a list on a "results.php" page. Now I want to...
|
by: san |
last post by:
Hi,
I wanted to know if this is possible and if so, how do I
do it. Say, I have a query "SELECT * FROM Table WHERE
Column="some_value". This executes on a very large data
set and I would like...
|
by: Stan |
last post by:
Hello all,
I'm looking for some hints as to how to use the results of a query in
another query. I assume I'm 'thinking' wrong in how to solve this, so
I'm hoping someone can clobber me and send...
|
by: Alex Hemingway |
last post by:
I have a table Products consisting of the following fields :-
ProductID, ProductName, PriceLevel, UnitPrice
and a query which returns all products with a specific PriceLevel.
What I would like...
|
by: Richard Coutts |
last post by:
I have a query created by the "Find Unmatched" query that lists items
in a table that were not selected by another query. The Query does
what it needs to do, but I can't edit any of the resulting...
|
by: lakshmi |
last post by:
Hi all
I'm trying to traverse through the results from a query
that returns more than 1 row. The data reader reads only
the first row. The following code doesn't work. Let me
know what's wrong....
|
by: bgreenspan |
last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am
doing and what I tried.
My database has entries with Contract Names and Expiry Dates, among
other fields. I have a form...
|
by: meendar |
last post by:
Hi to all,
I just need to get two fields from a table and manipulate the results
in next query of a procedure.I planned to code like what you see
below,
create procedure marks1
as
@ sql1 as...
|
by: zahmbonnie |
last post by:
I have created two different queries and I would like take the results from one and subtract the results from the other. I can not figure out how to write the saved query name in my new query.
Saved...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |