happygolucky Posted May 5, 2009 Share Posted May 5, 2009 Hello people, im new to this forum, but hopefuly after i become stronger in programming i will be a long standing member. Let me tell you what I have so far and then explain what im trying to do in PHP. I have an sql database with three tables containing details of local bands. table 1 = artists with these columns artistid(pk) int artist_name text genre text table 2 = albums ablumid(pk) int artistid int album_name text year int table 3 = tracks tackid(pk) int albumid int artistid int track_name text video_stream boolean video_download boolean Now i want to create a php interface which has a text box a drop down box and a search button. in the drop down box contains asrtists, albums, tracks, and genre. in the text box the user types the appropriate text on what the are searching for, selects an area in the dropdown box then the appropriate results are returned. then it would say is that band has tracks with videos available. I have no idea where to start with this. any clues or help, suggestions would be greatly appreciated. Its similar to the amazon search in what i am trying to create thanks in advance Im connecting to the database with pg_connect, after that im stuck Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 5, 2009 Share Posted May 5, 2009 Moving to PHP Help, as it seems you will need some help with forms and what not. More likely to get this kind of help here. Quote Link to comment Share on other sites More sharing options...
happygolucky Posted May 5, 2009 Author Share Posted May 5, 2009 thanks was unsure where to post as it involves psql and php Quote Link to comment Share on other sites More sharing options...
happygolucky Posted May 5, 2009 Author Share Posted May 5, 2009 okay. lets say i wanted to have track search, album search and artist search on seperate pages. This is what i have for the album search page <html> <head><title>Music Mart</title> </head> <body> <p>Search the database:<br /> <form action="artistsearch2.php" method="post"> Artist Name:<br /> <input type="text" name="artist_name" size="20" maxlength="40" value="" /><br /> <input type="submit" value="Search!" /> </form> </p> <?php /* If the form has been submitted with a supplied artist name */ if (isset($_POST['$artist_name'])){ //include "pgsql.class.php"; (throws an error on this line when is active) // Connect to server and select database $pgsqldb = @pg_connect("host=ginding address.co.uk user=****** password=********** dbname=******") or die("Could not connect to db server."); /* Set the posted variable to a convenient name */ $artist_name = $_POST['artist_name']; /* Query the employee table */ $pg->query("SELECT artist_name FROM artists WHERE artist_name='$artist_name'"); /* If records are found, output record */ if ($pgsqldb->numrows() > 0){ while ($row = $pgsqldb->fetchobject()) { echo "$row->artist_name, $<br />"; } } else { echo "No Results found."; } } ?> </body> </html> Blue October is a band in the database but it isnt returning anything, nor is any other band. where is this code letting me down. as you can see i have put my own work in but i am still struggling Quote Link to comment Share on other sites More sharing options...
btherl Posted May 6, 2009 Share Posted May 6, 2009 Try this: $sql = "SELECT artist_name FROM artists WHERE artist_name='$artist_name'"; $result = pg_query($pgsqldb, $sql) or die("Query: $sql\nFailed with: " . pg_last_error()); while ($row = pg_fetch_assoc($result)) { echo "{$row['artist_name']}<br>"; } If you still get no results from your query, echo the query so you can see what's actually being called. Good luck Quote Link to comment Share on other sites More sharing options...
happygolucky Posted May 6, 2009 Author Share Posted May 6, 2009 Thanks for your suggestion. Unfortunayely still no luck. Quote Link to comment Share on other sites More sharing options...
btherl Posted May 6, 2009 Share Posted May 6, 2009 Did you echo the query? Quote Link to comment Share on other sites More sharing options...
happygolucky Posted May 6, 2009 Author Share Posted May 6, 2009 this may be embrassing but i woudnt know how Quote Link to comment Share on other sites More sharing options...
btherl Posted May 6, 2009 Share Posted May 6, 2009 Ah, no worries. Here's how: $sql = "SELECT artist_name FROM artists WHERE artist_name='$artist_name'"; echo "We're about to run this query: $sql <br>"; $result = pg_query($pgsqldb, $sql) or die("Query: $sql\nFailed with: " . pg_last_error()); while ($row = pg_fetch_assoc($result)) { echo "{$row['artist_name']}<br>"; } Then in your output you will see "We're about to run this query: SELECT artist_name ..." You can take a look there and check that the query is what it should be. If you're not sure if the query is correct or not, post the output here. Quote Link to comment 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.