Please do help me


#1

hi;
i m new to php, i need some help. I have situation in which there are two tables in database; one is student table and other is description table. In student table there are two fields id and name; And in description table id,name and other stuff like email, address etc.
I wrote code to view the data from Student Table, but i need some help here. I want to use Id as hyperlink; so when someone clicks on the Id(that is shown from student table), it will show the all the details from description table of Id that is being cliked.

Thanks ALOT
The code which i wrote for showing data from student table is

<?php $host="localhost"; $usr="root"; $pass=""; $conn=mysql_connect($host,$usr,$pass) or die("Cannot connect"); $db=mysql_select_db("db",$conn) or die("Database not selected"); $qu="select * from std "; $v_query=mysql_query($qu); echo "n "; echo "
"; } echo "
ID NAME</th"; while($row=mysql_fetch_array($v_query)) { echo "
$row[std_id] $row[std_name]
n"; mysql_close($conn); ?>

#2

make a page which processes the “desc” request. make the link to it like this:

[php]

<?php $link = "http://www.mypage.com/description.php?id=".$row['id']; ?>

[/php]

then in the description.php page, do something like this:

[php]

<?php $id = $HTTP_GET_VARS['id']; ?>

[/php]

connect to mysql and use a select statement:

[php]

<?php $querystring = "SELECT * FROM description WHERE id = '".$id."'"; ?>

[/php]

then just output your data like you did in the other page and you’re set to go


#3

Thanks for the help

  i have changed the code after your guidence, and now there are two php pages (the second one is for showing description values). BUT i m getting an error.
                          [b]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:Silk22New Folderdes.php on line 17[/b]                       
        THE CODE For first page is 
<?php $host="localhost"; $usr="root"; $pass=""; $conn=mysql_connect($host,$usr,$pass) or die("Cannot connect"); $db=mysql_select_db("db",$conn) or die("Database not selected"); $qu="select * from std "; $v_query=mysql_query($qu); echo "n "; echo "
"; } echo "
ID NAME</th"; while($row=mysql_fetch_array($v_query)) { echo "
$row[std_id] $row[std_name]
n"; mysql_close($conn); ?>

AND THE CODE For des.php is

<?php $host="localhost"; $usr="root"; $pass=""; $conn=mysql_connect($host,$usr,$pass) or die("Cannot connect"); $db=mysql_select_db("db",$conn) or die("Database not selected"); $id=$HTTP_GET_VARS['id']; $qu="select * from description where name=$id"; $v_query=mysql_query($qu); echo "n "; echo " "; while($row=mysql_fetch_array($v_query)) { echo "

"; } echo "
NAME CLASS GPA
$row[name] $row[class] $row[gpa]
n"; mysql_close($conn); ?>

Regards @ Hasnain


#4

well, you’ve got several problems.

the first is that your script variables are named rather inconveniently. instead of sacrificing convenience for a smaller file size, name your variables so that you or anyone else looking at the script can know what you’re talking about. who knows? you might come back to the script three months later and not even remember what you were thinking.

second, try this:

[php]<?php
if( isset( $HTTP_GET_VARS[‘id’] ) && !empty( $HTTP_GET_VARS[‘id’] ) ) {
// print out all info from db
} else {
echo “You didn’t include an ID #.”;
};
?>
[/php]

third, try using this for every mysql function you’re running:

[php]<?php
mysql_query( $query) or die( "Line # __: ".mysql_error() );
?>
[/php]

for line number, just insert the line number the mysql function is on, or do something that is specific to the function, such as "couldn’t connect: " or "couldn’t query: "

if you have any problems that aren’t popping up but are causing the problem with mysql_fetch_array, that should make it real clear what’s wrong. try some of this stuff and tell me what you’ve found. :D


#5

THANKS John,
I will follow your instructions.

i have changed code and it is working now, i have passed student id(not name) to description.php and checked it against student id of description table.

Thanks again for your help.
BYE