View Full Version : Searching MySql db
notset4life
12-10-02, 05:36 PM
I have a database set up at this site:
http://www.cybermidi.com/select/index.php
I'm not that proficient in php programming, but I can get by.
But I don't know how to add "search capabilities".
What I would like to do is add a search box to the page that will search the song database. And perhaps add another to sort the database by title, artist, whatever.
Can anyone provide me info on where to look to get this information so I can complete the web site? I am not looking to PAY for designers who charge ridiculous prices. From my limited knowledge, I would think what I need to do is not that complicated.
Thanks
Flash
heck i'll do it for free.
<form method="POST" action="<? $PHP_SELF ?>">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#999999">
<tr>
<td width="243" valign="middle" height="29"> <font face="Arial" size="5"><b>Find
A Song</b></font></td>
<td valign="middle" width="154"><b><font size="3" face="Arial">Search
Field</font></b></td>
</tr>
<tr>
<td height="70" valign="top">
<input type="text" name="chevy" class="textbox" size="20">
</td>
<td valign="top" bgcolor="#999999"> <font face="Arial"> <font size="3">
<input type="radio" name="nova" class="bullet" value="title" checked>
Song Title<br>
<input type="radio" name="nova" class="bullet" value="artist">
Artist<br>
<input type="radio" name="nova" class="bullet" value="album">
Album</font></font></td>
</tr>
<tr>
<td height="47" valign="top">
<input type="submit" value="Submit" class="button" name="submit">
</td>
<td valign="top"> </td>
</tr>
</table>
</form>
and to show the results of the search:
<?php
include ("include/dbconnect.php");
if ($chevy)
{
$sql="SELECT * FROM $table WHERE $nova LIKE '%$chevy%' ORDER BY lastname ASC";
$result = mysql_query($sql);
$resultsnumber = mysql_numrows($result);
echo "<TABLE BORDER=0>";
echo "<tr><td><font face=\"Arial\">number of songs that matched your search: $resultsnumber\n\n</face></td><tr>";
while ($myrow = mysql_fetch_array($result))
{
$id = $myrow["id"];
$title = $myrow["title"];
$artist = $myrow["artist"];
$album = $myrow["album"];
echo "<TR><TD><b><font face=\"Arial\"><a href='song.php?id=$id'>$artist - $title</a></font></b></TD>";
}
echo "</TR></TABLE>";
}
?>
yea, that should work, if not, i'm sorry but i'm sure i'm close.
now you just need to put each song in a MySQL database using the variables $title, $artist, $album. and have a page called song.php or somethang that does what ever you want when someone clicks on a song name. also make 2 files:
include/dbconnect.php:
<?
include("include/config.php");
$db = mysql_connect("$dbserver", "$dbuser", "$dbpass");
mysql_select_db("$dbname",$db);
?>
include/config.php:
<?
$dbname = "dbname";
$dbserver = "server.powweb.com";
$dbuser = "username";
$dbpass = "password";
$table = "tablename"
?>
ya that should set your in the right direction
-brad
notset4life
12-10-02, 11:01 PM
Thanks for the well thought out code. But it gets an error.
This shows up when a search is done:
-------------------------
and to show the results of the search:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /www/c/cybermidi/htdocs/select/index.php on line 279
number of songs that matched your search:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /www/c/cybermidi/htdocs/select/index.php on line 284
For your trouble pick a couple of songs on me (if you are into MIDI). If you can resolve it, I'll even give you a free membership (again if you are into it).
Flash
i'm on it. but the problem is probably in your database. Does it contain a table? or much more the right values for $id, $title, $artist, $song? i'll be here all night - AIM = BYUTJ, email = bny5@email.byu.edu - if you want to do this i might need access to your phpMyAdmin account.
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.