Forum Moderators: coopster

Message Too Old, No Replies

Select id in address bar

         

NYCSavage

12:32 pm on Aug 31, 2009 (gmt 0)

10+ Year Member



Good morning everyone, I have a code that i'm working on that needs a slight tweak.

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

eelixduppy

1:48 pm on Aug 31, 2009 (gmt 0)



In 3 databases or 3 different tables in the same database?

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! :)

NYCSavage

2:07 pm on Aug 31, 2009 (gmt 0)

10+ Year Member



Thank you for the prompt reply, I have 3 tables in the same database sorry.

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'";

eelixduppy

2:46 pm on Aug 31, 2009 (gmt 0)



You mean placing the variable into the query itself? ie

$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.

NYCSavage

3:30 pm on Aug 31, 2009 (gmt 0)

10+ Year Member



eelixduppy, thank you for taking the time to help this noob lol

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

ALKateb

8:19 pm on Aug 31, 2009 (gmt 0)

10+ Year Member



what are you trying to echo? if ure trying to echo the fileds in that record then u have to use (mysql_fech_array)
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);
$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'];
}
?>