kasitzboym Posted March 22, 2010 Share Posted March 22, 2010 Hey everyone, Thanks in advance for any help i may get on this topic. I am trying to take the information from a table on MYSQL database and display the information, depending on the link in the URL, on the page. I have already created a page called staff.php I would like to take this page and display all of images of the staff members in the MYSQL database on this page with the images being link, this i have no problem with. I would then like to created it so that when they click on the staff members image then it will replace the entire page's information with the current staff members information that they have selected with the url showing their name such as example.com/staff.php?name=bob all of the code i have that already works is displayed below. Could someone help me with this as i need to finish this for the website to be posted online in a timely manner. staff.php <?php require("connect.php"); $query="SELECT * FROM staff"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $title=mysql_result($result,$i,"title"); $firstname=mysql_result($result,$i,"firstname"); $lastname=mysql_result($result,$i,"lastname"); $bio=mysql_result($result,$i,"bio"); $yearbegan=mysql_result($result,$i,"yearbegan"); $imagename=mysql_result($result,$i,"imagename"); echo "<a href=\staffmember.php?name=$firstname$lastname><img src=\"staffpicturesthumb/$imagename\" width=\"150\" height=\"200\" /></a> <br>"; $i++; } ?> Once again thanks for any help in advance!!! Link to comment https://forums.phpfreaks.com/topic/196184-using-php-with-mysql-for-desplaying-linked-information/ Share on other sites More sharing options...
Bio Posted March 22, 2010 Share Posted March 22, 2010 You dont have quotes around the url. I would suggest passing the index# rather than the first & last name. your next query will work better that way. Link to comment https://forums.phpfreaks.com/topic/196184-using-php-with-mysql-for-desplaying-linked-information/#findComment-1030246 Share on other sites More sharing options...
kasitzboym Posted March 22, 2010 Author Share Posted March 22, 2010 The url actually worked exactly like i wanted it and does display example.com/staff.php?name=BobJones So the url that its linking to doesn't actually have any problems i just have no idea how to display the information that is in the MYSQL database. I was told i have to put it into an array and use the $_GET[] function but i have no idea how to do that with mysql Link to comment https://forums.phpfreaks.com/topic/196184-using-php-with-mysql-for-desplaying-linked-information/#findComment-1030247 Share on other sites More sharing options...
Jax2 Posted March 22, 2010 Share Posted March 22, 2010 First, it would be easier just to use the ID number of the staff member instead of first / last name, but using your method, you could do it like this: echo "<a href=\staffmember.php?first=$firstname&last=$lastname><img src=\"staffpicturesthumb/$imagename\" width=\"150\" height=\"200\" /></a> <br>"; and then on staffmember.php you would call their data like this: $first=$_GET['first']; $last=$_GET['last']; $sql="select * from table WHERE firstname=$first, lastname=$last" $result=mysql_query($sql, $db); while $row=(mysql_fetch_array($result)) { CODE HERE }; That should do it ... Link to comment https://forums.phpfreaks.com/topic/196184-using-php-with-mysql-for-desplaying-linked-information/#findComment-1030248 Share on other sites More sharing options...
Jax2 Posted March 22, 2010 Share Posted March 22, 2010 What I meant by ID, is if you have your staff table set up like this: ID (unique) firstname lastname other1 other2 other3 ...etc then you can simply pass the ID (index) like this: echo "<a href=\staffmember.php?ID=$ID> Then on the next page, you can use : $ID=$_GET['ID']; sql="select * from table where ID=$ID" $result=mysql_query($sql, $db); while $row=(mysql_fetch_array($result)) { echo "First name: ".$row['firstname']."<br>"; echo "Last name: ".$row['lastname']."<br>"; echo "Other: ".$row['other']."<br>"; echo "Other1: ".$row['other1']."<br>"; }; and so on . Link to comment https://forums.phpfreaks.com/topic/196184-using-php-with-mysql-for-desplaying-linked-information/#findComment-1030251 Share on other sites More sharing options...
kasitzboym Posted March 22, 2010 Author Share Posted March 22, 2010 Could you explain this part of the code for me... I haven't seen this format before $result=mysql_query($sql, $db); Thanks Link to comment https://forums.phpfreaks.com/topic/196184-using-php-with-mysql-for-desplaying-linked-information/#findComment-1030254 Share on other sites More sharing options...
Jax2 Posted March 22, 2010 Share Posted March 22, 2010 it's just an easier way to connect to the database ... you have require("connection.php"), so in that file, make it look like this: <?php $host = "yourhost"; $username = "username"; $password = "password"; $dbname = "database name"; $db = mysql_connect($host, $username, $password); mysql_select_db($dbname,$db); ?> and then from now on you can do your queries fast as shown... $sql="sql statement"; $result=mysql_query($sql, $db); it's just an easier method of writing out your sql connections. Link to comment https://forums.phpfreaks.com/topic/196184-using-php-with-mysql-for-desplaying-linked-information/#findComment-1030257 Share on other sites More sharing options...
kasitzboym Posted March 23, 2010 Author Share Posted March 23, 2010 Alright i seam to be having some trouble with my code and i dont understand where it is hanging or why the code i have in staffmember.php is <?php require("connect.php"); $first=$_GET['first']; $last=$_GET['last']; $sql="select * from staff WHERE firstname=$first, lastname=$last"; $result=mysql_query($sql, $connect); while $row=(mysql_fetch_array($result)) { $id=mysql_result($result,"id"); $title=mysql_result($result,"title"); $firstname=mysql_result($result,"firstname"); $lastname=mysql_result($result,"lastname"); $bio=mysql_result($result,"bio"); $yearbegan=mysql_result($result,"yearbegan"); $imagename=mysql_result($result,"imagename"); echo "$firstname $lastname $bio $yearbegan }; ?> and the error it is giving me in the web browser is Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in C:\xampp\htdocs\sahnew\Final\staffmember.php on line 20 Line 20 is while $row=(mysql_fetch_array($result)) { Any ideas? Link to comment https://forums.phpfreaks.com/topic/196184-using-php-with-mysql-for-desplaying-linked-information/#findComment-1030272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.