Displaying Selected Table Data from MYSQL using ? in URL
Hi,
Complete Newbie to this and been tearing my hair out for a few days trying to do something.
I have a new mysql db and have created a table. I've managed to take a simpler version of what's now below and expand it to go to my database and pull out ALL records in the database and put them into a nice table displayed on screen.
A little background, the database will be used to store results of 52 contests, the code I have here is using a WHERE statement to pick out 1 contest and this works fine, however, what I want to be able to do is use something like a $_GET variable (I think) here and supply a blablabla.php?contest=xxxx to the URL bar.
I've tried lots of boards and lots of examples but everything I try ends up in a Parse error.
Can someone please look at this code and come up with a suggestion to allow me to take out the hard coded WHERE statement and supply the ?contest = xxxx to the browser. The user will select the appropriate contest from a ComboBox and this will supply the ?Contest=xxx to the browser.
I'm using phpmyadmin and used that to help me generate the SQL, hence the 4 lines in case anyone is wondering. My host has PHP v 4.3.2 if that helps.
and yes, you write that links just like that and pass the value of $var and $grade as you like from where ever you like ..
and then this page.php should look like this :
PHP Code:
$contest=$_GET['contest'];
$grade=$_GET['grade'];
$check=mysql_query("SELECT * FROM `2003results` WHERE Grade = '$grade' AND Contest = '$contest' ORDER BY grade, final place LIMIT 0, 50");
this is the concept to achive what you want ...
__________________ PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Just wanted to say thanks very much. got it working now, albeit, another little tweak required to what you posted, but thanks got me going in the right direction.
As I said I got your suggestion working with a slight tweak.
I'm now trying to progress to another step where now I want to pull out all the contests a band has competed in in a season.
I've got it grabbing by ?Band=xxx as per your suggestion but found that I'm always one row short in what it pulls back. I've added a counter $num_rows and that counts correct but my table is always missing the first entry that would appear.
I read on another post you answered something about calling twice and not printing first row, is that what I've done wrong ?
PHP Code:
<?php
$databaseName = "rspba_allresults";
$dbconnection = mysql_connect("*****", "*****", "*****") or die ('Cannot Connect To Results Databasebecause: ' . mysql_error());
mysql_select_db($databaseName,$dbconnection) or die ('Cannot use Results Database' . mysql_error());
$Band=$_GET['Band'];
// Pull out results for all contests per band
$sql = "SELECT * FROM 2003results WHERE Band = '$Band'";
$sql .= 'ORDER BY DATE, Grade DESC LIMIT 0, 30';