Forum Moderators: coopster
I have a SQL query that then displays a random 3 results which a user can click on and open up a page with further information.
eg:
Search results:
Alpha
November
Delta
Each one has an id number:
Alpha id:1
November id:14
Delta id:4
If you select Delta then the code tells the site to load the page:
ent.php?f=4
In the database, Delta (id 4) would be mentioned in 3 databases.
Now I have started coding the ent.php page but dont know how to populate it with just things associated with id 4
Can anyone help?
Thank you
You should be able to JOIN all of the tables together if that is what you are looking for. Read up for more information and try it out yourself, or give some more detail about the structure of your database and we'll try to get you the query you're going to need to grab all the data.
[dev.mysql.com...]
and Welcome to WebmasterWorld! :)
I know how to gain bits of information from each field in the database but what I want is for the page to load ent.php then for the code to read the part that says ?f=4 and associate that with Delta and so show a query result as if I had pre coded it:
$query="SELECT * FROM table1,table2,table3 WHERE entID='4'";
$query = "SELECT * FROM `table1`,`table2`,`table3` WHERE `entID` = '".[url=http://www.php.net/mysql-real-escape-string]mysql_real_escape_string[/url]($_GET['f'])."'";
This will grab the 'f' variable from the URI string and put it into the query.
I entered the code you gave and changed the table names (only used 1 as a test) and this result appeared:
Resource id #4
This is the code I used:
<?php
include("admin/dbinfo.inc.php");
mysql_connect("$host","$username","$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$query = "SELECT * FROM `ents` WHERE `entID` = '".mysql_real_escape_string($_GET['f'])."'";
$result=mysql_query($query);
echo "$result";
?>
I also tried changing the echo comment to see if my part was wrong:
echo "$query";
And the result said:
SELECT * FROM `entertainer` WHERE `entID` = '2'
So the code IS catching the number but how do I fix this? I'm already bald so have no further hair to pull out lol
<?php
include("admin/dbinfo.inc.php");
mysql_connect("$host","$username","$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$query = "SELECT * FROM `ents` WHERE `entID` = '".mysql_real_escape_string($_GET['f'])."'";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
?>
u can do that if ure expecting one record to be returned then when u want to echo the fields of that record u can do this
<?php
echo $row['ur_column_name'];
?>
if u are expecting more than one record u have to do it like this:
<?php
include("admin/dbinfo.inc.php");
mysql_connect("$host","$username","$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$query = "SELECT * FROM `ents` WHERE `entID` = '".mysql_real_escape_string($_GET['f'])."'";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)){
echo $row['ur_column_name'];
}
?>