Help with resquesting info from a MySQL Database

G

Guest

Guest
Im a newbie to this MySQL database stuff, and for my website, i decided to make a ringtone section. I read a couple of tutorials, and that was enough for me to make the actual database, but now i can't find a way of requesting the info which matches the conditions at the end of the url...

At the moment, my script looks like this:
---------------------------------------------------------------------

<html>
<head>
<title>CyberPlebs</title>
<STYLE type="text/css">
#P { font: 9pt Verdana,Helvetica,Arial }
#TD { font: 9pt Verdana,Helvetica,Arial }
.noline {a:Verdana,Helvetica,Arial,Sans Serif;font-size:10pt;color:#000000;text-decoration:none;}
A:hover { color:#3399FF; }
</STYLE>

<style>

</style>
</head>
<body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">

<?php



$db = mysql_connect("localhost", "abc", "chicken");

mysql_select_db("abc_uk_db",$db);

// display individual record

if ($id) {

$result = mysql_query("SELECT * FROM ringtone WHERE id=$id",$db);

$myrow = mysql_fetch_array($result);

printf("Title: %s\n<br>", $myrow["title"]);

printf("Band: %s\n<br>", $myrow["band"]);

printf("RingTone: %s\n<br>", $myrow["ringtone"]);

printf("Tempo: %s\n<br>", $myrow["tempo"]);

printf("Category: %s\n<br>", $myrow["Category"]);

}

else {


$result = mysql_query("SELECT * FROM ringtone",$db);

if ($myrow = mysql_fetch_array($result)) {


do {

printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["id"], $myrow["title"], $myrow[""]);

} while ($myrow = mysql_fetch_array($result));

} else {


echo "Sorry, no records were found!";

}
}
?>



</body>



</html>
<script language="JavaScript1.2">

//Scrollable content III- By http://www.dynamicdrive.com

var speed, currentpos=curpos1=0,alt=1,curpos2=-1

function initialize(){
if (window.parent.scrollspeed!=0){
speed=window.parent.scrollspeed
scrollwindow()
}
}

function scrollwindow(){
temp=(document.all)? document.body.scrollTop : window.pageYOffset
alt=(alt==0)? 1 : 0
if (alt==0)
curpos1=temp
else
curpos2=temp

window.scrollBy(0,speed)
}

setInterval("initialize()",10)

</script>

------------------------------------------------------------------------

now , what happens at the moment is that it checks to see if the end of the url is ?id= and if it is, show the results of the ringtone with the id which is at the end of the url (eg. ?id=6). But if there is no ?id= it just shows you the list of ringtones. But what i want is it to bring up all the results which match the criteria at the end of the url, so if it was ?Category=Rock&Tempo=200 it would bring up all the names of the ringtones which are in the rock category, and with a tempo of 200. I want the "id" bit at the top to stay though..
PLEASE HELP :wink:
 
If i have well understood....

For that all it s happening in your request
you have your category in your URL so use the $_GET array witch content all the var that u pass with your URL

then

do something like

$cat = $_GET['Category'];

and then
if($cat)
{
$result = mysql_query("SELECT * FROM ringtone WHERE category LIKE '$cat'",$db);
while($Row=mysql_fetch_array($result))
{
your code here to display all the ringtones from the wathever category
}
}

NB: this code supose dat ur field name in ur Db for the category is 'category'

to keep ur Id one displayed just add this code

hope it will be usefull

bye
cho@
 
Back
Top